private AtomicReference<CpuClock> setupCpuClockAtomicReference() { AtomicReference<CpuClock> cpuClock = new AtomicReference<>( CpuClock.NOT_AVAILABLE ); BiConsumer<Boolean,Boolean> cpuClockUpdater = ( before, after ) -> { if ( after ) { cpuClock.set( CpuClock.CPU_CLOCK ); } else { cpuClock.set( CpuClock.NOT_AVAILABLE ); } }; cpuClockUpdater.accept( null, config.get( GraphDatabaseSettings.track_query_cpu_time ) ); config.registerDynamicUpdateListener( GraphDatabaseSettings.track_query_cpu_time, cpuClockUpdater ); return cpuClock; }
private AtomicReference<HeapAllocation> setupHeapAllocationAtomicReference() { AtomicReference<HeapAllocation> heapAllocation = new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ); BiConsumer<Boolean,Boolean> heapAllocationUpdater = ( before, after ) -> { if ( after ) { heapAllocation.set( HeapAllocation.HEAP_ALLOCATION ); } else { heapAllocation.set( HeapAllocation.NOT_AVAILABLE ); } }; heapAllocationUpdater.accept( null, config.get( GraphDatabaseSettings.track_query_allocation ) ); config.registerDynamicUpdateListener( GraphDatabaseSettings.track_query_allocation, heapAllocationUpdater ); return heapAllocation; }
private AtomicLong getRotationThresholdAndRegisterForUpdates() { if ( rotationThreshold != null ) { return new AtomicLong( rotationThreshold ); } if ( readOnly ) { return new AtomicLong( Long.MAX_VALUE ); } if ( config == null ) { config = Config.defaults(); } AtomicLong configThreshold = new AtomicLong( config.get( logical_log_rotation_threshold ) ); config.registerDynamicUpdateListener( logical_log_rotation_threshold, ( prev, update ) -> configThreshold.set( update ) ); return configThreshold; }
public LogPruningImpl( FileSystemAbstraction fs, LogFiles logFiles, LogProvider logProvider, LogPruneStrategyFactory strategyFactory, Clock clock, Config config ) { this.fs = fs; this.logFiles = logFiles; this.msgLog = logProvider.getLog( getClass() ); this.strategyFactory = strategyFactory; this.clock = clock; this.pruneStrategy = strategyFactory.strategyFromConfigValue( fs, logFiles, clock, config.get( GraphDatabaseSettings.keep_logical_logs ) ); // Register listener for updates config.registerDynamicUpdateListener( GraphDatabaseSettings.keep_logical_logs, ( prev, update ) -> updateConfiguration( update ) ); }
@Test public void registeringUpdateListenerOnNonDynamicSettingMustThrow() { Config config = Config.builder().withConfigClasses( singletonList( mySettingsWithDefaults ) ).build(); expect.expect( IllegalArgumentException.class ); config.registerDynamicUpdateListener( MySettingsWithDefaults.hello, ( a, b ) -> fail( "never called" ) ); }
@Test public void updateDynamicShouldInformRegisteredListeners() { Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); AtomicInteger counter = new AtomicInteger( 0 ); config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( previous, update ) -> { counter.getAndIncrement(); assertTrue( previous ); assertFalse( update ); } ); config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "false", ORIGIN ); assertThat( counter.get(), is( 1 ) ); }
@Test public void updateDynamicShouldLogExceptionsFromUpdateListeners() { Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); IllegalStateException exception = new IllegalStateException( "Boo" ); config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( a, b ) -> { throw exception; } ); Log log = mock( Log.class ); config.setLogger( log ); String settingName = MyDynamicSettings.boolSetting.name(); config.updateDynamicSetting( settingName, "", ORIGIN ); verify( log ).error( "Failure when notifying listeners after dynamic setting change; " + "new setting might not have taken effect: Boo", exception ); }
config.registerDynamicUpdateListener( MyDynamicSettings.secretSetting, ( previous, update ) ->
private <T> void registerDynamicSettingUpdater( Setting<T> setting ) { config.registerDynamicUpdateListener( setting, ( a,b ) -> updateSettings() ); }
private AtomicReference<HeapAllocation> setupHeapAllocationAtomicReference() { AtomicReference<HeapAllocation> heapAllocation = new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ); BiConsumer<Boolean,Boolean> heapAllocationUpdater = ( before, after ) -> { if ( after ) { heapAllocation.set( HeapAllocation.HEAP_ALLOCATION ); } else { heapAllocation.set( HeapAllocation.NOT_AVAILABLE ); } }; heapAllocationUpdater.accept( null, config.get( GraphDatabaseSettings.track_query_allocation ) ); config.registerDynamicUpdateListener( GraphDatabaseSettings.track_query_allocation, heapAllocationUpdater ); return heapAllocation; }
private AtomicReference<CpuClock> setupCpuClockAtomicReference() { AtomicReference<CpuClock> cpuClock = new AtomicReference<>( CpuClock.NOT_AVAILABLE ); BiConsumer<Boolean,Boolean> cpuClockUpdater = ( before, after ) -> { if ( after ) { cpuClock.set( CpuClock.CPU_CLOCK ); } else { cpuClock.set( CpuClock.NOT_AVAILABLE ); } }; cpuClockUpdater.accept( null, config.get( GraphDatabaseSettings.track_query_cpu_time ) ); config.registerDynamicUpdateListener( GraphDatabaseSettings.track_query_cpu_time, cpuClockUpdater ); return cpuClock; }
private AtomicLong getRotationThresholdAndRegisterForUpdates() { if ( rotationThreshold != null ) { return new AtomicLong( rotationThreshold ); } if ( readOnly ) { return new AtomicLong( Long.MAX_VALUE ); } if ( config == null ) { config = Config.defaults(); } AtomicLong configThreshold = new AtomicLong( config.get( logical_log_rotation_threshold ) ); config.registerDynamicUpdateListener( logical_log_rotation_threshold, ( prev, update ) -> configThreshold.set( update ) ); return configThreshold; }
ConfigurableIOLimiter( Config config, ObjLongConsumer<Object> pauseNanos ) { this.pauseNanos = pauseNanos; Integer iops = config.get( GraphDatabaseSettings.check_point_iops_limit ); updateConfiguration( iops ); config.registerDynamicUpdateListener( GraphDatabaseSettings.check_point_iops_limit, ( prev, update ) -> updateConfiguration( update ) ); }
public LogPruningImpl( FileSystemAbstraction fs, LogFiles logFiles, LogProvider logProvider, LogPruneStrategyFactory strategyFactory, Clock clock, Config config ) { this.fs = fs; this.logFiles = logFiles; this.msgLog = logProvider.getLog( getClass() ); this.strategyFactory = strategyFactory; this.clock = clock; this.pruneStrategy = strategyFactory.strategyFromConfigValue( fs, logFiles, clock, config.get( GraphDatabaseSettings.keep_logical_logs ) ); // Register listener for updates config.registerDynamicUpdateListener( GraphDatabaseSettings.keep_logical_logs, ( prev, update ) -> updateConfiguration( update ) ); }