private static IndexEntryConflictException buildCauseChain( Set<IndexEntryConflictException> conflicts ) { IndexEntryConflictException chainedConflicts = null; for ( IndexEntryConflictException conflict : conflicts ) { chainedConflicts = Exceptions.chain( chainedConflicts, conflict ); } return chainedConflicts; }
private RuntimeException consumeAndChainException( T instance, Consumer<T> consumer, RuntimeException exception ) { try { consumer.accept( instance ); } catch ( RuntimeException e ) { exception = Exceptions.chain( exception, e ); } return exception; } }
private InterruptedException shutdownPool( ExecutorService pool, InterruptedException exception ) { if ( pool != null ) { pool.shutdown(); try { pool.awaitTermination( 30, TimeUnit.SECONDS ); } catch ( InterruptedException e ) { return Exceptions.chain( exception, e ); } } return exception; } }
private LifecycleException stopInstances( List<LifecycleInstance> instances ) { LifecycleException ex = null; for ( int i = instances.size() - 1; i >= 0; i-- ) { LifecycleInstance lifecycleInstance = instances.get( i ); try { lifecycleInstance.stop(); } catch ( LifecycleException e ) { ex = Exceptions.chain( ex, e ); } } return ex; }
/** * Closes the node,relationship,property and relationship type stores. */ @Override public void close() { RuntimeException ex = null; for ( StoreType type : STORE_TYPES ) { try { closeStore( type ); } catch ( RuntimeException t ) { ex = Exceptions.chain( ex, t ); } } if ( ex != null ) { throw ex; } }
/** * Method for calling a lambda function on many objects when it is expected that the function might * throw an exception. First exception will be thrown and subsequent will be suppressed. * This method guarantees that all subjects will be consumed, unless {@link OutOfMemoryError} or some other serious error happens. * * @param consumer lambda function to call on each object passed * @param subjects {@link Iterable} of objects to call the function on * @param <E> the type of exception anticipated, inferred from the lambda * @throws E if consumption fails with this exception */ public static <T, E extends Exception> void safeForAll( ThrowingConsumer<T,E> consumer, Iterable<T> subjects ) throws E { E exception = null; for ( T instance : subjects ) { try { consumer.accept( instance ); } catch ( Exception e ) { exception = Exceptions.chain( exception, (E) e ); } } if ( exception != null ) { throw exception; } }
private RuntimeException exitConstructor( Throwable throwable ) { try { close(); } catch ( IOException e ) { throwable = Exceptions.chain( new UncheckedIOException( e ), throwable ); } appendTreeInformation( throwable ); Exceptions.throwIfUnchecked( throwable ); return new RuntimeException( throwable ); }
@Override public void shutdown() { started = false; // First shut down the scheduler, so no new tasks are queued up in the pools. InterruptedException exception = shutDownScheduler(); // Then shut down the thread pools. This involves cancelling jobs which hasn't been cancelled already, // so we avoid having to wait the full maximum wait time on the executor service shut-downs. exception = Exceptions.chain( exception, pools.shutDownAll() ); // Finally, we shut the work-stealing executors down. for ( ExecutorService workStealingExecutor : workStealingExecutors.values() ) { exception = shutdownPool( workStealingExecutor, exception ); } workStealingExecutors.clear(); if ( exception != null ) { throw new RuntimeException( "Unable to shut down job scheduler properly.", exception ); } }
@Override public IndexSample sampleIndex() throws IndexNotFoundKernelException { List<IndexSample> samples = new ArrayList<>(); Exception exception = null; for ( IndexSampler sampler : samplers ) { try { samples.add( sampler.sampleIndex() ); } catch ( IndexNotFoundKernelException | RuntimeException e ) { exception = Exceptions.chain( exception, e ); } } if ( exception != null ) { Exceptions.throwIfUnchecked( exception ); throw (IndexNotFoundKernelException)exception; } return combineSamples( samples ); }
@Override public void setCursorException( String message ) { cursorException = Exceptions.chain( cursorException, new CursorException( message ) ); }
ex = Exceptions.chain( ex, e );
e = Exceptions.chain( e, e1 );
private static IndexEntryConflictException buildCauseChain( Set<IndexEntryConflictException> conflicts ) { IndexEntryConflictException chainedConflicts = null; for ( IndexEntryConflictException conflict : conflicts ) { chainedConflicts = Exceptions.chain( chainedConflicts, conflict ); } return chainedConflicts; }
private RuntimeException consumeAndChainException( T instance, Consumer<T> consumer, RuntimeException exception ) { try { consumer.accept( instance ); } catch ( RuntimeException e ) { exception = Exceptions.chain( exception, e ); } return exception; } }
private InterruptedException shutdownPool( ExecutorService pool, InterruptedException exception ) { if ( pool != null ) { pool.shutdown(); try { pool.awaitTermination( 30, TimeUnit.SECONDS ); } catch ( InterruptedException e ) { return Exceptions.chain( exception, e ); } } return exception; } }
private LifecycleException stopInstances( List<LifecycleInstance> instances ) { LifecycleException ex = null; for ( int i = instances.size() - 1; i >= 0; i-- ) { LifecycleInstance lifecycleInstance = instances.get( i ); try { lifecycleInstance.stop(); } catch ( LifecycleException e ) { ex = Exceptions.chain( ex, e ); } } return ex; }
/** * Closes the node,relationship,property and relationship type stores. */ @Override public void close() { RuntimeException ex = null; for ( StoreType type : STORE_TYPES ) { try { closeStore( type ); } catch ( RuntimeException t ) { ex = Exceptions.chain( ex, t ); } } if ( ex != null ) { throw ex; } }
private RuntimeException exitConstructor( Throwable throwable ) { try { close(); } catch ( IOException e ) { throwable = Exceptions.chain( new UncheckedIOException( e ), throwable ); } appendTreeInformation( throwable ); Exceptions.throwIfUnchecked( throwable ); return new RuntimeException( throwable ); }
@Override public void shutdown() { started = false; // First shut down the scheduler, so no new tasks are queued up in the pools. InterruptedException exception = shutDownScheduler(); // Then shut down the thread pools. This involves cancelling jobs which hasn't been cancelled already, // so we avoid having to wait the full maximum wait time on the executor service shut-downs. exception = Exceptions.chain( exception, pools.shutDownAll() ); // Finally, we shut the work-stealing executors down. for ( ExecutorService workStealingExecutor : workStealingExecutors.values() ) { exception = shutdownPool( workStealingExecutor, exception ); } workStealingExecutors.clear(); if ( exception != null ) { throw new RuntimeException( "Unable to shut down job scheduler properly.", exception ); } }
@Override public IndexSample sampleIndex() throws IndexNotFoundKernelException { List<IndexSample> samples = new ArrayList<>(); Exception exception = null; for ( IndexSampler sampler : samplers ) { try { samples.add( sampler.sampleIndex() ); } catch ( IndexNotFoundKernelException | RuntimeException e ) { exception = Exceptions.chain( exception, e ); } } if ( exception != null ) { Exceptions.throwIfUnchecked( exception ); throw (IndexNotFoundKernelException)exception; } return combineSamples( samples ); }