func (p *Pool) updateInstanceMux(s skynet.ServiceInfo) { if _, ok := p.servicePools[s.AddrString()]; !ok { p.AddInstance(s) return } p.servicePools[s.AddrString()].service = s }
/* 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 }
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) } }
func (p *Pool) removeInstanceMux(s skynet.ServiceInfo) { delete(p.servicePools, s.AddrString()) }