joao-r-reis commented on code in PR #1929:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1929#discussion_r2794750371


##########
event_listeners.go:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40
+ * Copyright (c) 2012, The Gocql authors,
+ * provided under the BSD-3-Clause License.
+ * See the NOTICE file distributed with this work for additional information.
+ */
+
+package gocql
+
+import "net"
+
+// TopologyChangeListener receives topology change events.
+// Host may be nil if the node is not yet known to the ring.
+type TopologyChangeListener interface {
+       OnNewNode(event NewNodeEvent)
+       OnRemovedNode(event RemovedNodeEvent)
+}
+
+// TODO: thinking about this, do we actually need different struct for each 
event type?
+// Having structs as a parameter to the event handlers allows us to add more 
fields
+// in the future without breaking the API, but it does add some boilerplate 
code and
+// I'm unsure if we really need it.
+
+type NewNodeEvent struct {
+       Host *HostInfo
+       IP   net.IP
+       Port int
+}
+
+type RemovedNodeEvent struct {
+       Host *HostInfo
+       IP   net.IP
+       Port int
+}
+
+// NodeStatusChangeListener receives node state change events.
+// Host may be nil if the node is not yet known to the ring.
+type NodeStatusChangeListener interface {
+       OnNodeUp(event NodeUpEvent)
+       OnNodeDown(event NodeDownEvent)
+}
+
+type NodeUpEvent struct {
+       Host *HostInfo
+       IP   net.IP
+       Port int
+}
+
+type NodeDownEvent struct {
+       Host *HostInfo
+       IP   net.IP
+       Port int
+}
+
+// SchemaChangeListener receives schema change events.
+type SchemaChangeListener interface {
+       OnKeyspaceCreated(event KeyspaceCreatedEvent)
+       OnKeyspaceUpdated(event KeyspaceUpdatedEvent)
+       OnKeyspaceDropped(event KeyspaceDroppedEvent)
+
+       OnTableCreated(event TableCreatedEvent)
+       OnTableUpdated(event TableUpdatedEvent)
+       OnTableDropped(event TableDroppedEvent)
+
+       OnTypeCreated(event UserTypeCreatedEvent)
+       OnTypeUpdated(event UserTypeUpdatedEvent)
+       OnTypeDropped(event UserTypeDroppedEvent)
+
+       OnFunctionCreated(event FunctionCreatedEvent)
+       OnFunctionUpdated(event FunctionUpdatedEvent)
+       OnFunctionDropped(event FunctionDroppedEvent)
+
+       OnAggregateCreated(event AggregateCreatedEvent)
+       OnAggregateUpdated(event AggregateUpdatedEvent)
+       OnAggregateDropped(event AggregateDroppedEvent)
+}

Review Comment:
   Let's split this interface. I was thinking something like this:
   
   ```
   type SchemaChangeOptions struct {
       KeyspaceListener KeyspaceEventListener
       TableListener       TableEventListener
       UserTypeListener UserTypeEventListener
       FunctionListener FunctionEventListener
       AggregateListener AggregateEventListener
   }
   // and then each Listener interface has the respective 
Created/Updated/Dropped events
   ```
   
   This allows users to only subscribe to the type of schema events they want 
(it's quite likely that someone might only care about keyspace or table events 
for example).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to