QuitService->BaseService

This commit is contained in:
Jae Kwon 2016-10-28 12:04:58 -07:00
parent 855255d73e
commit 161e36fd56
2 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ const (
) )
type WSClient struct { type WSClient struct {
QuitService BaseService
Address string // IP:PORT or /path/to/socket Address string // IP:PORT or /path/to/socket
Endpoint string // /websocket/url/endpoint Endpoint string // /websocket/url/endpoint
Dialer func(string, string) (net.Conn, error) Dialer func(string, string) (net.Conn, error)
@ -39,7 +39,7 @@ func NewWSClient(remoteAddr, endpoint string) *WSClient {
ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity), ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity),
ErrorsCh: make(chan error, wsErrorsChannelCapacity), ErrorsCh: make(chan error, wsErrorsChannelCapacity),
} }
wsClient.QuitService = *NewQuitService(log, "WSClient", wsClient) wsClient.BaseService = *NewBaseService(log, "WSClient", wsClient)
return wsClient return wsClient
} }
@ -48,7 +48,7 @@ func (wsc *WSClient) String() string {
} }
func (wsc *WSClient) OnStart() error { func (wsc *WSClient) OnStart() error {
wsc.QuitService.OnStart() wsc.BaseService.OnStart()
err := wsc.dial() err := wsc.dial()
if err != nil { if err != nil {
return err return err
@ -84,7 +84,7 @@ func (wsc *WSClient) dial() error {
} }
func (wsc *WSClient) OnStop() { func (wsc *WSClient) OnStop() {
wsc.QuitService.OnStop() wsc.BaseService.OnStop()
// ResultsCh/ErrorsCh is closed in receiveEventsRoutine. // ResultsCh/ErrorsCh is closed in receiveEventsRoutine.
} }

View File

@ -264,7 +264,7 @@ const (
// contains listener id, underlying ws connection, // contains listener id, underlying ws connection,
// and the event switch for subscribing to events // and the event switch for subscribing to events
type wsConnection struct { type wsConnection struct {
QuitService BaseService
remoteAddr string remoteAddr string
baseConn *websocket.Conn baseConn *websocket.Conn
@ -285,13 +285,13 @@ func NewWSConnection(baseConn *websocket.Conn, funcMap map[string]*RPCFunc, evsw
funcMap: funcMap, funcMap: funcMap,
evsw: evsw, evsw: evsw,
} }
wsc.QuitService = *NewQuitService(log, "wsConnection", wsc) wsc.BaseService = *NewBaseService(log, "wsConnection", wsc)
return wsc return wsc
} }
// wsc.Start() blocks until the connection closes. // wsc.Start() blocks until the connection closes.
func (wsc *wsConnection) OnStart() error { func (wsc *wsConnection) OnStart() error {
wsc.QuitService.OnStart() wsc.BaseService.OnStart()
// Read subscriptions/unsubscriptions to events // Read subscriptions/unsubscriptions to events
go wsc.readRoutine() go wsc.readRoutine()
@ -318,7 +318,7 @@ func (wsc *wsConnection) OnStart() error {
} }
func (wsc *wsConnection) OnStop() { func (wsc *wsConnection) OnStop() {
wsc.QuitService.OnStop() wsc.BaseService.OnStop()
wsc.evsw.RemoveListener(wsc.remoteAddr) wsc.evsw.RemoveListener(wsc.remoteAddr)
wsc.readTimeout.Stop() wsc.readTimeout.Stop()
wsc.pingTicker.Stop() wsc.pingTicker.Stop()