Merge "Wiring rest-connector with config subsytem."
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RpcListener.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.remote.rpc;
10
11
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;
19
20 public class RpcListener implements RpcRegistrationListener{
21
22   private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
23   private final ActorRef rpcRegistry;
24   private final String actorPath;
25
26   public RpcListener(ActorRef rpcRegistry, String actorPath) {
27     this.rpcRegistry = rpcRegistry;
28     this.actorPath = actorPath;
29   }
30
31   @Override
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);
36     try {
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());
42     }
43
44   }
45
46   @Override
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);
51     try {
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());
56     }
57   }
58 }