Browse Source

cluster: add option to disable specific events

Add options to disable registering for status change and topology events
Chris Bannister 10 years ago
parent
commit
a22b1d9299
2 changed files with 22 additions and 1 deletions
  1. 8 0
      cluster.go
  2. 14 1
      control.go

+ 8 - 0
cluster.go

@@ -142,6 +142,14 @@ type ClusterConfig struct {
 	// such host filtering and token aware query routing will not be available.
 	DisableInitialHostLookup bool
 
+	// Configure events the driver will register for
+	Events struct {
+		// disable registering for status events (node up/down)
+		DisableNodeStatusEvents bool
+		// disable registering for topology events (node added/removed/moved)
+		DisableTopologyEvents bool
+	}
+
 	// internal config for testing
 	disableControlConn bool
 }

+ 14 - 1
control.go

@@ -123,8 +123,21 @@ func (c *controlConn) connect(endpoints []string) error {
 }
 
 func (c *controlConn) registerEvents(conn *Conn) error {
+	var events []string
+
+	if !c.session.cfg.Events.DisableTopologyEvents {
+		events = append(events, "TOPOLOGY_CHANGE")
+	}
+	if !c.session.cfg.Events.DisableNodeStatusEvents {
+		events = append(events, "STATUS_CHANGE")
+	}
+
+	if len(events) == 0 {
+		return nil
+	}
+
 	framer, err := conn.exec(&writeRegisterFrame{
-		events: []string{"TOPOLOGY_CHANGE", "STATUS_CHANGE", "STATUS_CHANGE"},
+		events: events,
 	}, nil)
 	if err != nil {
 		return err