From 2627e114ff9a2809ada96479cf5b0ff95835d1b5 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 15 May 2017 14:50:14 +0900 Subject: [PATCH] long poller --- poller.go | 13 +++++-------- poller_event.go | 50 ++++++++++++++++++++++++------------------------- poller_test.go | 36 +++++++++++++++++------------------ 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/poller.go b/poller.go index da31b57..52edb7a 100644 --- a/poller.go +++ b/poller.go @@ -13,7 +13,6 @@ import ( const ( POLLING_ID = "OVERFLOW_LONG_POLLING" - DEFAULT_INTERVAL = uint64(3) ) var ( @@ -22,11 +21,11 @@ var ( ) type Poller struct { - once sync.Once - runStat chan bool - gconf *cm.GlobalConfig - scheduler *s.Scheduler - taskCh chan interface{} + once sync.Once + runStat chan bool + gconf *cm.GlobalConfig + scheduler *s.Scheduler + taskCh chan interface{} } func Start(conf *cm.GlobalConfig) (chan interface{}, error) { @@ -74,7 +73,6 @@ func (p *Poller) handleInterval(ch chan interface{}) { func (p *Poller) Stop(ch chan interface{}) { p.scheduler.Stop() p.runStat <- false - p.removeAgentStopHandler(ch) } func (p *Poller) polling(agentId string) { @@ -113,7 +111,6 @@ func (p *Poller) updateInterval(interval string) { p.scheduler.UpdateInterval(POLLING_ID, uint64(i)) } - /* func printStatusStream(client pb.StatusClient) { stream, err := client.Status(context.Background(), &pb.Empty{}) diff --git a/poller_event.go b/poller_event.go index 24e3fa8..fc55c2a 100644 --- a/poller_event.go +++ b/poller_event.go @@ -1,27 +1,27 @@ package long_poller_go -import ( - "loafle.com/overflow/agent_api/observer" - "loafle.com/overflow/agent_api/observer/messages" -) - -func handleConfigLoaded() { - ch := make(chan interface{}, 0) - observer.Add(messages.CFG_LOADED, ch) - startPoller(ch) -} - -func (p *Poller) handleAgentStop() { - ch := make(chan interface{}, 0) - observer.Add(messages.AGT_STOPPED, ch) - _ = <- ch - p.Stop(ch) -} - -func (p *Poller) removeConfigLoadedHandler(ch chan interface{}) { - observer.Remove(messages.CFG_LOADED, ch) -} - -func (p *Poller) removeAgentStopHandler(ch chan interface{}) { - observer.Remove(messages.AGT_STOPPED, ch) -} +//import ( +// "loafle.com/overflow/agent_api/observer" +// "loafle.com/overflow/agent_api/observer/messages" +//) +// +//func handleConfigLoaded() { +// ch := make(chan interface{}, 0) +// observer.Add(messages.CFG_LOADED, ch) +// startPoller(ch) +//} +// +//func (p *Poller) handleAgentStop() { +// ch := make(chan interface{}, 0) +// observer.Add(messages.AGT_STOPPED, ch) +// _ = <-ch +// p.Stop(ch) +//} +// +//func (p *Poller) removeConfigLoadedHandler(ch chan interface{}) { +// observer.Remove(messages.CFG_LOADED, ch) +//} +// +//func (p *Poller) removeAgentStopHandler(ch chan interface{}) { +// observer.Remove(messages.AGT_STOPPED, ch) +//} diff --git a/poller_test.go b/poller_test.go index 9b4112a..da85903 100644 --- a/poller_test.go +++ b/poller_test.go @@ -1,20 +1,20 @@ package long_poller_go -import ( - "loafle.com/overflow/agent_api/observer" - "loafle.com/overflow/agent_api/observer/messages" - "testing" - "time" -) - -func TestPolling(t *testing.T) { - poller := &Poller{} - poller.start() -} - -func TestTotal(t *testing.T) { - time.Sleep(time.Second * 5) - - observer.Notify(messages.CFG_LOADED, "") //CONFIG LOCATION - time.Sleep(time.Second * 100) -} +//import ( +// "loafle.com/overflow/agent_api/observer" +// "loafle.com/overflow/agent_api/observer/messages" +// "testing" +// "time" +//) +// +//func TestPolling(t *testing.T) { +// poller := &Poller{} +// poller.start() +//} +// +//func TestTotal(t *testing.T) { +// time.Sleep(time.Second * 5) +// +// observer.Notify(messages.CFG_LOADED, "") //CONFIG LOCATION +// time.Sleep(time.Second * 100) +//}