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.remote.rpc.utils.ActorUtil;
16 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class RpcListener implements RpcRegistrationListener{
23 private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
24 private final ActorRef rpcRegistry;
25 private final String actorPath;
27 public RpcListener(ActorRef rpcRegistry, String actorPath) {
28 this.rpcRegistry = rpcRegistry;
29 this.actorPath = actorPath;
33 public void onRpcImplementationAdded(QName rpc) {
34 LOG.debug("Adding registration for [{}]", rpc);
35 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null);
36 AddRpc addRpcMsg = new AddRpc(routeId, actorPath);
38 ActorUtil.executeLocalOperation(rpcRegistry, addRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION);
39 LOG.debug("Route added [{}-{}]", routeId, this.actorPath);
40 } catch (Exception e) {
41 // Just logging it because Akka API throws this exception
42 LOG.error(e.toString());
48 public void onRpcImplementationRemoved(QName rpc) {
49 LOG.debug("Removing registration for [{}]", rpc);
50 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null);
51 RemoveRpc removeRpcMsg = new RemoveRpc(routeId);
53 ActorUtil.executeLocalOperation(rpcRegistry, removeRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION);
54 } catch (Exception e) {
55 // Just logging it because Akka API throws this exception
56 LOG.error(e.toString());