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 java.util.concurrent.TimeoutException;
15 import org.opendaylight.controller.cluster.ActorSystemProvider;
16 import org.opendaylight.controller.cluster.ActorSystemProviderListener;
17 import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor;
18 import org.opendaylight.controller.cluster.datastore.TerminationMonitor;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.util.ListenerRegistry;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.Await;
24 import scala.concurrent.duration.FiniteDuration;
26 public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable {
27 private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data";
28 private static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class);
30 private final ActorSystem actorSystem;
31 private final ListenerRegistry<ActorSystemProviderListener> listeners = ListenerRegistry.create();
33 public ActorSystemProviderImpl(
34 final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) {
35 LOG.info("Creating new ActorSystem");
37 actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader);
39 actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
40 actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS);
44 public ActorSystem getActorSystem() {
49 public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
50 final ActorSystemProviderListener listener) {
51 return listeners.register(listener);
55 public void close() throws TimeoutException, InterruptedException {
56 LOG.info("Shutting down ActorSystem");
57 Await.result(actorSystem.terminate(), FiniteDuration.create(10, TimeUnit.SECONDS));