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 LOG.debug("Adding registration for [{}]", rpc);
35 RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
36 List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
37 routeIds.add(routeId);
38 RpcRegistry.Messages.AddOrUpdateRoutes addRpcMsg = new RpcRegistry.Messages.AddOrUpdateRoutes(routeIds);
39 rpcRegistry.tell(addRpcMsg, ActorRef.noSender());
43 public void onRpcImplementationRemoved(QName rpc) {
44 LOG.debug("Removing registration for [{}]", rpc);
45 RpcRouter.RouteIdentifier<?,?,?> routeId = new RouteIdentifierImpl(null, rpc, null);
46 List<RpcRouter.RouteIdentifier<?,?,?>> routeIds = new ArrayList<>();
47 routeIds.add(routeId);
48 RpcRegistry.Messages.RemoveRoutes removeRpcMsg = new RpcRegistry.Messages.RemoveRoutes(routeIds);
49 rpcRegistry.tell(removeRpcMsg, ActorRef.noSender());