-import java.util.ArrayList;
-import java.util.List;
-
-public class RpcListener implements RpcRegistrationListener{
-
- private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
- private final ActorRef rpcRegistry;
-
- public RpcListener(ActorRef rpcRegistry) {
- this.rpcRegistry = rpcRegistry;
- }
-
- @Override
- public void onRpcImplementationAdded(QName rpc) {
- LOG.debug("Adding registration for [{}]", rpc);
- RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
- List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
- routeIds.add(routeId);
- RpcRegistry.Messages.AddOrUpdateRoutes addRpcMsg = new RpcRegistry.Messages.AddOrUpdateRoutes(routeIds);
- rpcRegistry.tell(addRpcMsg, ActorRef.noSender());
- }
-
- @Override
- public void onRpcImplementationRemoved(QName rpc) {
- LOG.debug("Removing registration for [{}]", rpc);
- RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
- List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
- routeIds.add(routeId);
- RpcRegistry.Messages.RemoveRoutes removeRpcMsg = new RpcRegistry.Messages.RemoveRoutes(routeIds);
- rpcRegistry.tell(removeRpcMsg, ActorRef.noSender());
- }
+/**
+ * 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.
+ */
+final class RpcListener implements DOMRpcAvailabilityListener {
+ private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
+
+ private final ActorRef rpcRegistry;
+
+ RpcListener(final ActorRef rpcRegistry) {
+ this.rpcRegistry = requireNonNull(rpcRegistry);
+ }
+
+ @Override
+ public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
+ checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
+ LOG.debug("Adding registration for [{}]", rpcs);
+
+ rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
+ }
+
+ @Override
+ public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
+ checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
+
+ LOG.debug("Removing registration for [{}]", rpcs);
+ rpcRegistry.tell(new RemoveRoutes(rpcs), ActorRef.noSender());
+ }
+
+ @Override
+ public boolean acceptsImplementation(final DOMRpcImplementation impl) {
+ return !(impl instanceof RemoteRpcImplementation);
+ }