Skip to content

Commit

Permalink
Change error handler to be an executor. Keep throw on close logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW authored and martinfurmanski committed Sep 10, 2018
1 parent 2cde460 commit c560a45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
Expand Up @@ -60,29 +60,9 @@ public void close()
{ {
if ( channel != null ) if ( channel != null )
{ {
try errorHandler.execute( () -> channel.close() );
{
channel.close();
}
catch ( Throwable t )
{
errorHandler.add( t );
}
}
if ( !chunks.isEmpty() )
{
for ( ByteBuf byteBuf : chunks )
{
try
{
ReferenceCountUtil.release( byteBuf );
}
catch ( Throwable t )
{
errorHandler.add( t );
}
}
} }
chunks.forEach( byteBuf -> errorHandler.execute( () -> ReferenceCountUtil.release( byteBuf ) ) );
} }
} }


Expand Down
Expand Up @@ -44,14 +44,7 @@ public static void runAll( String description, ThrowingRunnable... actions ) thr
{ {
for ( ThrowingRunnable action : actions ) for ( ThrowingRunnable action : actions )
{ {
try errorHandler.execute( action );
{
action.run();
}
catch ( Throwable e )
{
errorHandler.add( e );
}
} }
} }
} }
Expand All @@ -61,6 +54,18 @@ public ErrorHandler( String message )
this.message = message; this.message = message;
} }


public void execute( ThrowingRunnable throwingRunnable )
{
try
{
throwingRunnable.run();
}
catch ( Throwable e )
{
throwables.add( e );
}
}

public void add( Throwable throwable ) public void add( Throwable throwable )
{ {
throwables.add( throwable ); throwables.add( throwable );
Expand Down
Expand Up @@ -264,18 +264,11 @@ public static void shutdownCoreMembers( Collection<CoreClusterMember> members )
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
private static void shutdownMembers( Collection<? extends ClusterMember> clusterMembers, ErrorHandler errorHandler ) private static void shutdownMembers( Collection<? extends ClusterMember> clusterMembers, ErrorHandler errorHandler )
{ {
try errorHandler.execute( () -> combine( invokeAll( "cluster-shutdown", clusterMembers, cm ->
{ {
combine( invokeAll( "cluster-shutdown", clusterMembers, cm -> cm.shutdown();
{ return null;
cm.shutdown(); } ) ).get() );
return null;
} ) ).get();
}
catch ( Exception e )
{
errorHandler.add( e );
}
} }


private static <X extends GraphDatabaseAPI, T extends ClusterMember<X>, R> List<Future<R>> invokeAll( String threadName, Collection<T> members, private static <X extends GraphDatabaseAPI, T extends ClusterMember<X>, R> List<Future<R>> invokeAll( String threadName, Collection<T> members,
Expand Down

0 comments on commit c560a45

Please sign in to comment.