private void replayBuffer() { Runnable command = pollRunnable(); while ( command != null ) { realExecutor.execute( command ); command = pollRunnable(); } }
@Override public void execute( @Nonnull Runnable command ) { // First do an unsynchronized check to see if a realExecutor is present if ( realExecutor != null ) { realExecutor.execute( command ); return; } // Now do a synchronized check to avoid race conditions synchronized ( this ) { if ( realExecutor != null ) { realExecutor.execute( command ); return; } else { queueRunnable( command ); } } } }
public void satisfyWith( Executor executor ) { synchronized ( this ) { if ( realExecutor != null ) { throw new RuntimeException( "real executor is already set. Cannot override" ); } realExecutor = executor; replayBuffer(); } }
Semaphore lock = new Semaphore( 1 ); BufferingExecutor later = new BufferingExecutor(); later.execute( counter::incrementAndGet ); later.execute( lock::release );
private LogProvider createFileSystemUserLogProvider( Config config, FormattedLogProvider.Builder builder ) { BufferingExecutor deferredExecutor = new BufferingExecutor(); dependencies.withDeferredExecutor( deferredExecutor, Group.LOG_ROTATION ); FileSystemAbstraction fs = new DefaultFileSystemAbstraction(); File destination = config.get( GraphDatabaseSettings.store_user_log_path ); Long rotationThreshold = config.get( GraphDatabaseSettings.store_user_log_rotation_threshold ); try { if ( rotationThreshold == 0L ) { userLogFileStream = createOrOpenAsOutputStream( fs, destination, true ); return builder.toOutputStream( userLogFileStream ); } return builder.toOutputStream( new RotatingFileOutputStreamSupplier( fs, destination, rotationThreshold, config.get( GraphDatabaseSettings.store_user_log_rotation_delay ).toMillis(), config.get( GraphDatabaseSettings.store_user_log_max_archives ), deferredExecutor ) ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
private LogProvider createFileSystemUserLogProvider( Config config, FormattedLogProvider.Builder builder ) { BufferingExecutor deferredExecutor = new BufferingExecutor(); dependencies.withDeferredExecutor( deferredExecutor, Group.LOG_ROTATION ); FileSystemAbstraction fs = new DefaultFileSystemAbstraction(); File destination = config.get( GraphDatabaseSettings.store_user_log_path ); Long rotationThreshold = config.get( GraphDatabaseSettings.store_user_log_rotation_threshold ); try { if ( rotationThreshold == 0L ) { userLogFileStream = createOrOpenAsOutputStream( fs, destination, true ); return builder.toOutputStream( userLogFileStream ); } return builder.toOutputStream( new RotatingFileOutputStreamSupplier( fs, destination, rotationThreshold, config.get( GraphDatabaseSettings.store_user_log_rotation_delay ).toMillis(), config.get( GraphDatabaseSettings.store_user_log_max_archives ), deferredExecutor ) ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
public void satisfyWith( Executor executor ) { synchronized ( this ) { if ( realExecutor != null ) { throw new RuntimeException( "real executor is already set. Cannot override" ); } realExecutor = executor; replayBuffer(); } }
private void replayBuffer() { Runnable command = pollRunnable(); while ( command != null ) { realExecutor.execute( command ); command = pollRunnable(); } }
@Override public void execute( @Nonnull Runnable command ) { // First do an unsynchronized check to see if a realExecutor is present if ( realExecutor != null ) { realExecutor.execute( command ); return; } // Now do a synchronized check to avoid race conditions synchronized ( this ) { if ( realExecutor != null ) { realExecutor.execute( command ); return; } else { queueRunnable( command ); } } } }