2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.remote.rpc;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import akka.actor.ActorRef;
14 import java.util.Collection;
16 import org.opendaylight.controller.remote.rpc.registry.ActionRegistry;
17 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
18 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes;
19 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes;
20 import org.opendaylight.mdsal.dom.api.DOMActionAvailabilityExtension;
21 import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
22 import org.opendaylight.mdsal.dom.api.DOMActionInstance;
23 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
24 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
25 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than
31 * {@link RemoteRpcImplementation} or {@link RemoteActionImplementation}.
32 * The knowledge of such implementations is forwarded to {@link RpcRegistry} and {@link ActionRegistry},
33 * which is responsible for advertising their presence to other nodes.
35 final class OpsListener implements DOMRpcAvailabilityListener, DOMActionAvailabilityExtension.AvailabilityListener {
36 private static final Logger LOG = LoggerFactory.getLogger(OpsListener.class);
38 private final ActorRef rpcRegistry;
39 private final ActorRef actionRegistry;
41 OpsListener(final ActorRef rpcRegistry, final ActorRef actionRegistry) {
42 this.rpcRegistry = requireNonNull(rpcRegistry);
43 this.actionRegistry = requireNonNull(actionRegistry);
47 public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
48 checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
49 LOG.debug("Adding registration for [{}]", rpcs);
51 rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
55 public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
56 checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
58 LOG.debug("Removing registration for [{}]", rpcs);
59 rpcRegistry.tell(new RemoveRoutes(rpcs), ActorRef.noSender());
63 public boolean acceptsImplementation(final DOMRpcImplementation impl) {
64 return !(impl instanceof RemoteRpcImplementation);
68 public boolean acceptsImplementation(final DOMActionImplementation impl) {
69 return !(impl instanceof RemoteActionImplementation);
73 public void onActionsChanged(final Set<DOMActionInstance> removed, final Set<DOMActionInstance> added) {
74 LOG.debug("adding registration for [{}]", added);
75 LOG.debug("removing registration for [{}]", removed);
76 actionRegistry.tell(new ActionRegistry.Messages.UpdateActions(added, removed), ActorRef.noSender());