Skip to content

Commit

Permalink
Fix minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Apr 23, 2018
1 parent e5a7539 commit 2f396ca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
Expand Up @@ -48,7 +48,7 @@ public void disable()


private void doOperation( ThrowingConsumer<Suspendable,Throwable> operation, String description ) private void doOperation( ThrowingConsumer<Suspendable,Throwable> operation, String description )
{ {
ErrorHandler.certainOperations( description, suspendables.stream() ErrorHandler.runAll( description, suspendables.stream()
.map( (Function<Suspendable,ErrorHandler.ThrowingRunnable>) suspendable -> () -> operation.accept( suspendable ) ) .map( (Function<Suspendable,ErrorHandler.ThrowingRunnable>) suspendable -> () -> operation.accept( suspendable ) )
.toArray( ErrorHandler.ThrowingRunnable[]::new ) ); .toArray( ErrorHandler.ThrowingRunnable[]::new ) );
} }
Expand Down
Expand Up @@ -22,15 +22,20 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


import org.neo4j.function.ThrowingAction;


public class ErrorHandler implements AutoCloseable public class ErrorHandler implements AutoCloseable
{ {
private final List<Throwable> throwables = new ArrayList<>(); private final List<Throwable> throwables = new ArrayList<>();
private final String message; private final String message;


public static void certainOperations( String description, ThrowingRunnable... actions ) throws RuntimeException /**
* Ensures each action is executed. Any throwables will be saved and thrown after all actions have been executed. The first caught throwable will be cause
* and any other will be added as suppressed.
*
* @param description The exception message if any are thrown.
* @param actions Throwing runnables to execute.
* @throws RuntimeException thrown if any action throws after all have been executed.
*/
public static void runAll( String description, ThrowingRunnable... actions ) throws RuntimeException
{ {
try ( ErrorHandler errorHandler = new ErrorHandler( description ) ) try ( ErrorHandler errorHandler = new ErrorHandler( description ) )
{ {
Expand Down
Expand Up @@ -93,7 +93,8 @@ protected void start0()


workerGroup = new NioEventLoopGroup( 0, threadFactory ); workerGroup = new NioEventLoopGroup( 0, threadFactory );


ServerBootstrap bootstrap = new ServerBootstrap().group( workerGroup ) ServerBootstrap bootstrap = new ServerBootstrap()
.group( workerGroup )
.channel( NioServerSocketChannel.class ) .channel( NioServerSocketChannel.class )
.option( ChannelOption.SO_REUSEADDR, Boolean.TRUE ) .option( ChannelOption.SO_REUSEADDR, Boolean.TRUE )
.localAddress( listenAddress.socketAddress() ) .localAddress( listenAddress.socketAddress() )
Expand Down
Expand Up @@ -38,7 +38,7 @@ public void shouldExecuteAllFailingOperations()
AtomicBoolean bool = new AtomicBoolean( false ); AtomicBoolean bool = new AtomicBoolean( false );
try try
{ {
ErrorHandler.certainOperations( "test", Assert::fail, () -> ErrorHandler.runAll( "test", Assert::fail, () ->
{ {
bool.set( true ); bool.set( true );
throw new IllegalStateException( FAILMESSAGE ); throw new IllegalStateException( FAILMESSAGE );
Expand Down
Expand Up @@ -57,9 +57,7 @@ void set( Lifecycle lifecycle ) throws Throwable


enum SuspendedState enum SuspendedState
{ {
Untouched( suspendable -> Untouched( suspendable -> {} ),
{
} ),
Enabled( Suspendable::enable ), Enabled( Suspendable::enable ),
Disabled( Suspendable::disable ); Disabled( Suspendable::disable );


Expand Down

0 comments on commit 2f396ca

Please sign in to comment.