org.apache.wicket.ThreadContext类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.apache.wicket.ThreadContext类的一些代码示例,展示了ThreadContext类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext类的具体详情如下:
包路径:org.apache.wicket.ThreadContext
类名称:ThreadContext

ThreadContext介绍

[英]Holds thread local state for Wicket data.
[中]保存Wicket数据的线程本地状态。

代码示例

代码示例来源: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: 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/wicket

/**
 * Checks if the <code>Application</code> threadlocal is set in this thread
 * 
 * @return true if {@link Application#get()} can return the instance of application, false
 *         otherwise
 */
public static boolean exists()
{
  return ThreadContext.getApplication() != null;
}

代码示例来源: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

@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: at.molindo/molindo-wicket-utils

/**
 * 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);
  }
}

代码示例来源:origin: org.apache.wicket/wicket-native-websocket-core

Application oldApplication = ThreadContext.getApplication();
Session oldSession = ThreadContext.getSession();
RequestCycle oldRequestCycle = ThreadContext.getRequestCycle();
  ThreadContext.setRequestCycle(requestCycle);
  ThreadContext.setApplication(application);
    ThreadContext.setSession(session);
    ThreadContext.setApplication(oldApplication);
    ThreadContext.setRequestCycle(oldRequestCycle);
    ThreadContext.setSession(oldSession);

代码示例来源: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: at.molindo/molindo-wicket-utils

Session oldSession = ThreadContext.exists() ? ThreadContext.getSession() : null;
ThreadContext oldContext = ThreadContext.detach();
  ThreadContext.setApplication(webApplication);
  ThreadContext.setSession(oldSession);
  ThreadContext.setRequestCycle(webApplication.createRequestCycle(request, response));
  Session newSession = ThreadContext.getSession();
  ThreadContext.restore(oldContext);
  if (oldSession == null && newSession != null && !newSession.isTemporary()) {
    ThreadContext.setSession(newSession);

代码示例来源: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: org.jabylon/rest.ui

private void internalUmount(String path){
    //workaround so wicket doesn't choke because the thread context isn't filled (wrong thread)
    Application application = ThreadContext.getApplication();
    if (application == null)
      ThreadContext.setApplication(JabylonApplication.this);
    if(ThreadContext.getSession()==null)
      ThreadContext.setSession(new WebSession(createFakeRequest(null)));
//        unmount(path);
    /*
     * umount seems to be greedy, e.g. a prefix match is enough.
     * That's troublesome because umount /settings/log will also umount /settings
     */
    ICompoundRequestMapper rootRequestMapperAsCompound = getRootRequestMapperAsCompound();
    if (rootRequestMapperAsCompound instanceof CompoundRequestMapper) {
      CompoundRequestMapper compound = (CompoundRequestMapper) rootRequestMapperAsCompound;
      Iterator<IRequestMapper> it = compound.iterator();
      while (it.hasNext()) {
        IRequestMapper iRequestMapper = it.next();
        if (iRequestMapper instanceof ResouceAwareMountedMapper) {
          ResouceAwareMountedMapper mapper = (ResouceAwareMountedMapper) iRequestMapper;
          if(path.equals(mapper.getMountPath()))
          {
            logger.info("Unmounting  {}",path);
            getRootRequestMapperAsCompound().remove(mapper);
          }
        }
      }
    }
  }

代码示例来源:origin: apache/wicket

@Override
public Object deserialize(final byte[] data)
  ThreadContext old = ThreadContext.get(false);
  final ByteArrayInputStream in = new ByteArrayInputStream(data);
  ObjectInputStream ois = null;
  try
    Application oldApplication = ThreadContext.getApplication();
    try
        if (app != null)
          ThreadContext.setApplication(app);
        ThreadContext.setApplication(oldApplication);
        IOUtils.close(ois);
    ThreadContext.restore(old);

代码示例来源: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.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: org.jabylon/rest.ui

@Override
public Object addingService(ServiceReference ref) {
  PageProvider service = (PageProvider)bundleContext.getService(ref);
  Object pathObject = ref.getProperty(PageProvider.MOUNT_PATH_PROPERTY);
  if (pathObject instanceof String) {
    String path = (String) pathObject;
    Class pageClass = service.getPageClass();
    if(pageClass==ResourcePage.class) {
      //workaround so wicket doesn't choke because the thread context isn't filled (wrong thread)
      ThreadContext.setApplication(JabylonApplication.this);
      ThreadContext.setSession(new WebSession(createFakeRequest(null)));
      //if the main page is ready, we can mount the rest of the pages
        initMainPages();
    }
    logger.info("Mounting new page {} at {}", pageClass, path); //$NON-NLS-1$
    mount(new ResouceAwareMountedMapper(path, pageClass));
  } else {
    logger.warn("Ignored Page {} because it was registered with invalid path property '{}'", service, pathObject); //$NON-NLS-1$
  }
  return service;
}

代码示例来源:origin: apache/wicket

/**
 *
 */
private void newSession()
{
  ThreadContext.setSession(null);
  // the following will create a new session and put it in the thread context
  session = Session.get();
}

代码示例来源:origin: org.apache.wicket/wicket-core

/**
 * 
 * @param requestCycle
 */
private static void set(RequestCycle requestCycle)
{
  ThreadContext.setRequestCycle(requestCycle);
}

代码示例来源:origin: apache/wicket

/**
 * Checks existence of a <code>Session</code> associated with the current thread.
 * 
 * @return {@code true} if {@link Session#get()} can return the instance of session,
 *         {@code false} otherwise
 */
public static boolean exists()
{
  Session session = ThreadContext.getSession();
  if (session == null)
  {
    // no session is available via ThreadContext, so lookup in session store
    RequestCycle requestCycle = RequestCycle.get();
    if (requestCycle != null)
    {
      session = Application.get().getSessionStore().lookup(requestCycle.getRequest());
      if (session != null)
      {
        ThreadContext.setSession(session);
      }
    }
  }
  return session != null;
}

代码示例来源:origin: org.apache.wicket/wicket-core

/**
 * Returns request cycle associated with current thread.
 * 
 * @return request cycle instance or <code>null</code> if no request cycle is associated with
 *         current thread.
 */
public static RequestCycle get()
{
  return ThreadContext.getRequestCycle();
}

代码示例来源:origin: org.apache.wicket/wicket-core

private void cleanupBoundApplicationAndSession()
{
  ThreadContext.detach();
}

相关文章