Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / OpsListener.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 package org.opendaylight.controller.remote.rpc;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import akka.actor.ActorRef;
14 import java.util.Collection;
15 import java.util.Set;
16 import org.opendaylight.controller.remote.rpc.registry.ActionRegistry;
17 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
18 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes;
19 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes;
20 import org.opendaylight.mdsal.dom.api.DOMActionAvailabilityExtension;
21 import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
22 import org.opendaylight.mdsal.dom.api.DOMActionInstance;
23 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
24 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
25 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * A {@link DOMRpcAvailabilityListener} reacting to RPC implementations different than
31  * {@link RemoteRpcImplementation} or {@link RemoteActionImplementation}.
32  * The knowledge of such implementations is forwarded to {@link RpcRegistry} and {@link ActionRegistry},
33  * which is responsible for advertising their presence to other nodes.
34  */
35 final class OpsListener implements DOMRpcAvailabilityListener, DOMActionAvailabilityExtension.AvailabilityListener {
36     private static final Logger LOG = LoggerFactory.getLogger(OpsListener.class);
37
38     private final ActorRef rpcRegistry;
39     private final ActorRef actionRegistry;
40
41     OpsListener(final ActorRef rpcRegistry, final ActorRef actionRegistry) {
42         this.rpcRegistry = requireNonNull(rpcRegistry);
43         this.actionRegistry = requireNonNull(actionRegistry);
44     }
45
46     @Override
47     public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
48         checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
49         LOG.debug("Adding registration for [{}]", rpcs);
50
51         rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
52     }
53
54     @Override
55     public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
56         checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
57
58         LOG.debug("Removing registration for [{}]", rpcs);
59         rpcRegistry.tell(new RemoveRoutes(rpcs), ActorRef.noSender());
60     }
61
62     @Override
63     public boolean acceptsImplementation(final DOMRpcImplementation impl) {
64         return !(impl instanceof RemoteRpcImplementation);
65     }
66
67     @Override
68     public boolean acceptsImplementation(final DOMActionImplementation impl) {
69         return !(impl instanceof RemoteActionImplementation);
70     }
71
72     @Override
73     public void onActionsChanged(final Set<DOMActionInstance> removed, final Set<DOMActionInstance> added) {
74         LOG.debug("adding registration for [{}]", added);
75         LOG.debug("removing registration for [{}]", removed);
76         actionRegistry.tell(new ActionRegistry.Messages.UpdateActions(added, removed), ActorRef.noSender());
77     }
78 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.