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;
11 import static java.util.Objects.requireNonNull;
13 import akka.actor.ActorRef;
14 import akka.actor.OneForOneStrategy;
15 import akka.actor.Props;
16 import akka.actor.SupervisorStrategy;
17 import java.util.concurrent.TimeUnit;
18 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
19 import org.opendaylight.controller.remote.rpc.registry.ActionRegistry;
20 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
21 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
22 import org.opendaylight.mdsal.dom.api.DOMActionService;
23 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
24 import org.opendaylight.mdsal.dom.api.DOMRpcService;
25 import org.opendaylight.yangtools.concepts.Registration;
26 import scala.concurrent.duration.FiniteDuration;
29 * This class acts as a supervisor, creates all the actors, resumes them, if an exception is thrown. It also registers
30 * {@link OpsListener} with the local {@link DOMRpcService}.
32 public class OpsManager extends AbstractUntypedActor {
33 private final DOMRpcProviderService rpcProvisionRegistry;
34 private final RemoteOpsProviderConfig config;
35 private final DOMRpcService rpcServices;
36 private final DOMActionProviderService actionProvisionRegistry;
37 private final DOMActionService actionService;
39 private Registration listenerReg;
40 private ActorRef opsInvoker;
41 private ActorRef actionRegistry;
42 private ActorRef rpcRegistry;
43 private ActorRef opsRegistrar;
45 OpsManager(final DOMRpcProviderService rpcProvisionRegistry, final DOMRpcService rpcServices,
46 final RemoteOpsProviderConfig config, final DOMActionProviderService actionProviderService,
47 final DOMActionService actionService) {
48 this.rpcProvisionRegistry = requireNonNull(rpcProvisionRegistry);
49 this.rpcServices = requireNonNull(rpcServices);
50 this.config = requireNonNull(config);
51 actionProvisionRegistry = requireNonNull(actionProviderService);
52 this.actionService = requireNonNull(actionService);
55 public static Props props(final DOMRpcProviderService rpcProvisionRegistry, final DOMRpcService rpcServices,
56 final RemoteOpsProviderConfig config,
57 final DOMActionProviderService actionProviderService,
58 final DOMActionService actionService) {
59 requireNonNull(rpcProvisionRegistry, "RpcProviderService can not be null!");
60 requireNonNull(rpcServices, "RpcService can not be null!");
61 requireNonNull(config, "RemoteOpsProviderConfig can not be null!");
62 requireNonNull(actionProviderService, "ActionProviderService can not be null!");
63 requireNonNull(actionService, "ActionService can not be null!");
64 return Props.create(OpsManager.class, rpcProvisionRegistry, rpcServices, config,
65 actionProviderService, actionService);
69 public void preStart() throws Exception {
72 opsInvoker = getContext().actorOf(OpsInvoker.props(rpcServices, actionService)
73 .withMailbox(config.getMailBoxName()), config.getRpcBrokerName());
74 LOG.debug("Listening for RPC invocation requests with {}", opsInvoker);
76 opsRegistrar = getContext().actorOf(OpsRegistrar.props(config, rpcProvisionRegistry, actionProvisionRegistry)
77 .withMailbox(config.getMailBoxName()), config.getRpcRegistrarName());
78 LOG.debug("Registering remote RPCs with {}", opsRegistrar);
80 rpcRegistry = getContext().actorOf(RpcRegistry.props(config, opsInvoker, opsRegistrar)
81 .withMailbox(config.getMailBoxName()), config.getRpcRegistryName());
82 LOG.debug("Propagating RPC information with {}", rpcRegistry);
84 actionRegistry = getContext().actorOf(ActionRegistry.props(config, opsInvoker, opsRegistrar)
85 .withMailbox(config.getMailBoxName()), config.getActionRegistryName());
86 LOG.debug("Propagating action information with {}", actionRegistry);
88 final OpsListener opsListener = new OpsListener(rpcRegistry, actionRegistry);
89 LOG.debug("Registering local availability listener {}", opsListener);
90 listenerReg = rpcServices.registerRpcListener(opsListener);
94 public void postStop() throws Exception {
95 if (listenerReg != null) {
104 protected void handleReceive(final Object message) {
105 unknownMessage(message);
109 public SupervisorStrategy supervisorStrategy() {
110 return new OneForOneStrategy(10, FiniteDuration.create(1, TimeUnit.MINUTES), t -> {
111 LOG.error("An exception happened actor will be resumed", t);
112 return SupervisorStrategy.resume();