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.cluster.akka.impl;
10 import akka.actor.ActorSystem;
11 import akka.actor.Props;
12 import com.typesafe.config.Config;
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.QuarantinedMonitorActor;
17 import org.opendaylight.controller.cluster.datastore.TerminationMonitor;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.util.ListenerRegistry;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import scala.concurrent.Await;
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 Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class);
29 private final ActorSystem actorSystem;
30 private final ListenerRegistry<ActorSystemProviderListener> listeners = new ListenerRegistry<>();
32 public ActorSystemProviderImpl(
33 final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) {
34 LOG.info("Creating new ActorSystem");
36 actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader);
38 actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
39 actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS);
43 public ActorSystem getActorSystem() {
48 public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
49 final ActorSystemProviderListener listener) {
50 return listeners.register(listener);
54 @SuppressWarnings("checkstyle:IllegalCatch")
56 LOG.info("Shutting down ActorSystem");
59 Await.result(actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
60 } catch (final Exception e) {
61 LOG.warn("Error awaiting actor termination", e);