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.messages.AddRpc;
14 import org.opendaylight.controller.remote.rpc.messages.RemoveRpc;
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 public class RpcListener implements RpcRegistrationListener{
22 private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
23 private final ActorRef rpcRegistry;
24 private final String actorPath;
26 public RpcListener(ActorRef rpcRegistry, String actorPath) {
27 this.rpcRegistry = rpcRegistry;
28 this.actorPath = actorPath;
32 public void onRpcImplementationAdded(QName rpc) {
33 LOG.debug("Adding registration for [{}]", rpc);
34 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null);
35 AddRpc addRpcMsg = new AddRpc(routeId, actorPath);
37 ActorUtil.executeLocalOperation(rpcRegistry, addRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION);
38 LOG.debug("Route added [{}-{}]", routeId, this.actorPath);
39 } catch (Exception e) {
40 // Just logging it because Akka API throws this exception
41 LOG.error(e.toString());
47 public void onRpcImplementationRemoved(QName rpc) {
48 LOG.debug("Removing registration for [{}]", rpc);
49 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null);
50 RemoveRpc removeRpcMsg = new RemoveRpc(routeId);
52 ActorUtil.executeLocalOperation(rpcRegistry, removeRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION);
53 } catch (Exception e) {
54 // Just logging it because Akka API throws this exception
55 LOG.error(e.toString());