Added new notification framework:
* The listener has to implement the IEventChannelListener interface.
* A listener subscribes to a notification channel by using
IDatagridService.addListener(), and unsubscribes by using
IDatagridService.removeListener()
The channel is created and started automatically when the first
listener is added.
* A channel can be created by using IDatagridService.createChannel()
e.g., by the publisher of events. Note that createChannel() automatically
starts the event channel operation.
* A publisher uses IEventChannel.addEntry() and removeEntry() to generate
add/delete events.
* The listener receives the add/remove events by implementing
the IEventChannelListener.entryAdded() and entryRemoved() methods.
Example of usage:
Listener/Subscriber:
private FooFlowPath fooFlowPath = new FooFlowPath();
datagridService.addListener("mapFooFlowPath", fooFlowPath,
Long.class, FlowPath.class);
...
class FooFlowPath implements IEventChannelListener<Long, FlowPath> {
/**
* Receive a notification that an entry is added.
*
* @param value the value for the entry.
*/
@Override
public void entryAdded(FlowPath value) {
// Process the event
}
/**
* Receive a notification that an entry is removed.
*
* @param value the value for the entry.
*/
@Override
public void entryRemoved(FlowPath value) {
// Process the event
}
...
}
Sender/Publisher:
private IEventChannel<Long, FlowPath> fooFlowPathChannel = null;
fooFlowPathChannel = datagridService.createChannel("mapFooFlowPath",
Long.class, FlowPath.class);
...
// Transmit an event
fooFlowPathChannel.addEntry(flowPath.flowId().value(), flowPath);
Change-Id: Ie3246a4e200d5b6293c1f175df3652cdf571be69
diff --git a/src/main/java/net/onrc/onos/datagrid/IEventChannel.java b/src/main/java/net/onrc/onos/datagrid/IEventChannel.java
new file mode 100644
index 0000000..7479491
--- /dev/null
+++ b/src/main/java/net/onrc/onos/datagrid/IEventChannel.java
@@ -0,0 +1,88 @@
+package net.onrc.onos.datagrid;
+
+import java.util.Collection;
+
+/**
+ * Event Channel Interface.
+ */
+public interface IEventChannel<K, V> {
+ /**
+ * Startup the channel operation.
+ */
+ void startup();
+
+ /**
+ * Shutdown the channel operation.
+ */
+ void shutdown();
+
+ /**
+ * Verify the key and value types of a channel.
+ *
+ * @param typeK the type of the key to verify.
+ * @param typeV the type of the value to verify.
+ * @return true if the key and value types of the channel match,
+ * otherwise false.
+ */
+ boolean verifyKeyValueTypes(Class typeK, Class typeV);
+
+ /**
+ * Add event channel listener.
+ *
+ * @param listener the listener to add.
+ */
+ void addListener(IEventChannelListener<K, V> listener);
+
+ /**
+ * Remove event channel listener.
+ *
+ * @param listener the listener to remove.
+ */
+ void removeListener(IEventChannelListener<K, V> listener);
+
+ /**
+ * Add an entry to the channel.
+ *
+ * @param key the key of the entry to add.
+ * @param value the value of the entry to add.
+ */
+ void addEntry(K key, V value);
+
+ /**
+ * Remove an entry from the channel.
+ *
+ * @param key the key of the entry to remove.
+ */
+ void removeEntry(K key);
+
+ /**
+ * Update an entry in the channel.
+ *
+ * @param key the key of the entry to update.
+ * @param value the value of the entry to update.
+ */
+ void updateEntry(K key, V value);
+
+ /**
+ * Get an entry from the channel.
+ *
+ * @param key the key of the entry to get.
+ * @return the entry if found, otherwise null.
+ */
+ @Deprecated
+ V getEntry(K key);
+
+ /**
+ * Get all entries in the channel.
+ *
+ * @return all entries that are currently in the channel.
+ */
+ @Deprecated
+ Collection<V> getAllEntries();
+
+ /**
+ * Remove all entries in the channel.
+ */
+ @Deprecated
+ void removeAllEntries();
+}