func (registry *Registry) Register(uri route.Uri, endpoint *route.Endpoint) { registry.Lock() defer registry.Unlock() uri = uri.ToLower() key := tableKey{ addr: endpoint.CanonicalAddr(), uri: uri, } var endpointToRegister *route.Endpoint entry, found := registry.table[key] if found { endpointToRegister = entry.endpoint } else { endpointToRegister = endpoint entry = &tableEntry{endpoint: endpoint} registry.table[key] = entry } pool, found := registry.byUri[uri] if !found { pool = route.NewPool() registry.byUri[uri] = pool } pool.Add(endpointToRegister) entry.updatedAt = time.Now() registry.timeOfLastUpdate = time.Now() }
func (r *RouteRegistry) Lookup(uri route.Uri) *route.Pool { r.RLock() uri = uri.ToLower() pool := r.byUri[uri] r.RUnlock() return pool }
func (registry *Registry) Unregister(uri route.Uri, endpoint *route.Endpoint) { registry.Lock() defer registry.Unlock() uri = uri.ToLower() key := tableKey{ addr: endpoint.CanonicalAddr(), uri: uri, } registry.unregisterUri(key) }
func (r *RouteRegistry) Lookup(uri route.Uri) *route.Pool { r.RLock() uri = uri.ToLower() var err error pool, found := r.byUri.MatchUri(uri) for !found && err == nil { uri, err = uri.NextWildcard() pool, found = r.byUri.MatchUri(uri) } r.RUnlock() return pool }
func (r *RouteRegistry) Unregister(uri route.Uri, endpoint *route.Endpoint) { r.Lock() uri = uri.ToLower() pool, found := r.byUri[uri] if found { pool.Remove(endpoint) if pool.IsEmpty() { delete(r.byUri, uri) } } r.Unlock() }
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) { t := time.Now() r.Lock() uri = uri.ToLower() pool, found := r.byUri[uri] if !found { pool = route.NewPool(r.dropletStaleThreshold / 4) r.byUri[uri] = pool } pool.Put(endpoint) r.timeOfLastUpdate = t r.Unlock() }
func (r *Registry) lookupByUri(uri route.Uri) (*route.Pool, bool) { uri = uri.ToLower() pool, ok := r.byUri[uri] return pool, ok }