Turn FileAkkaConfigurationReader into a component
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / FileAkkaConfigurationReader.java
1 /*
2  * Copyright (c) 2014 Cisco 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.common.actor;
9
10 import static com.google.common.base.Preconditions.checkState;
11
12 import com.typesafe.config.Config;
13 import com.typesafe.config.ConfigFactory;
14 import java.io.File;
15 import javax.inject.Singleton;
16 import org.kohsuke.MetaInfServices;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Component(immediate = true)
24 @MetaInfServices
25 @Singleton
26 public class FileAkkaConfigurationReader implements AkkaConfigurationReader {
27     private static final Logger LOG = LoggerFactory.getLogger(FileAkkaConfigurationReader.class);
28     private static final String CUSTOM_AKKA_CONF_PATH = "./configuration/initial/akka.conf";
29     private static final String FACTORY_AKKA_CONF_PATH = "./configuration/factory/akka.conf";
30
31     @Override
32     public Config read() {
33         File customConfigFile = new File(CUSTOM_AKKA_CONF_PATH);
34         checkState(customConfigFile.exists(), "%s is missing", customConfigFile);
35
36         File factoryConfigFile = new File(FACTORY_AKKA_CONF_PATH);
37         if (factoryConfigFile.exists()) {
38             return ConfigFactory.parseFile(customConfigFile).withFallback(ConfigFactory.parseFile(factoryConfigFile));
39         }
40
41         return ConfigFactory.parseFile(customConfigFile);
42     }
43
44     @Activate
45     void activate() {
46         LOG.info("File-based Akka configuration reader enabled");
47     }
48
49     @Deactivate
50     void deactivate() {
51         LOG.info("File-based Akka configuration reader disabled");
52     }
53 }

©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.