예제 #1
0
파일: pool.go 프로젝트: bubble66/skynet
func (p *Pool) updateInstanceMux(s skynet.ServiceInfo) {
	if _, ok := p.servicePools[s.AddrString()]; !ok {
		p.AddInstance(s)
		return
	}

	p.servicePools[s.AddrString()].service = s
}
예제 #2
0
파일: pool.go 프로젝트: bubble66/skynet
/*
Pool.Acquire will return an idle connection or a new one
*/
func (p *Pool) Acquire(s skynet.ServiceInfo) (c conn.Connection, err error) {
	if _, ok := p.servicePools[s.AddrString()]; !ok {
		return nil, UnknownService
	}

	r, err := p.servicePools[s.AddrString()].pool.Acquire()

	if err != nil {
		return nil, err
	}

	return r.(conn.Connection), nil
}
예제 #3
0
파일: pool.go 프로젝트: bubble66/skynet
func (p *Pool) addInstanceMux(s skynet.ServiceInfo) {
	if _, ok := p.servicePools[s.AddrString()]; !ok {
		sp := &servicePool{
			service: s,
			pool: pools.NewResourcePool(func() (pools.Resource, error) {
				c, err := conn.NewConnection(s.Name, GetNetwork(), s.AddrString(), DIAL_TIMEOUT)

				if err == nil {
					c.SetIdleTimeout(getIdleTimeout(s))
				}

				return c, err
			},
				getIdleConnectionsToInstance(s),
				getMaxConnectionsToInstance(s)),
		}

		p.servicePools[s.AddrString()] = sp
	} else {
		p.UpdateInstance(s)
	}
}
예제 #4
0
파일: pool.go 프로젝트: bubble66/skynet
func (p *Pool) removeInstanceMux(s skynet.ServiceInfo) {
	delete(p.servicePools, s.AddrString())
}