2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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
8 package org.opendaylight.controller.cluster.akka.osgi.impl;
10 import akka.actor.ActorSystem;
11 import com.typesafe.config.Config;
12 import java.util.concurrent.TimeoutException;
13 import org.opendaylight.controller.cluster.ActorSystemProvider;
14 import org.opendaylight.controller.cluster.ActorSystemProviderListener;
15 import org.opendaylight.controller.cluster.akka.impl.ActorSystemProviderImpl;
16 import org.opendaylight.controller.cluster.akka.impl.AkkaConfigFactory;
17 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.service.component.annotations.Activate;
21 import org.osgi.service.component.annotations.Component;
22 import org.osgi.service.component.annotations.Deactivate;
23 import org.osgi.service.component.annotations.Reference;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import scala.concurrent.Await;
27 import scala.concurrent.duration.Duration;
29 @Component(immediate = true)
30 public final class OSGiActorSystemProvider implements ActorSystemProvider {
31 private static final Logger LOG = LoggerFactory.getLogger(OSGiActorSystemProvider.class);
34 AkkaConfigurationReader reader = null;
36 private ActorSystemProviderImpl delegate;
39 public ActorSystem getActorSystem() {
40 return delegate.getActorSystem();
44 public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
45 final ActorSystemProviderListener listener) {
46 return delegate.registerActorSystemProviderListener(listener);
50 void activate(final BundleContext bundleContext) {
51 LOG.info("Actor System provider starting");
52 final Config akkaConfig = AkkaConfigFactory.createAkkaConfig(reader);
53 delegate = new ActorSystemProviderImpl(BundleClassLoaderFactory.createClassLoader(bundleContext),
54 QuarantinedMonitorActorPropsFactory.createProps(bundleContext, akkaConfig), akkaConfig);
55 LOG.info("Actor System provider started");
59 void deactivate() throws TimeoutException, InterruptedException {
60 LOG.info("Actor System provider stopping");
61 Await.result(delegate.asyncClose(), Duration.Inf());
63 LOG.info("Actor System provider stopped");