本文整理了Java中org.apache.wicket.ThreadContext.setApplication()
方法的一些代码示例,展示了ThreadContext.setApplication()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.setApplication()
方法的具体详情如下:
包路径:org.apache.wicket.ThreadContext
类名称:ThreadContext
方法名:setApplication
[英]Binds the specified application to current thread.
[中]将指定的应用程序绑定到当前线程。
代码示例来源:origin: org.apache.wicket/wicket-core
private WebApplication bindApplication()
{
// find wicket application and bind it to thread
WebApplication application = (WebApplication)Application.get(filterName);
if (application == null)
{
throw new IllegalStateException("Could not find wicket application mapped to filter: " +
filterName +
". Make sure you set filterName attribute to the name of the wicket filter " +
"for the wicket application whose session you want to access.");
}
ThreadContext.setApplication(application);
return application;
}
代码示例来源:origin: apache/wicket
private WebApplication bindApplication()
{
// find wicket application and bind it to thread
WebApplication application = (WebApplication)Application.get(filterName);
if (application == null)
{
throw new IllegalStateException("Could not find wicket application mapped to filter: " +
filterName +
". Make sure you set filterName attribute to the name of the wicket filter " +
"for the wicket application whose session you want to access.");
}
ThreadContext.setApplication(application);
return application;
}
代码示例来源:origin: org.apache.wicket/wicket-core
/**
* 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();
}
}
代码示例来源:origin: org.apache.wicket/wicket-core
/**
* 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);
}
}
代码示例来源:origin: apache/wicket
/**
* 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);
}
}
代码示例来源:origin: apache/wicket
@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();
}
}
}
});
代码示例来源:origin: apache/wicket
/**
* 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();
}
}
代码示例来源:origin: apache/syncope
@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();
}
}
}
代码示例来源:origin: apache/syncope
@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();
}
}
}
代码示例来源:origin: OrienteerBAP/Orienteer
private void executeInNewThread(Runnable runnable) {
OrienteerWebSession session = OrienteerWebSession.get();
OrienteerWebApplication app = OrienteerWebApplication.get();
RequestCycle requestCycle = RequestCycle.get();
new Thread(() -> {
ThreadContext.setSession(session);
ThreadContext.setApplication(app);
ThreadContext.setRequestCycle(requestCycle);
runnable.run();
}).start();
}
代码示例来源:origin: org.apache.wicket/wicket-atmosphere
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);
}
代码示例来源:origin: inductiveautomation/ignition-sdk-examples
@Override
public void shutdown() {
/* remove our bundle */
BundleUtil.get().removeBundle("HomeConnect");
if (context.getState() != ContextState.STOPPING) {
WebApplication wicket = context.getWebApplication();
Application currentApplication = ThreadContext.getApplication();
ThreadContext.setApplication(wicket);
try {
wicket.unmount("ack/${id}");
} finally {
ThreadContext.setApplication(currentApplication);
}
}
}
代码示例来源:origin: org.ops4j.pax.wicket/org.ops4j.pax.wicket.service
/** {@inheritDoc} */
@Override
public final PageMounter addingService(ServiceReference<PageMounter> reference) {
PageMounter mounter = super.addingService(reference);
List<? extends MountPointInfo> infos = mounter.getMountPoints();
for (MountPointInfo info : infos) {
LOGGER.trace("Make sure that path {} is clear before trying to remount", info.getPath());
Application oldApp = ThreadContext.getApplication();
ThreadContext.setApplication(application);
try {
application.unmount(info.getPath());
} catch (IllegalArgumentException e) {
LOGGER.trace("Unmounting not possible since nothing here by now.");
// this could happen if wicket had not been started at all by now --> simply ignore
}
LOGGER.trace("Trying to mount {} with {}", info.getPath(), info.getPage().getName());
application.mountPage(info.getPath(), info.getPage());
ThreadContext.setApplication(oldApp);
LOGGER.info("Mounted {} with {}", info.getPath(), info.getPage().getName());
}
return mounter;
}
代码示例来源:origin: OrienteerBAP/Orienteer
@Override
public CompletableFuture<Void> fetchMailsAsync(OMailSettings settings, String folderName, Consumer<Message> consumer) {
OrienteerWebSession session = OrienteerWebSession.get();
OrienteerWebApplication app = OrienteerWebApplication.get();
RequestCycle requestCycle = RequestCycle.get();
return CompletableFuture.runAsync(() -> {
ThreadContext.setSession(session);
ThreadContext.setApplication(app);
ThreadContext.setRequestCycle(requestCycle);
try {
fetchMails(settings, folderName, consumer);
} catch (Exception ex) {
LOG.error("Error during fetching mails: {}", settings, ex);
}
});
}
代码示例来源:origin: apache/syncope
@Override
public void run() {
ThreadContext.setApplication(application);
ThreadContext.setSession(session);
try {
timeoutHandlingConnectionChecker(
new ResourceChecker(key, this.application),
resourceTestTimeout,
resources,
runningResCheck);
} finally {
ThreadContext.detach();
}
}
}
代码示例来源:origin: apache/syncope
@Override
public void run() {
ThreadContext.setApplication(application);
ThreadContext.setSession(session);
try {
timeoutHandlingConnectionChecker(
new ConnectorChecker(key, this.application),
connectorTestTimeout,
connectors,
runningConnCheck);
} finally {
ThreadContext.detach();
}
}
}
代码示例来源:origin: OrienteerBAP/Orienteer
private void performTask(OSendMailTaskSessionRuntime runtime) {
OrienteerWebSession session = OrienteerWebSession.get();
OrienteerWebApplication app = OrienteerWebApplication.get();
RequestCycle requestCycle = RequestCycle.get();
new Thread(() -> {
ThreadContext.setSession(session);
ThreadContext.setApplication(app);
ThreadContext.setRequestCycle(requestCycle);
DBClosure.sudoConsumer(db -> {
try {
sendMails(runtime);
} catch (Exception ex) {
LOG.error("Error occurred during perform task {}", OSendMailTask.this, ex);
} finally {
runtime.finish();
}
});
}).start();
}
代码示例来源:origin: org.ops4j.pax.wicket/org.ops4j.pax.wicket.service
/** {@inheritDoc} */
@Override
public final void removedService(ServiceReference<PageMounter> reference, PageMounter mounter) {
PageMounter pageMounter = mounter;
List<? extends MountPointInfo> infos = pageMounter.getMountPoints();
for (MountPointInfo info : infos) {
LOGGER.trace("Trying to mount {} with {}", info.getPath(), info.getPage().getName());
Application oldApp = ThreadContext.getApplication();
ThreadContext.setApplication(application);
if (!Session.exists()) {
Request request = new MockWebRequest(Url.parse(info.getPath()));
ThreadContext.setSession(new WebSession(request));
}
application.unmount(info.getPath());
ThreadContext.setApplication(oldApp);
LOGGER.info("Unmounted {} with {}", info.getPath(), info.getPage().getName());
}
super.removedService(reference, pageMounter);
}
}
代码示例来源:origin: apache/wicket
@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();
}
}
代码示例来源:origin: org.apache.wicket/wicket-native-websocket-javax
@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();
}
}
内容来源于网络,如有侵权,请联系作者删除!