func (p *Pool) updateInstanceMux(s skynet.ServiceInfo) { if _, ok := p.servicePools[s.AddrString()]; !ok { p.AddInstance(s) return } p.servicePools[s.AddrString()].service = s }
func (ic *InstanceChooser) add(instance *skynet.ServiceInfo) { for _, in := range ic.instances { if in.GetConfigPath() == instance.GetConfigPath() { return } } ic.instances = append(ic.instances, instance) }
func (ic *InstanceChooser) remove(instance *skynet.ServiceInfo) { for i, in := range ic.instances { if in.GetConfigPath() == instance.GetConfigPath() { ic.instances[i] = ic.instances[len(ic.instances)-1] ic.instances = ic.instances[:len(ic.instances)-1] return } } }
/* 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 (im *InstanceMonitor) monitorInstanceStats() { rev := im.doozer.GetCurrentRevision() watchPath := path.Join("/statistics", "**") for { ev, err := im.doozer.Wait(watchPath, rev+1) rev = ev.Rev if err != nil { continue } // If it's being removed no need to send notification, it's sent my monitorInstances if ev.IsDel() { continue } else { var s skynet.ServiceInfo var stats skynet.ServiceStatistics var ok bool servicePath := strings.Replace(ev.Path, "/statistics", "/services", 1) // If InstanceMonitor doesn't know about it, it was probably deleted, safe not to send notification if s, ok = im.instances[servicePath]; !ok { continue } buf := bytes.NewBuffer(ev.Body) err = json.Unmarshal(buf.Bytes(), &stats) if err != nil { fmt.Println("error unmarshalling service") continue } s.Stats = &stats // Let's create an update notification to send, with our new statistics im.notificationChan <- InstanceMonitorNotification{ Path: ev.Path, Service: s, OldService: im.instances[servicePath], Type: InstanceStatsUpdateNotification, } } } }
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()) }