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 akka.actor.ActorRef;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
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.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than {@link RemoteRpcImplementation}.
25 * The knowledge of such implementations is forwarded to {@link RpcRegistry}, which is responsible for advertising
26 * their presence to other nodes.
28 final class RpcListener implements DOMRpcAvailabilityListener {
29 private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
31 private final ActorRef rpcRegistry;
33 RpcListener(final ActorRef rpcRegistry) {
34 this.rpcRegistry = Preconditions.checkNotNull(rpcRegistry);
38 public void onRpcAvailable(@Nonnull final Collection<DOMRpcIdentifier> rpcs) {
39 Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
40 LOG.debug("Adding registration for [{}]", rpcs);
42 rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
46 public void onRpcUnavailable(@Nonnull final Collection<DOMRpcIdentifier> rpcs) {
47 Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
49 LOG.debug("Removing registration for [{}]", rpcs);
50 rpcRegistry.tell(new RemoveRoutes(rpcs), ActorRef.noSender());
54 public boolean acceptsImplementation(final DOMRpcImplementation impl) {
55 return !(impl instanceof RemoteRpcImplementation);