Add option to disable default ActorSystemQuarantinedEvent handling
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / akka / osgi / impl / QuarantinedMonitorActorPropsFactory.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.osgi.impl;
9
10 import akka.actor.Props;
11 import com.typesafe.config.Config;
12 import com.typesafe.config.ConfigException;
13 import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor;
14 import org.osgi.framework.BundleContext;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public final class QuarantinedMonitorActorPropsFactory {
19     private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActorPropsFactory.class);
20
21     private static final String DEFAULT_HANDLING_DISABLED =
22         "akka.disable-default-actor-system-quarantined-event-handling";
23
24     private QuarantinedMonitorActorPropsFactory() {
25
26     }
27
28     public static Props createProps(final BundleContext bundleContext, final Config akkaConfig) {
29         try {
30             if (akkaConfig.getBoolean(DEFAULT_HANDLING_DISABLED)) {
31                 LOG.info("{} was set, default handling is disabled", DEFAULT_HANDLING_DISABLED);
32                 return QuarantinedMonitorActor.props(() -> { });
33             }
34         } catch (ConfigException configEx) {
35             LOG.info("Akka config doesn't contain property {}. Therefore default handling will be used",
36                 DEFAULT_HANDLING_DISABLED);
37         }
38         return QuarantinedMonitorActor.props(() -> {
39             // restart the entire karaf container
40             LOG.warn("Restarting karaf container");
41             System.setProperty("karaf.restart.jvm", "true");
42             System.setProperty("karaf.restart", "true");
43             bundleContext.getBundle(0).stop();
44         });
45     }
46 }