Consumer<Boolean> contextPreservingListener = forced -> { try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { storedContext.restore(); listener.accept(forced);
boolean whileRunning = false; try (ThreadContext.StoredContext ignore = stashContext()){ ctx.restore(); whileRunning = true; in.run();
@Override protected void doRun() throws Exception { boolean whileRunning = false; threadsOriginalContext = stashContext(); try { creatorsContext.restore(); whileRunning = true; in.doRun(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
Consumer<Boolean> contextPreservingListener = forced -> { try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { storedContext.restore(); listener.accept(forced);
@Override protected void doRun() throws Exception { boolean whileRunning = false; threadsOriginalContext = stashContext(); try { creatorsContext.restore(); whileRunning = true; in.doRun(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
@Override protected void doRun() throws Exception { boolean whileRunning = false; threadsOriginalContext = stashContext(); try { creatorsContext.restore(); whileRunning = true; in.doRun(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
@Override protected void doRun() throws Exception { boolean whileRunning = false; threadsOriginalContext = stashContext(); try { creatorsContext.restore(); whileRunning = true; in.doRun(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
@Override public void run() { boolean whileRunning = false; try (ThreadContext.StoredContext ignore = stashContext()){ ctx.restore(); whileRunning = true; in.run(); whileRunning = false; } catch (IllegalStateException ex) { if (whileRunning || threadLocal.closed.get() == false) { throw ex; } // if we hit an ISE here we have been shutting down // this comes from the threadcontext and barfs if // our threadpool has been shutting down } }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
@Override public void handleResponse(T response) { contextToRestore.restore(); innerHandler.handleResponse(response); }
@Override public void handleException(TransportException e) { contextToRestore.restore(); innerHandler.handleException(e); }
@Override public void onAfter() { try { in.onAfter(); } finally { if (threadsOriginalContext != null) { threadsOriginalContext.restore(); } } }
@Override public void onAfter() { try { in.onAfter(); } finally { if (threadsOriginalContext != null) { threadsOriginalContext.restore(); } } }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
@Override public void onAfter() { try { in.onAfter(); } finally { if (threadsOriginalContext != null) { threadsOriginalContext.restore(); } } }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
@Override public void onAfter() { try { in.onAfter(); } finally { if (threadsOriginalContext != null) { threadsOriginalContext.restore(); } } }
@Override public void handleResponse(T response) { contextToRestore.restore(); innerHandler.handleResponse(response); }
@Override public void handleException(TransportException e) { contextToRestore.restore(); innerHandler.handleException(e); }