Class DbProperties
- java.lang.Object
-
- de.businesscode.bcdui.toolbox.config.DbProperties
-
public class DbProperties extends java.lang.Object
this class loads the configuration properties from database, this class is thread-safe and can also be used as a singleton, thegetProperties(String)
method is used to retrieve properties and it will keep the internal data up-to-date in caserefreshCycleSec
has been set in constructor. You may want to setsetListener(Listener)
to listen to updates. This class has no threads monitoring the age of data, so the reload does not happen fully on its own, rather the aging is checked on following methods:getProperties(String)
,reloadIfAged()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DbProperties.Listener
-
Constructor Summary
Constructors Constructor Description DbProperties(java.lang.String bindingSetId, int refreshCycleSec)
create DbProperties instance, the properties are NOT initialized/loaded, considerreload()
orscheduleReload()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getLastRefreshTime()
java.util.HashMap<java.lang.String,java.lang.Object>
getProperties(java.lang.String scopeId)
boolean
reload()
triggers reload of properties, this is a *blocking* call, if you want to reload properties asynchronously usescheduleReload()
method, however only one concurrent reload is processed, so that if multiple threads call this method simultaneously the first one initiates a reload while other calls are discarded and this method returns immediately with 'false'void
reloadIfAged()
this method has no effect in case no refreshCycle was set during construction, otherwise it schedules load in case of aged datavoid
scheduleReload()
triggers scheduled reload of properties and returns immediately, however, the load is performed only once in a time, even though this method is called from multiple threads simulatenously, while loading other calls to this methds are ignored.void
scheduleReload(long refreshCycleSec)
unlikescheduleReload()
this method schedules the reload only in case the last reload time is older than given 'maturedTimeMs' such thatgetLastRefreshTime()
+ maturedTimeMs <= current timevoid
setListener(DbProperties.Listener listener)
-
-
-
Constructor Detail
-
DbProperties
public DbProperties(java.lang.String bindingSetId, int refreshCycleSec) throws BindingException
create DbProperties instance, the properties are NOT initialized/loaded, considerreload()
orscheduleReload()
- Parameters:
bindingSetId
-refreshCycleSec
- to refresh the properties, may be 0 to disable auto-refresh cycle- Throws:
BindingException
- if binding-set could not be obtained or was not foundjava.lang.RuntimeException
- in case name of DataSource could not be obtained
-
-
Method Detail
-
setListener
public void setListener(DbProperties.Listener listener)
-
reload
public boolean reload()
triggers reload of properties, this is a *blocking* call, if you want to reload properties asynchronously usescheduleReload()
method, however only one concurrent reload is processed, so that if multiple threads call this method simultaneously the first one initiates a reload while other calls are discarded and this method returns immediately with 'false'- Returns:
- true if properties have been reloaded or false if another concurrent reload is in process, so this call has had no effect
-
scheduleReload
public void scheduleReload()
triggers scheduled reload of properties and returns immediately, however, the load is performed only once in a time, even though this method is called from multiple threads simulatenously, while loading other calls to this methds are ignored. calling this methods effectively is same asscheduleReload(long)
with 0 as parameter.
-
scheduleReload
public void scheduleReload(long refreshCycleSec)
unlikescheduleReload()
this method schedules the reload only in case the last reload time is older than given 'maturedTimeMs' such thatgetLastRefreshTime()
+ maturedTimeMs <= current time- Parameters:
refreshCycleSec
- the mature time offset or 0 to schedule immediately
-
getLastRefreshTime
public long getLastRefreshTime()
- Returns:
- the last refresh ms
-
getProperties
public java.util.HashMap<java.lang.String,java.lang.Object> getProperties(java.lang.String scopeId)
- Parameters:
scopeId
-- Returns:
- property-set for given scope, may be NULL if no such scope exists
-
reloadIfAged
public void reloadIfAged()
this method has no effect in case no refreshCycle was set during construction, otherwise it schedules load in case of aged data
-
-