Class 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, the getProperties(String) method is used to retrieve properties and it will keep the internal data up-to-date in case refreshCycleSec has been set in constructor. You may want to set setListener(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, consider reload() or scheduleReload()
    • 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 use scheduleReload() 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 data
      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.
      void scheduleReload​(long refreshCycleSec)
      unlike scheduleReload() this method schedules the reload only in case the last reload time is older than given 'maturedTimeMs' such that getLastRefreshTime() + maturedTimeMs <= current time
      void setListener​(DbProperties.Listener listener)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DbProperties

        public DbProperties​(java.lang.String bindingSetId,
                            int refreshCycleSec)
                     throws BindingException
        create DbProperties instance, the properties are NOT initialized/loaded, consider reload() or scheduleReload()
        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 found
        java.lang.RuntimeException - in case name of DataSource could not be obtained
    • Method Detail

      • reload

        public boolean reload()
        triggers reload of properties, this is a *blocking* call, if you want to reload properties asynchronously use scheduleReload() 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 as scheduleReload(long) with 0 as parameter.
      • scheduleReload

        public void scheduleReload​(long refreshCycleSec)
        unlike scheduleReload() this method schedules the reload only in case the last reload time is older than given 'maturedTimeMs' such that getLastRefreshTime() + 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