Remove CSS modules
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / akka / impl / ActorSystemProviderImpl.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. 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.cluster.akka.impl;
9
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;
24
25 public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable {
26     private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data";
27     static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class);
28     private final ActorSystem actorSystem;
29     private final ListenerRegistry<ActorSystemProviderListener> listeners = new ListenerRegistry<>();
30
31     public ActorSystemProviderImpl(
32             final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) {
33         LOG.info("Creating new ActorSystem");
34
35         actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader);
36
37         actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
38         actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS);
39     }
40
41     @Override
42     public ActorSystem getActorSystem() {
43         return actorSystem;
44     }
45
46     @Override
47     public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
48             final ActorSystemProviderListener listener) {
49         return listeners.register(listener);
50     }
51
52     @Override
53     @SuppressWarnings("checkstyle:IllegalCatch")
54     public void close() {
55         LOG.info("Shutting down ActorSystem");
56
57         try {
58             Await.result(actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
59         } catch (final Exception e) {
60             LOG.warn("Error awaiting actor termination", e);
61         }
62     }
63 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.