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
9 package org.opendaylight.controller.remote.rpc;
12 import akka.actor.ActorRef;
13 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
14 import org.opendaylight.controller.sal.connector.api.RpcRouter;
15 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.util.ArrayList;
21 import java.util.List;
23 public class RpcListener implements RpcRegistrationListener{
25 private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
26 private final ActorRef rpcRegistry;
28 public RpcListener(ActorRef rpcRegistry) {
29 this.rpcRegistry = rpcRegistry;
33 public void onRpcImplementationAdded(QName rpc) {
34 if(LOG.isDebugEnabled()) {
35 LOG.debug("Adding registration for [{}]", rpc);
37 RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
38 List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
39 routeIds.add(routeId);
40 RpcRegistry.Messages.AddOrUpdateRoutes addRpcMsg = new RpcRegistry.Messages.AddOrUpdateRoutes(routeIds);
41 rpcRegistry.tell(addRpcMsg, ActorRef.noSender());
45 public void onRpcImplementationRemoved(QName rpc) {
46 if(LOG.isDebugEnabled()) {
47 LOG.debug("Removing registration for [{}]", rpc);
49 RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
50 List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
51 routeIds.add(routeId);
52 RpcRegistry.Messages.RemoveRoutes removeRpcMsg = new RpcRegistry.Messages.RemoveRoutes(routeIds);
53 rpcRegistry.tell(removeRpcMsg, ActorRef.noSender());