Class CentralDogmaBeanFactory
java.lang.Object
com.linecorp.centraldogma.client.updater.CentralDogmaBeanFactory
Creates a new bean instance that mirrors its properties from Central Dogma.
In the following example, mirroredFoo.getA()
and getB()
will return the latest known
values retrieved from /myProject/myRepo/foo.json
along with the latest revision in Central Dogma.
If the latest values are not available yet, the revision will be set to null.
> CentralDogma dogma = ...;
> // Optionally, waits for the initial endpoints in order to fetch the first value without additional delay.
> dogma.whenEndpointReady().get(10, TimeUnit.SECONDS);
> CentralDogmaBeanFactory factory = new CentralDogmaBeanFactory(dogma, new ObjectMapper());
> Foo mirroredFoo = factory.get(new Foo(), Foo.class);
>
> @CentralDogmaBean(project = "myProject",
> repository = "myRepo",
> path = "/foo.json")
> public class Foo {
> private int a;
> private String b;
>
> public int getA() { return a; }
> public void setA(int a) { this.a = a; }
> public String getB() { return b; }
> public void setB(String b) { this.b = b; }
> public Revision getRevision() { return null; }
> }
In the following example, callback will be called when a property is updated with a new value:
CentralDogmaBeanFactory factory = new CentralDogmaBeanFactory(dogma, new ObjectMapper());
Consumer<Foo> fooUpdatedListener = (Foo f) -> {
System.out.println("foo has updated to: " + f);
};
Foo mirroredFoo = factory.get(new Foo(), Foo.class, fooUpdatedListener);
-
Constructor Summary
ConstructorDescriptionCentralDogmaBeanFactory
(CentralDogma dogma, ObjectMapper objectMapper) Creates a new factory instance. -
Method Summary
Modifier and TypeMethodDescription<T> T
Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.<T> T
Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.<T> T
get
(T defaultValue, Class<T> beanType, CentralDogmaBeanConfig overrides) Returns a newly-created bean instance with some or all of its settings overridden.<T> T
get
(T defaultValue, Class<T> beanType, CentralDogmaBeanConfig overrides, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) Returns a newly-created bean instance with some or all of its settings overridden.<T> T
Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.<T> T
get
(T defaultValue, Class<T> beanType, Consumer<T> changeListener, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.<T> T
get
(T defaultValue, Class<T> beanType, Consumer<T> changeListener, CentralDogmaBeanConfig overrides) Returns a newly-created bean instance with some or all of its settings overridden.<T> T
get
(T defaultValue, Class<T> beanType, Consumer<T> changeListener, CentralDogmaBeanConfig overrides, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) Returns a newly-created bean instance with some or all of its settings overridden.
-
Constructor Details
-
CentralDogmaBeanFactory
Creates a new factory instance.
-
-
Method Details
-
get
Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
-
get
Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
changeListener
- theConsumer
ofbeanType
, invoked whenbean
is updated. Will consume the new value of the bean.- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
-
get
public <T> T get(T defaultValue, Class<T> beanType, Consumer<T> changeListener, CentralDogmaBeanConfig overrides) Returns a newly-created bean instance with some or all of its settings overridden.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
changeListener
- theConsumer
ofbeanType
, invoked whenbean
is updated. Will consume the new value of the bean.overrides
- theCentralDogmaBeanConfig
whose properties will override the settings specified by theCentralDogmaBean
annotation- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
-
get
public <T> T get(T defaultValue, Class<T> beanType, Consumer<T> changeListener, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) throws TimeoutException, InterruptedException Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
changeListener
- theConsumer
ofbeanType
, invoked whenbean
is updated. Will consume the new value of the bean.initialValueTimeout
- when a value larger than zero given to this argument, this method tries to wait for the initial value to be fetched until the timeoutinitialValueTimeoutUnit
- theTimeUnit
ofinitialValueTimeout
- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
- Throws:
TimeoutException
- wheninitialValueTimeoutMillis
is positive and it failed to obtain the initial value within configured timeoutInterruptedException
- wheninitialValueTimeoutMillis
is positive and it got interrupted while waiting for the initial value
-
get
Returns a newly-created bean instance with some or all of its settings overridden.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
overrides
- theCentralDogmaBeanConfig
whose properties will override the settings specified by theCentralDogmaBean
annotation- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
-
get
public <T> T get(T defaultValue, Class<T> beanType, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) throws TimeoutException, InterruptedException Returns a newly-created bean instance with the settings specified byCentralDogmaBean
annotation.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
initialValueTimeout
- when a value larger than zero given to this argument, this method tries to wait for the initial value to be fetched until the timeoutinitialValueTimeoutUnit
- theTimeUnit
ofinitialValueTimeout
- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
- Throws:
TimeoutException
- wheninitialValueTimeoutMillis
is positive and it failed to obtain the initial value within configured timeoutInterruptedException
- wheninitialValueTimeoutMillis
is positive and it got interrupted while waiting for the initial value
-
get
public <T> T get(T defaultValue, Class<T> beanType, CentralDogmaBeanConfig overrides, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) throws TimeoutException, InterruptedException Returns a newly-created bean instance with some or all of its settings overridden.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
overrides
- theCentralDogmaBeanConfig
whose properties will override the settings specified by theCentralDogmaBean
annotationinitialValueTimeout
- when a value larger than zero given to this argument, this method tries to wait for the initial value to be fetched until the timeoutinitialValueTimeoutUnit
- theTimeUnit
ofinitialValueTimeout
- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
- Throws:
TimeoutException
- wheninitialValueTimeoutMillis
is positive and it failed to obtain the initial value within configured timeoutInterruptedException
- wheninitialValueTimeoutMillis
is positive and it got interrupted while waiting for the initial value
-
get
public <T> T get(T defaultValue, Class<T> beanType, Consumer<T> changeListener, CentralDogmaBeanConfig overrides, long initialValueTimeout, TimeUnit initialValueTimeoutUnit) throws TimeoutException, InterruptedException Returns a newly-created bean instance with some or all of its settings overridden.- Parameters:
defaultValue
- a Java bean annotated withCentralDogmaBean
. The default value is used before initialization.beanType
- the type ofbean
changeListener
- theConsumer
ofbeanType
, invoked whenbean
is updated. Will consume the new value of the bean.overrides
- theCentralDogmaBeanConfig
whose properties will override the settings specified by theCentralDogmaBean
annotationinitialValueTimeout
- when a value larger than zero given to this argument, this method tries to wait for the initial value to be fetched until the timeoutinitialValueTimeoutUnit
- theTimeUnit
ofinitialValueTimeout
- Returns:
- a new Java bean whose getters return the latest known values mirrored from Central Dogma
- Throws:
TimeoutException
- wheninitialValueTimeoutMillis
is positive and it failed to obtain the initial value within configured timeoutInterruptedException
- wheninitialValueTimeoutMillis
is positive and it got interrupted while waiting for the initial value
-