Merge "Fix precondition formatting"
[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.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;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 public class RpcListener implements RpcRegistrationListener{
24
25   private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class);
26   private final ActorRef rpcRegistry;
27
28   public RpcListener(ActorRef rpcRegistry) {
29     this.rpcRegistry = rpcRegistry;
30   }
31
32   @Override
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());
40   }
41
42   @Override
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());
50   }
51 }