Пример #1
0
func (r *RouteRegistry) Register(uri route.Uri, ep *route.Endpoint) {
	t := time.Now()
	r.Lock()

	uri = uri.RouteKey()

	pool, found := r.byUri.Find(uri)
	if !found {
		contextPath := parseContextPath(uri)
		pool = route.NewPool(r.dropletStaleThreshold/4, contextPath)
		r.byUri.Insert(uri, pool)
	}

	pool.Put(ep)

	r.timeOfLastUpdate = t
	r.Unlock()
}
Пример #2
0
func (r *RouteRegistry) RegisterAll(uri route.Uri, eps []*route.Endpoint) {
	r.Lock()
	defer r.Unlock()

	uri = uri.RouteKey()

	contextPath := parseContextPath(uri)
	pool := route.NewPool(r.dropletStaleThreshold/4, contextPath)

	for _, ep := range eps {
		r.logger.Infof("route.endpoint: %v", ep)
		pool.Put(ep)
	}

	r.logger.Infof("byUri: %#v", *pool)
	ok := r.byUri.Insert(uri, pool)
	r.logger.Infof("=======ok: %#v", *ok.Pool)

	r.timeOfLastUpdate = time.Now()

}
Пример #3
0
	. "vulcan/router/registry"
)

var _ = Describe("Trie", func() {

	var (
		r *Trie
	)

	BeforeEach(func() {
		r = NewTrie()
	})

	Describe(".Find", func() {
		It("works for the root node", func() {
			p := route.NewPool(42, "")
			r.Insert("/", p)
			node, ok := r.Find("/")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("finds an exact match to an existing key", func() {
			p := route.NewPool(42, "")
			r.Insert("/foo/bar", p)
			node, ok := r.Find("/foo/bar")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("returns nil when no exact match is found", func() {