2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.controller.config.yang.config.actor_system_provider.impl;
10 import akka.actor.ActorSystem;
11 import akka.osgi.BundleDelegatingClassLoader;
12 import com.typesafe.config.ConfigFactory;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.cluster.ActorSystemProvider;
15 import org.opendaylight.controller.cluster.ActorSystemProviderListener;
16 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
17 import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.util.ListenerRegistry;
20 import org.osgi.framework.BundleContext;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.duration.Duration;
25 public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable {
26 private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data";
27 private static final String CONFIGURATION_NAME = "odl-cluster-data";
28 static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class);
30 private ActorSystem actorSystem;
31 private final BundleDelegatingClassLoader classLoader;
32 private final ListenerRegistry<ActorSystemProviderListener> listeners = new ListenerRegistry<>();
34 public ActorSystemProviderImpl(BundleContext bundleContext) {
35 LOG.info("Creating new ActorSystem");
37 classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(),
38 Thread.currentThread().getContextClassLoader());
43 private void createActorSystem() {
44 AkkaConfigurationReader configurationReader = new FileAkkaConfigurationReader();
45 actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME,
46 ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME), classLoader);
50 public ActorSystem getActorSystem() {
55 public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
56 ActorSystemProviderListener listener) {
57 return listeners.register(listener);
62 LOG.info("Shutting down ActorSystem");
64 actorSystem.shutdown();
66 actorSystem.awaitTermination(Duration.create(10, TimeUnit.SECONDS));
67 } catch (Exception e) {
68 LOG.warn("Error awaiting actor termination", e);