mirror of https://github.com/status-im/consul.git
consul: type safe event handlers
This commit is contained in:
parent
15a1cf589b
commit
c4a4b9df34
|
@ -1,11 +1,27 @@
|
||||||
package consul
|
package consul
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/serf/serf"
|
||||||
|
)
|
||||||
|
|
||||||
// lanEventHandler is used to handle events from the lan Serf cluster
|
// lanEventHandler is used to handle events from the lan Serf cluster
|
||||||
func (s *Server) lanEventHandler() {
|
func (s *Server) lanEventHandler() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-s.eventChLAN:
|
case e := <-s.eventChLAN:
|
||||||
s.logger.Printf("[INFO] LAN Event: %v", e)
|
switch e.EventType() {
|
||||||
|
case serf.EventMemberJoin:
|
||||||
|
s.localJoin(e.(serf.MemberEvent))
|
||||||
|
case serf.EventMemberLeave:
|
||||||
|
s.localLeave(e.(serf.MemberEvent))
|
||||||
|
case serf.EventMemberFailed:
|
||||||
|
s.localFailed(e.(serf.MemberEvent))
|
||||||
|
case serf.EventUser:
|
||||||
|
s.localEvent(e.(serf.UserEvent))
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[WARN] Unhandled LAN Serf Event: %#v", e)
|
||||||
|
}
|
||||||
|
|
||||||
case <-s.shutdownCh:
|
case <-s.shutdownCh:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -17,9 +33,53 @@ func (s *Server) wanEventHandler() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-s.eventChWAN:
|
case e := <-s.eventChWAN:
|
||||||
s.logger.Printf("[INFO] WAN Event: %v", e)
|
switch e.EventType() {
|
||||||
|
case serf.EventMemberJoin:
|
||||||
|
s.remoteJoin(e.(serf.MemberEvent))
|
||||||
|
case serf.EventMemberLeave:
|
||||||
|
s.remoteLeave(e.(serf.MemberEvent))
|
||||||
|
case serf.EventMemberFailed:
|
||||||
|
s.remoteFailed(e.(serf.MemberEvent))
|
||||||
|
case serf.EventUser:
|
||||||
|
s.remoteEvent(e.(serf.UserEvent))
|
||||||
|
default:
|
||||||
|
s.logger.Printf("[WARN] Unhandled LAN Serf Event: %#v", e)
|
||||||
|
}
|
||||||
|
|
||||||
case <-s.shutdownCh:
|
case <-s.shutdownCh:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// localJoin is used to handle join events on the lan serf cluster
|
||||||
|
func (s *Server) localJoin(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// localLeave is used to handle leave events on the lan serf cluster
|
||||||
|
func (s *Server) localLeave(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// localFailed is used to handle fail events on the lan serf cluster
|
||||||
|
func (s *Server) localFailed(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// localEvent is used to handle events on the lan serf cluster
|
||||||
|
func (s *Server) localEvent(ue serf.UserEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteJoin is used to handle join events on the wan serf cluster
|
||||||
|
func (s *Server) remoteJoin(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteLeave is used to handle leave events on the wan serf cluster
|
||||||
|
func (s *Server) remoteLeave(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteFailed is used to handle fail events on the wan serf cluster
|
||||||
|
func (s *Server) remoteFailed(me serf.MemberEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteEvent is used to handle events on the wan serf cluster
|
||||||
|
func (s *Server) remoteEvent(ue serf.UserEvent) {
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue