private void cleanupBoundApplicationAndSession() { ThreadContext.detach(); }
private void cleanupBoundApplicationAndSession() { ThreadContext.detach(); }
/** * 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); } }
/** * Destroys the tester. Restores {@link ThreadContext} to state before instance of * {@link WicketTester} was created. */ public void destroy() { try { ThreadContext.setApplication(application); application.internalDestroy(); } finally { ThreadContext.detach(); } }
/** * 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); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { boolean existed = ThreadContext.exists(); if (existed == false) { ThreadContext.setApplication(application); } try { return method.invoke(o, args); } finally { if (existed == false) { ThreadContext.detach(); } } } });
/** * Destroys the tester. Restores {@link ThreadContext} to state before instance of * {@link WicketTester} was created. */ public void destroy() { try { ThreadContext.setApplication(application); application.internalDestroy(); } finally { ThreadContext.detach(); } }
@Override public String call() throws Exception { ThreadContext.setApplication(application); ThreadContext.setSession(session); try { final ConnInstanceTO connector = connectorRestClient.read(key); return String.format("{ \"status\": \"%s\", \"target\": \"%s\"}", connectorRestClient.check(connector).getLeft() ? TopologyNode.Status.REACHABLE : TopologyNode.Status.UNREACHABLE, key); } catch (Exception e) { LOG.warn("Error checking connection for {}", key, e); return String.format("{ \"status\": \"%s\", \"target\": \"%s\"}", TopologyNode.Status.FAILURE, key); } finally { ThreadContext.detach(); } } }
@Override public String call() throws Exception { ThreadContext.setApplication(application); ThreadContext.setSession(session); try { final ResourceTO resource = resourceRestClient.read(key); return String.format("{ \"status\": \"%s\", \"target\": \"%s\"}", resourceRestClient.check(resource).getLeft() ? TopologyNode.Status.REACHABLE : TopologyNode.Status.UNREACHABLE, key); } catch (Exception e) { LOG.warn("Error checking connection for {}", key, e); return String.format("{ \"status\": \"%s\", \"target\": \"%s\"}", TopologyNode.Status.FAILURE, key); } finally { ThreadContext.detach(); } } }
/** * @see junit.framework.TestCase#setUp() */ @Before public void commonBefore() { // make sure no leaked threadlocals are present ThreadContext.detach(); WebApplication application = newApplication(); tester = newWicketTester(application); }
private void postToSingleResource(Object payload, AtmosphereResource resource) { AtmosphereEvent event = new AtmosphereEvent(payload, resource); ThreadContext.detach(); ThreadContext.setApplication(application); PageKey key; Collection<EventSubscription> subscriptionsForPage; synchronized (this) { key = trackedPages.get(resource.uuid()); subscriptionsForPage = Collections2.filter( Collections.unmodifiableCollection(subscriptions.get(key)), new EventFilter(event)); } if (key == null) broadcaster.removeAtmosphereResource(resource); else if (!subscriptionsForPage.isEmpty()) post(resource, key, subscriptionsForPage, event); }
/** */ @BeforeEach public void commonBefore() { // make sure no leaked threadlocals are present ThreadContext.detach(); WebApplication application = newApplication(); tester = newWicketTester(application); }
private void postToSingleResource(Object payload, AtmosphereResource resource) { AtmosphereEvent event = new AtmosphereEvent(payload, resource); ThreadContext.detach(); ThreadContext.setApplication(application); PageKey key; Iterable<EventSubscription> subscriptionsForPage; synchronized (this) { key = trackedPages.get(resource.uuid()); Collection<EventSubscription> eventSubscriptions = subscriptions.get(key); subscriptionsForPage = Iterables.filter(ImmutableList.copyOf(eventSubscriptions), new EventFilter(event)); } if (key == null) getBroadcaster().removeAtmosphereResource(resource); else { Iterator<EventSubscription> iterator = subscriptionsForPage.iterator(); if (iterator.hasNext()) post(resource, key, iterator, event); } }
@Override public void run() { ThreadContext.setApplication(application); ThreadContext.setSession(session); try { timeoutHandlingConnectionChecker( new ResourceChecker(key, this.application), resourceTestTimeout, resources, runningResCheck); } finally { ThreadContext.detach(); } } }
ThreadContext.detach(); application = null;
@Override public void run() { ThreadContext.setApplication(application); ThreadContext.setSession(session); try { timeoutHandlingConnectionChecker( new ConnectorChecker(key, this.application), connectorTestTimeout, connectors, runningConnCheck); } finally { ThreadContext.detach(); } } }
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { String appName = getApplicationName(session); WebApplication app = (WebApplication) WebApplication.get(appName); app.getApplicationListeners().add(new ApplicationListener(applicationDestroyed)); try { ThreadContext.setApplication(app); javaxWebSocketProcessor = new JavaxWebSocketProcessor(session, app, endpointConfig); } finally { ThreadContext.detach(); } }
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { String appName = getApplicationName(session); WebApplication app = (WebApplication) WebApplication.get(appName); app.getApplicationListeners().add(new ApplicationListener(applicationDestroyed)); try { ThreadContext.setApplication(app); javaxWebSocketProcessor = new JavaxWebSocketProcessor(session, app, endpointConfig); } finally { ThreadContext.detach(); } }
ThreadContext oldContext = ThreadContext.detach();