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/IDatagridService.java b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
index d3cf98e..118cbfa 100755
--- a/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
+++ b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
@@ -21,6 +21,45 @@
* Interface for providing Datagrid Service to other modules.
*/
public interface IDatagridService extends IFloodlightService {
+ /**
+ * Create an event channel.
+ *
+ * If the channel already exists, just return it.
+ * NOTE: The channel is started automatically.
+ *
+ * @param channelName the event channel name.
+ * @param typeK the type of the Key in the Key-Value store.
+ * @param typeV the type of the Value in the Key-Value store.
+ * @return the event channel for the channel name.
+ */
+ <K, V> IEventChannel<K, V> createChannel(String channelName,
+ Class<K> typeK, Class<V> typeV);
+
+ /**
+ * Add event channel listener.
+ *
+ * NOTE: The channel is started automatically right after the listener
+ * is added.
+ *
+ * @param channelName the event channel name.
+ * @param listener the listener to add.
+ * @param typeK the type of the Key in the Key-Value store.
+ * @param typeV the type of the Value in the Key-Value store.
+ * @return the event channel for the channel name.
+ */
+ <K, V> IEventChannel<K, V> addListener(String channelName,
+ IEventChannelListener<K, V> listener,
+ Class<K> typeK, Class<V> typeV);
+
+ /**
+ * Remove event channel listener.
+ *
+ * @param channelName the event channel name.
+ * @param listener the listener to remove.
+ */
+ <K, V> void removeListener(String channelName,
+ IEventChannelListener<K, V> listener);
+
/*
* register all the intents as one batch
*/