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

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

	r.RUnlock()

	return pool
}
示例#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)
}
示例#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
}
示例#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()
}
示例#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()
}
示例#7
0
func (r *Registry) lookupByUri(uri route.Uri) (*route.Pool, bool) {
	uri = uri.ToLower()
	pool, ok := r.byUri[uri]
	return pool, ok
}