Esempio n. 1
0
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()
}
Esempio n. 2
0
func (r *RouteRegistry) Lookup(uri route.Uri) *route.Pool {
	r.RLock()

	uri = uri.ToLower()
	pool := r.byUri[uri]

	r.RUnlock()

	return pool
}
Esempio n. 3
0
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)
}
Esempio n. 4
0
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
}
Esempio n. 5
0
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()
}
Esempio n. 6
0
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()
}
Esempio n. 7
0
func (r *Registry) lookupByUri(uri route.Uri) (*route.Pool, bool) {
	uri = uri.ToLower()
	pool, ok := r.byUri[uri]
	return pool, ok
}