/** * unset request and session to force mocking */ public static <V> V withNewRequest(WebApplication webApplication, IMockRequestCallback<V> callback) { ThreadContext oldContext = ThreadContext.detach(); try { return withRequest(webApplication, callback); } finally { ThreadContext.restore(oldContext); } }
/** * Get the result from the given supplier inside a bound {@link ThreadContext}. * * @param supplier * supplier * @return result of {@link Supplier#get()} */ private <T> T inThreadContext(Supplier<T> supplier) { ThreadContext oldContext = ThreadContext.detach(); try { ThreadContext.setApplication(application); return supplier.get(); } finally { ThreadContext.restore(oldContext); } }
/** * Get the result from the given supplier inside a bound {@link ThreadContext}. * * @param supplier * supplier * @return result of {@link Supplier#get()} */ private <T> T inThreadContext(Supplier<T> supplier) { ThreadContext oldContext = ThreadContext.detach(); try { ThreadContext.setApplication(application); return supplier.get(); } finally { ThreadContext.restore(oldContext); } }
/** * Post an event to a single resource. This will invoke the event handlers on all components on * the page with the suspended connection. The resulting AJAX update (if any) is pushed to the * client. * * @param event * @param resource */ public void post(Object event, AtmosphereResource resource) { ThreadContext oldContext = ThreadContext.get(false); try { postToSingleResource(event, resource); } finally { ThreadContext.restore(oldContext); } }
/** * Post an event to a single resource. This will invoke the event handlers on all components on * the page with the suspended connection. The resulting AJAX update (if any) is pushed to the * client. * * @param event * @param resource */ public void post(Object event, AtmosphereResource resource) { ThreadContext oldContext = ThreadContext.get(false); try { postToSingleResource(event, resource); } finally { ThreadContext.restore(oldContext); } }
/** * Post an event to all pages that have a suspended connection. This will invoke the event * handlers on components, annotated with {@link Subscribe}. The resulting AJAX updates are * pushed to the clients. * * @param event */ public void post(Object event) { ThreadContext oldContext = ThreadContext.get(false); try { for (AtmosphereResource resource : ImmutableList.copyOf(getBroadcaster().getAtmosphereResources())) { postToSingleResource(event, resource); } } finally { ThreadContext.restore(oldContext); } }
/** * Post an event to all pages that have a suspended connection. This will invoke the event * handlers on components, annotated with {@link Subscribe}. The resulting AJAX updates are * pushed to the clients. * * @param event */ public void post(Object event) { ThreadContext oldContext = ThreadContext.get(false); try { for (AtmosphereResource resource : broadcaster.getAtmosphereResources()) { postToSingleResource(event, resource); } } finally { ThreadContext.restore(oldContext); } }
ThreadContext.restore(old);
ThreadContext.restore(old);
ThreadContext.restore(previousThreadContext);
ThreadContext.restore(previousThreadContext);
} finally { Session newSession = ThreadContext.getSession(); ThreadContext.restore(oldContext); if (oldSession == null && newSession != null && !newSession.isTemporary()) {