Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

akka java programmatic override configuration

The few topics I can find about this are for Scala, rather than Java, and none address remote actors.

I have a base configuration file (SERVER_CONFIG_FILE):

Include "akka-common"

TheSystem {
  akka {
    actor {
      provider = "akka.remote.RemoteActorRefProvider"
        deployment { 
          /OtherSupervisor {
            remote = "akka://[email protected]:8553"
          }
        }
      }
    remote {
      transport = "akka.remote.netty.NettyRemoteTransport"
      netty {
        hostname = "127.0.0.1"
        port = 8552
      }
    }
  }
}

I want to load it in my program, and then override several settings, but I can't figure out the code. Something like:

private final Config serverConfig = ConfigFactory.load(SERVER_CONFIG_FILE).withValue...?

I need to override the value of "akka://[email protected]:8553", and also the hostname. I think the hostname can be addressed by "ComparisonSystem.akka.remote.netty.hostname", but confirmation would help.

I really do not know how to address the first value, nor what java calls to use to make it come together. I can learn from an example I can see, but not from the Scala I find, and nothing addresses having that Actor Name in the path.

Thanks in advance.

like image 948
bret Avatar asked Feb 28 '26 19:02

bret


1 Answers

You can do that like this, note that you use the Config instance with overrides and let it fallback to your default configuration rather than the other way around:

Config overrides = ConfigFactory.parseString("some.setting=a-value");
Config actualConfig = overrides.withFallback(ConfigFactory.load());

Or if you do not like building strings you could use properties to specify your overrides:

Properties properties = new Properties();
properties.setProperty("some.setting", "a-value");
Config overrides = ConfigFactory.parseProperties(properties);
Config actualConfig = overrides.withFallback(ConfigFactory.load());
like image 164
johanandren Avatar answered Mar 03 '26 10:03

johanandren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!