Skip to content

Commit

Permalink
TransactionTemplate failed callback is now invoked when all retires h…
Browse files Browse the repository at this point in the history
…ave failed
  • Loading branch information
klaren committed Oct 18, 2017
1 parent 7ecc7cd commit 6598fb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
20 changes: 6 additions & 14 deletions community/common/src/main/java/org/neo4j/function/Predicates.java
Expand Up @@ -41,33 +41,25 @@
*/ */
public class Predicates public class Predicates
{ {
private static final Predicate TRUE = item -> true;

private static final Predicate FALSE = item -> false;

private static final Predicate NOT_NULL = Objects::nonNull;
private static final int DEFAULT_POLL_INTERVAL = 20; private static final int DEFAULT_POLL_INTERVAL = 20;


private Predicates() private Predicates()
{ {
} }


@SuppressWarnings( "unchecked" )
public static <T> Predicate<T> alwaysTrue() public static <T> Predicate<T> alwaysTrue()
{ {
return TRUE; return x -> true;
} }


@SuppressWarnings( "unchecked" )
public static <T> Predicate<T> alwaysFalse() public static <T> Predicate<T> alwaysFalse()
{ {
return FALSE; return x -> false;
} }


@SuppressWarnings( "unchecked" )
public static <T> Predicate<T> notNull() public static <T> Predicate<T> notNull()
{ {
return NOT_NULL; return Objects::nonNull;
} }


@SafeVarargs @SafeVarargs
Expand Down Expand Up @@ -112,18 +104,18 @@ public static <T> Predicate<T> any( final Iterable<Predicate<T>> predicates )
}; };
} }


public static <T> Predicate<T> instanceOf( @Nonnull final Class clazz ) public static <T> Predicate<T> instanceOf( @Nonnull final Class<?> clazz )
{ {
return item -> item != null && clazz.isInstance( item ); return item -> item != null && clazz.isInstance( item );
} }


public static <T> Predicate<T> instanceOfAny( final Class... classes ) public static <T> Predicate<T> instanceOfAny( final Class<?>... classes )
{ {
return item -> return item ->
{ {
if ( item != null ) if ( item != null )
{ {
for ( Class clazz : classes ) for ( Class<?> clazz : classes )
{ {
if ( clazz.isInstance( item ) ) if ( clazz.isInstance( item ) )
{ {
Expand Down
Expand Up @@ -132,8 +132,7 @@ public void execute( final Consumer<Transaction> txConsumer )
} ); } );
} }


public <T> T execute( Function<Transaction, T> txFunction ) public <T> T execute( Function<Transaction, T> txFunction ) throws TransactionFailureException
throws TransactionFailureException
{ {
Throwable txEx = null; Throwable txEx = null;
for ( int i = 0; i < retries; i++ ) for ( int i = 0; i < retries; i++ )
Expand Down Expand Up @@ -163,28 +162,16 @@ public <T> T execute( Function<Transaction, T> txFunction )
} }
catch ( InterruptedException e ) catch ( InterruptedException e )
{ {
throw new TransactionFailureException( "Interrupted", e ); TransactionFailureException interrupted = new TransactionFailureException( "Interrupted", e );
monitor.failed( interrupted );
throw interrupted;
} }


monitor.retrying(); monitor.retrying();
} }
} }


if ( txEx instanceof TransactionFailureException ) monitor.failed( txEx );
{ throw new TransactionFailureException( "Failed", txEx );
throw (TransactionFailureException) txEx;
}
else if ( txEx instanceof Error )
{
throw (Error) txEx;
}
else if ( txEx instanceof RuntimeException )
{
throw (RuntimeException) txEx;
}
else
{
throw new TransactionFailureException( "Failed", txEx );
}
} }
} }

0 comments on commit 6598fb2

Please sign in to comment.