Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / OpsListener.java
@@ -12,9 +12,14 @@ import static java.util.Objects.requireNonNull;
 
 import akka.actor.ActorRef;
 import java.util.Collection;
+import java.util.Set;
+import org.opendaylight.controller.remote.rpc.registry.ActionRegistry;
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes;
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes;
+import org.opendaylight.mdsal.dom.api.DOMActionAvailabilityExtension;
+import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
+import org.opendaylight.mdsal.dom.api.DOMActionInstance;
 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
@@ -22,17 +27,20 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than {@link RemoteRpcImplementation}.
- * The knowledge of such implementations is forwarded to {@link RpcRegistry}, which is responsible for advertising
- * their presence to other nodes.
+ * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than
+ * {@link RemoteRpcImplementation} or {@link RemoteActionImplementation}.
+ * The knowledge of such implementations is forwarded to {@link RpcRegistry} and {@link ActionRegistry},
+ * which is responsible for advertising their presence to other nodes.
  */
-final class RpcListener implements DOMRpcAvailabilityListener {
-    private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
+final class OpsListener implements DOMRpcAvailabilityListener, DOMActionAvailabilityExtension.AvailabilityListener {
+    private static final Logger LOG = LoggerFactory.getLogger(OpsListener.class);
 
     private final ActorRef rpcRegistry;
+    private final ActorRef actionRegistry;
 
-    RpcListener(final ActorRef rpcRegistry) {
+    OpsListener(final ActorRef rpcRegistry, final ActorRef actionRegistry) {
         this.rpcRegistry = requireNonNull(rpcRegistry);
+        this.actionRegistry = requireNonNull(actionRegistry);
     }
 
     @Override
@@ -55,4 +63,16 @@ final class RpcListener implements DOMRpcAvailabilityListener {
     public boolean acceptsImplementation(final DOMRpcImplementation impl) {
         return !(impl instanceof RemoteRpcImplementation);
     }
+
+    @Override
+    public boolean acceptsImplementation(final DOMActionImplementation impl) {
+        return !(impl instanceof RemoteActionImplementation);
+    }
+
+    @Override
+    public void onActionsChanged(final Set<DOMActionInstance> removed, final Set<DOMActionInstance> added) {
+        LOG.debug("adding registration for [{}]", added);
+        LOG.debug("removing registration for [{}]", removed);
+        actionRegistry.tell(new ActionRegistry.Messages.UpdateActions(added, removed), ActorRef.noSender());
+    }
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.