Implementation for enabling remote rpc calls between 2 instances of md-sal
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / implementation / src / main / java / org / opendaylight / controller / sal / connector / remoterpc / RoutingTableProvider.java
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java
new file mode 100644 (file)
index 0000000..cfdf986
--- /dev/null
@@ -0,0 +1,32 @@
+package org.opendaylight.controller.sal.connector.remoterpc;
+
+import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+import com.google.common.base.Optional;
+
+public class RoutingTableProvider implements AutoCloseable {
+
+    @SuppressWarnings("rawtypes")
+    final ServiceTracker<RoutingTable,RoutingTable> tracker;
+    
+    
+    public RoutingTableProvider(BundleContext ctx) {
+        @SuppressWarnings("rawtypes")
+        ServiceTracker<RoutingTable, RoutingTable> rawTracker = new ServiceTracker<>(ctx, RoutingTable.class, null);
+        tracker = rawTracker;
+        tracker.open();
+    }
+    
+    public Optional<RoutingTable<String, String>> getRoutingTable() {
+        @SuppressWarnings("unchecked")
+        RoutingTable<String,String> tracked = tracker.getService();
+        return Optional.fromNullable(tracked);
+    }
+
+    @Override
+    public void close() throws Exception {
+        tracker.close();
+    }
+}