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;
15 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
16 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes;
17 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes;
18 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
19 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
20 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than {@link RemoteRpcImplementation}.
26 * The knowledge of such implementations is forwarded to {@link RpcRegistry}, which is responsible for advertising
27 * their presence to other nodes.
29 final class RpcListener implements DOMRpcAvailabilityListener {
30 private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
32 private final ActorRef rpcRegistry;
34 RpcListener(final ActorRef rpcRegistry) {
35 this.rpcRegistry = requireNonNull(rpcRegistry);
39 public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
40 checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
41 LOG.debug("Adding registration for [{}]", rpcs);
43 rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
47 public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
48 checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
50 LOG.debug("Removing registration for [{}]", rpcs);
51 rpcRegistry.tell(new RemoveRoutes(rpcs), ActorRef.noSender());
55 public boolean acceptsImplementation(final DOMRpcImplementation impl) {
56 return !(impl instanceof RemoteRpcImplementation);