X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fakka%2Fimpl%2FActorSystemProviderImpl.java;h=4868d04f7d8df9188b4b324d5cd9176d132f9e1e;hb=1d5ca4009be6c61d7b61989799037ad8f1ab7a75;hp=746ccf5524b9f0fa686654f3abb497edac7de6ad;hpb=35235f427f3a056f85fe83ddd1133e67540328f7;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/impl/ActorSystemProviderImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/impl/ActorSystemProviderImpl.java index 746ccf5524..4868d04f7d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/impl/ActorSystemProviderImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/impl/ActorSystemProviderImpl.java @@ -9,8 +9,12 @@ package org.opendaylight.controller.cluster.akka.impl; import akka.actor.ActorSystem; import akka.actor.Props; +import akka.actor.Terminated; +import akka.dispatch.OnComplete; import com.typesafe.config.Config; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.ActorSystemProvider; import org.opendaylight.controller.cluster.ActorSystemProviderListener; import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor; @@ -20,21 +24,22 @@ import org.opendaylight.yangtools.util.ListenerRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Await; +import scala.concurrent.ExecutionContext; +import scala.concurrent.Future; import scala.concurrent.duration.FiniteDuration; public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable { private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data"; private static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class); - private final ActorSystem actorSystem; - private final ListenerRegistry listeners = new ListenerRegistry<>(); + private final @NonNull ActorSystem actorSystem; + private final ListenerRegistry listeners = ListenerRegistry.create(); public ActorSystemProviderImpl( final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) { LOG.info("Creating new ActorSystem"); actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader); - actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS); actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS); } @@ -50,15 +55,29 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab return listeners.register(listener); } - @Override - @SuppressWarnings("checkstyle:IllegalCatch") - public void close() { + public Future asyncClose() { LOG.info("Shutting down ActorSystem"); - try { - Await.result(actorSystem.terminate(), FiniteDuration.create(10, TimeUnit.SECONDS)); - } catch (final Exception e) { - LOG.warn("Error awaiting actor termination", e); - } + final Future ret = actorSystem.terminate(); + ret.onComplete(new OnComplete() { + @Override + public void onComplete(final Throwable failure, final Terminated success) throws Throwable { + if (failure != null) { + LOG.warn("ActorSystem failed to shut down", failure); + } else { + LOG.info("ActorSystem shut down"); + } + } + }, ExecutionContext.global()); + return ret; + } + + public void close(final FiniteDuration wait) throws TimeoutException, InterruptedException { + Await.result(asyncClose(), wait); + } + + @Override + public void close() throws TimeoutException, InterruptedException { + close(FiniteDuration.create(10, TimeUnit.SECONDS)); } }