ru.fix:dynamic-property-jackson

https://github.com/ru-fix/dynamic-property

License

License

Categories

Categories

Jackson Data JSON
GroupId

GroupId

ru.fix
ArtifactId

ArtifactId

dynamic-property-jackson
Last Version

Last Version

2.0.8
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

ru.fix:dynamic-property-jackson
https://github.com/ru-fix/dynamic-property
Project URL

Project URL

https://github.com/ru-fix/dynamic-property
Source Code Management

Source Code Management

https://github.com/ru-fix/dynamic-property

Download dynamic-property-jackson

Dependencies

compile (1)

Group / Artifact Type Version
ru.fix : dynamic-property-api jar 2.0.8

runtime (4)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar 2.9.9
com.fasterxml.jackson.core : jackson-databind jar 2.9.9
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar 2.9.9
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.9.9

Project Modules

There are no modules declared in this project.

dynamic-property

Maven Central

Provides easy way to change application configuration at runtime.

Inject properties by id

class MyService{
    
    @PropertyId("my.service.rate")
    lateinit var rate: DynamicProperty<Integer>
    
    fun myMethod(){
        val rate = rate.get()
        //use current value of rate from dynamic property
        calculate(rate)
    }
}
class MyService {
    
    @PropertyId("my.service.setting")
    lateinit var setting: PropertySubscription<Setting>

    @PostConstruct
    fun postConstructInitialization() {
        setting.setAndCallListener{oldValue, newValue ->
            updateState(newValue)
        }       
    }
    fun updateState(setting: Setting) {}
    fun doWork() {}
}

Provide default values for injected properties

class MyService{
    
    @PropertyId("my.service.rate")
    var rate = DynamicProperty.of(12)
    
    @PropertyId("my.service.setting")
    var setting = PropertySubscription.of(Setting(7, 15))
}

Inject properties explicitly through constructor

class MyService(setting: DynamicProperty<Setting>) {
    val subscription = setting.createSubscription().setAndCallListener { oldSetting, newSetting ->
        // initialize service
        // or update state on settings change
        updateState(newSetting)
    }

    fun updateState(setting: Setting) {}
    fun doWork() {}
}
class MyService(val setting: DynamicProperty<Setting>) {
    fun doWork() {
        val currentSetting = setting.get()
    }
}

Support various property sources.

  • properties files
  • ZooKeeper

Compose properties

You can build one property based on another:

val stringProperty: DynamicProperty<String>

val intProperty = stringProperty.map { str -> str.toInt() }

val service = ServiceThatRequiresIntProperty(intProperty)

Combine properties

You can build new property based on several others:

val first = AtomicProperty("hello")
val second = AtomicProperty("123")

val combined = CombinedProperty(listOf(first, second)) { first.get() + second.get() }
//combined == "hello123"
        
first.set("hi")
//combined == "hi123"

second.set("42")
//combined == "hi42"

Mock property in tests

//constant property that never changes
val constantProperty = DynamicProperty.of(122)
val myService = MyService(constantProperty)
myService.doWork()

//property that could change during test
val atomicProperty = AtomicProperty(122)
val myService = MyService(atomicProperty)
atomicProperty.set(512)
myService.doWork()

Polled values

DynamicPropertyPoller regularly invoke user defined supplier function that returns current value of DynamicProperty that backed by custom user defined data source.

DynamicPropertyPoller poller = DynamicPropertyPoller(
        NamedExecutors.newSingleThreadScheduler(
            "polling",
            profiler
        ),
        DynamicProperty.of(Schedule.withRate(1000L)));


class UserClassWithDynamicPropertiesBackedByCustomDataSource {
  DynamicProperty<String> myProperty;

  public UserClass(DynamicPropertyPoller poller){
     myProperty = poller.createProperty(()-> myDaoService.loadValueFromDatabase(...));
     myProperty.addAndCallListener( value -> {
         //init or update state based on property value
         ...
     });
  }
}
ru.fix

FIX

FIX Company

Versions

Version
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.1.11
1.1.10
1.1.9-jdk8
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.14