Skip to content
Eugene Strokin edited this page Apr 30, 2021 · 2 revisions

What is Dynocon?

Dynocon is a library for dynamic configuration. It supports multiple sources of the configuration properties. Properties sources could be combined into a cascading hierarchy and be polled periodically. The changes provided to the code automatically, without restarting the application.

Configuration properties read is lock-free. All the polling and value updates are happening in separate threads.

Quick start

Add dependency into your project:

Maven:

<dependency>
	<groupId>com.comcast</groupId>
	<artifactId>dynocon-core</artifactId>
	<version>LATEST</version>
</dependency>

Create a configuration file:

Add a service.json file into /opt folder. The content of the file is JSON with properties and values:

{
  "myPropertyName": "value1",
  "complexProperty": {
    "prop1": "Hello world",
    "prop2": 777
  }
}

Add a configuration property into your code:

public static final Property<String> MY_PROPERTY = new Property<>("myPropertyName", String.class);

... SNIP ...

Assert.assertEquals("value1", MY_PROPERTY.get());

Default value for a property:

public static final Property<String> MY_OTHER_PROPERTY = new Property<>("myOtherPropertyName", String.class).ifNull("SOME DEFAULT VALUE");

... SNIP ...

Assert.assertEquals("SOME DEFAULT VALUE", MY_OTHER_PROPERTY.get());

Create a POJO for your complex property:

public class MyComplexConfig {
  private String prop1;
  private Integer prop2;

... GETTERS AND SETTERS ...
}

... SNIP ...

public static final Property<MyComplexConfig> MY_COMPLEX_PROPERTY = new Property<>("complexProperty", MyComplexConfig.class);

... SNIP ...

Assert.assertEquals("Hello world", MY_COMPLEX_PROPERTY.get().getProp1());
Assert.assertEquals(777, MY_COMPLEX_PROPERTY.get().getProp2());

Update values of a property:

Open service.json file and update the value of any JSON field. You should see the change reflected in your code in less than 30 seconds.

Next: