protected void initRefreshCycle ( ) { // Check if should check for updates Integer refresh = PropertyUtil . getPropertyAsInteger ( PropertyUtil . HAWKULAR_APM_CONFIG_REFRESH ) ; if ( log . isLoggable ( Level . FINER ) ) { log . finer ( "Configuration refresh cycle (in seconds) = " + refresh ) ; } if ( refresh != null ) { Executors . newSingleThreadScheduledExecutor ( new ThreadFactory ( ) { public Thread newThread ( Runnable r ) { Thread t = Executors . defaultThreadFactory ( ) . newThread ( r ) ; t . setDaemon ( true ) ; return t ; } } ) . scheduleAtFixedRate ( new Runnable ( ) { @ Override public void run ( ) { try { Map < String , TransactionConfig > changed = configurationService . getTransactions ( null , configLastUpdated ) ; for ( Map . Entry < String , TransactionConfig > stringBusinessTxnConfigEntry : changed . entrySet ( ) ) { TransactionConfig btc = stringBusinessTxnConfigEntry . getValue ( ) ; if ( btc . isDeleted ( ) ) { if ( log . isLoggable ( Level . FINER ) ) { log . finer ( "Removing config for btxn '" + stringBusinessTxnConfigEntry . getKey ( ) + "' = " + btc ) ; } filterManager . remove ( stringBusinessTxnConfigEntry . getKey ( ) ) ; processorManager . remove ( stringBusinessTxnConfigEntry . getKey ( ) ) ; } else { if ( log . isLoggable ( Level . FINER ) ) { log . finer ( "Changed config for btxn '" + stringBusinessTxnConfigEntry . getKey ( ) + "' = " + btc ) ; } filterManager . init ( stringBusinessTxnConfigEntry . getKey ( ) , btc ) ; processorManager . init ( stringBusinessTxnConfigEntry . getKey ( ) , btc ) ; } if ( btc . getLastUpdated ( ) > configLastUpdated ) { configLastUpdated = btc . getLastUpdated ( ) ; } } } catch ( Exception e ) { log . log ( Level . SEVERE , "Failed to update transaction configuration" , e ) ; } } } , refresh . intValue ( ) , refresh . intValue ( ) , TimeUnit . SECONDS ) ; } }
This method initialises the refresh cycle .