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


##########
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)
+}
+
+type KeyspaceCreatedEvent struct {
+       Keyspace *KeyspaceMetadata
+}
+
+type KeyspaceUpdatedEvent struct {
+       Old *KeyspaceMetadata
+       New *KeyspaceMetadata
+}
+
+type KeyspaceDroppedEvent struct {
+       Keyspace *KeyspaceMetadata
+}
+
+type TableCreatedEvent struct {
+       Table *TableMetadata
+}
+
+type TableUpdatedEvent struct {
+       Old *TableMetadata
+       New *TableMetadata
+}
+
+type TableDroppedEvent struct {
+       Table *TableMetadata
+}
+
+type UserTypeCreatedEvent struct {
+       Type *UserTypeMetadata
+}
+
+type UserTypeUpdatedEvent struct {
+       Old *UserTypeMetadata
+       New *UserTypeMetadata
+}
+
+type UserTypeDroppedEvent struct {
+       Type *UserTypeMetadata
+}
+
+type FunctionCreatedEvent struct {
+       Function *FunctionMetadata
+}
+
+type FunctionUpdatedEvent struct {
+       Old *FunctionMetadata
+       New *FunctionMetadata
+}
+
+type FunctionDroppedEvent struct {
+       Function *FunctionMetadata
+}
+
+type AggregateCreatedEvent struct {
+       Aggregate *AggregateMetadata
+}
+
+type AggregateUpdatedEvent struct {
+       Old *AggregateMetadata
+       New *AggregateMetadata
+}
+
+type AggregateDroppedEvent struct {
+       Aggregate *AggregateMetadata
+}

Review Comment:
   I like that the events are consistent with the java driver API but I don't 
think we have the internal metadata system to handle this efficiently right 
now. We will probably be in a better state to implement this API once 
https://github.com/apache/cassandra-gocql-driver/pull/1926 is merged (the slack 
convo that is linked in one of the comments shows the discussion around my 
proposal for the new metadata system).



##########
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)

Review Comment:
   We already have a `HostStateNotifier` interface that pretty much does what 
we're looking for. The drawback is that a user can only use it by implementing 
a custom `HostSelectionPolicy`. We can just add a new `HostStateNotifier` field 
in the `Events` config struct instead of creating this one.



-- 
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