package probe import ( "fmt" "sync" "git.loafle.net/commons_go/logging" crr "git.loafle.net/commons_go/rpc/registry" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" ) func New() ProbeManager { a := &probeManagers{} return a } type ProbeManager interface { Start() error Stop() } type probeManagers struct { cClient oogwc.Client stopChan chan struct{} stopWg sync.WaitGroup } func (pm *probeManagers) Start() error { if nil != pm.stopChan { logging.Logger().Panic("Probe: already running. Stop it before starting it again") } rpcRegistry := crr.NewRPCRegistry() // napService := &oopar.NoAuthProbeService{ // DoneChan: pm.serviceDoneChan, // ConfigPath: pm.configPath, // Config: pm.config, // } // rpcRegistry.RegisterService(napService, "") // ch := client.NewClientHandler(rpcRegistry) // sb := client.NewSocketBuilder(napService) // if nil == sb { // return fmt.Errorf("Auth: Cannot create SocketBuilder") // } // pm.cClient = client.NewClient(ch, sb) pm.stopChan = make(chan struct{}) pm.stopWg.Add(1) go pm.handleProbe() return nil } func (pm *probeManagers) Stop() { if pm.stopChan == nil { logging.Logger().Warn("Auth: auth must be started before stopping it") } close(pm.stopChan) pm.stopWg.Wait() pm.stopChan = nil pm.cClient.Close() logging.Logger().Info(fmt.Sprintf("Auth: stopped")) } func (pm *probeManagers) handleProbe() { var err error defer func() { pm.stopWg.Done() pm.Stop() }() if err = pm.cClient.Connect(); nil != err { return } for { select { case <-pm.stopChan: return } } }