Adding ISharedCollectionsService and implementation in HazelcastDatagrid.
Change-Id: Iace8b57b4b8f6e43dadacaed0415c77f72efe46b
diff --git a/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
index ec870e4..1d0d8ea 100644
--- a/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
@@ -5,6 +5,8 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentMap;
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
@@ -27,7 +29,8 @@
* The relevant data is stored in the Hazelcast datagrid and shared as
* appropriate in a multi-node cluster.
*/
-public class HazelcastDatagrid implements IFloodlightModule, IDatagridService {
+public class HazelcastDatagrid implements IFloodlightModule, IDatagridService,
+ ISharedCollectionsService {
static final Logger log = LoggerFactory.getLogger(HazelcastDatagrid.class);
/**
@@ -119,6 +122,7 @@
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IDatagridService.class);
+ l.add(ISharedCollectionsService.class);
return l;
}
@@ -135,6 +139,7 @@
new HashMap<Class<? extends IFloodlightService>,
IFloodlightService>();
m.put(IDatagridService.class, this);
+ m.put(ISharedCollectionsService.class, this);
return m;
}
@@ -306,4 +311,31 @@
}
}
}
+
+ /**
+ * Create an shared, concurrent map.
+ *
+ * @param mapName the shared map name.
+ * @param typeK the type of the Key in the map.
+ * @param typeV the type of the Value in the map.
+ * @return the shared map for the channel name.
+ */
+ @Override
+ public <K, V> ConcurrentMap<K, V> getConcurrentMap(String mapName, Class<K> typeK,
+ Class<V> typeV) {
+ return hazelcastInstance.getMap(mapName);
+ }
+
+ /**
+ * Create an shared, blocking queue.
+ *
+ * @param queueName the shared queue name.
+ * @param typeT the type of the queue.
+ * @return the shared queue for the queue name.
+ */
+ @Override
+ public <T> BlockingQueue<T> getBlockingQueue(String queueName, Class<T> typeT) {
+ return hazelcastInstance.getQueue(queueName);
+ }
+
}
diff --git a/src/main/java/net/onrc/onos/core/datagrid/ISharedCollectionsService.java b/src/main/java/net/onrc/onos/core/datagrid/ISharedCollectionsService.java
new file mode 100644
index 0000000..30e5596
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/datagrid/ISharedCollectionsService.java
@@ -0,0 +1,32 @@
+package net.onrc.onos.core.datagrid;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentMap;
+
+import net.floodlightcontroller.core.module.IFloodlightService;
+
+/**
+ * Interface for providing shared maps and queues to other modules.
+ */
+public interface ISharedCollectionsService extends IFloodlightService {
+ /**
+ * Create an shared, concurrent map.
+ *
+ * @param mapName the shared map name.
+ * @param typeK the type of the Key in the map.
+ * @param typeV the type of the Value in the map.
+ * @return the shared map for the channel name.
+ */
+ <K, V> ConcurrentMap<K, V> getConcurrentMap(String mapName,
+ Class<K> typeK, Class<V> typeV);
+
+ /**
+ * Create an shared, blocking queue.
+ *
+ * @param queueName the shared queue name.
+ * @param typeT the type of the queue.
+ * @return the shared queue for the queue name.
+ */
+ <T> BlockingQueue<T> getBlockingQueue(String queueName,
+ Class<T> typeT);
+}