Exemple #1
0
func (p *Pool) updateInstanceMux(s skynet.ServiceInfo) {
	if _, ok := p.servicePools[s.AddrString()]; !ok {
		p.AddInstance(s)
		return
	}

	p.servicePools[s.AddrString()].service = s
}
Exemple #2
0
/*
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
}
Exemple #3
0
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)
	}
}
Exemple #4
0
func (p *Pool) removeInstanceMux(s skynet.ServiceInfo) {
	delete(p.servicePools, s.AddrString())
}