Convert sal-remoterpc-provided to OSGi DS
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / OSGiRemoteOpsProvider.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.actor.PoisonPill;
13 import org.opendaylight.controller.cluster.ActorSystemProvider;
14 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
15 import org.opendaylight.mdsal.dom.api.DOMActionService;
16 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
17 import org.opendaylight.mdsal.dom.api.DOMRpcService;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
21 import org.osgi.service.component.annotations.Reference;
22 import org.osgi.service.metatype.annotations.AttributeDefinition;
23 import org.osgi.service.metatype.annotations.Designate;
24 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 @Component(immediate = true, configurationPid = "org.opendaylight.controller.remoterpc")
29 @Designate(ocd = OSGiRemoteOpsProvider.Config.class)
30 public final class OSGiRemoteOpsProvider {
31     @ObjectClassDefinition()
32     public @interface Config {
33         @AttributeDefinition(name = "enable-metric-capture")
34         boolean metricCapture() default true;
35         @AttributeDefinition(name = "bounded-mailbox-capacity")
36         int boundedMailboxCapacity() default 1000;
37     }
38
39     private static final Logger LOG = LoggerFactory.getLogger(OSGiRemoteOpsProvider.class);
40
41     @Reference
42     ActorSystemProvider actorSystemProvider = null;
43     @Reference
44     DOMRpcProviderService rpcProviderService = null;
45     @Reference
46     DOMRpcService rpcService = null;
47     @Reference
48     DOMActionProviderService actionProviderService = null;
49     @Reference
50     DOMActionService actionService = null;
51
52     private ActorRef opsManager;
53
54     @Activate
55     void activate(final Config config) {
56         LOG.info("Remote Operations service starting");
57         final ActorSystem actorSystem = actorSystemProvider.getActorSystem();
58         final RemoteOpsProviderConfig opsConfig = RemoteOpsProviderConfig.newInstance(actorSystem.name(),
59             config.metricCapture(), config.boundedMailboxCapacity());
60
61         opsManager = actorSystem.actorOf(OpsManager.props(rpcProviderService, rpcService, opsConfig,
62                 actionProviderService, actionService), opsConfig.getRpcManagerName());
63         LOG.debug("Ops Manager started at {}", opsManager);
64         LOG.info("Remote Operations service started");
65     }
66
67     @Deactivate
68     void deactivate() {
69         LOG.info("Remote Operations service stopping");
70         LOG.debug("Stopping Ops Manager at {}", opsManager);
71         opsManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
72         opsManager = null;
73         LOG.info("Remote Operations services stopped");
74     }
75 }