当前位置: 首页>>代码示例>>Java>>正文


Java Session.endAccess方法代码示例

本文整理汇总了Java中org.apache.catalina.Session.endAccess方法的典型用法代码示例。如果您正苦于以下问题:Java Session.endAccess方法的具体用法?Java Session.endAccess怎么用?Java Session.endAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Session的用法示例。


在下文中一共展示了Session.endAccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findSession

import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 */
@Override
public Session findSession(String id) throws IOException {

    Session session = super.findSession(id);
    // OK, at this point, we're not sure if another thread is trying to
    // remove the session or not so the only way around this is to lock it
    // (or attempt to) and then try to get it by this session id again. If
    // the other code ran swapOut, then we should get a null back during
    // this run, and if not, we lock it out so we can access the session
    // safely.
    if(session != null) {
        synchronized(session){
            session = super.findSession(session.getIdInternal());
            if(session != null){
               // To keep any external calling code from messing up the
               // concurrency.
               session.access();
               session.endAccess();
            }
        }
    }
    if (session != null)
        return session;

    // See if the Session is in the Store
    session = swapIn(id);
    return session;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:PersistentManagerBase.java

示例2: findSession

import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
 * Return the active Session, associated with this Manager, with the
 * specified session id (if any); otherwise return <code>null</code>.
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 *
 * @param id The session id for the session to be returned
 *
 * @exception IllegalStateException if a new session cannot be
 *  instantiated for any reason
 * @exception IOException if an input/output error occurs while
 *  processing this request
 */
public Session findSession(String id) throws IOException {

    Session session = super.findSession(id);
    // OK, at this point, we're not sure if another thread is trying to
    // remove the session or not so the only way around this is to lock it
    // (or attempt to) and then try to get it by this session id again. If
    // the other code ran swapOut, then we should get a null back during
    // this run, and if not, we lock it out so we can access the session
    // safely.
    if(session != null) {
        synchronized(session){
            session = super.findSession(session.getIdInternal());
            if(session != null){
               // To keep any external calling code from messing up the
               // concurrency.
               session.access();
               session.endAccess();
            }
        }
    }
    if (session != null)
        return (session);

    // See if the Session is in the Store
    session = swapIn(id);
    return (session);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:PersistentManagerBase.java

示例3: findSession

import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * This method checks the persistence store if persistence is enabled,
 * otherwise just uses the functionality from ManagerBase.
 */
@Override
public Session findSession(String id) throws IOException {

	Session session = super.findSession(id);
	// OK, at this point, we're not sure if another thread is trying to
	// remove the session or not so the only way around this is to lock it
	// (or attempt to) and then try to get it by this session id again. If
	// the other code ran swapOut, then we should get a null back during
	// this run, and if not, we lock it out so we can access the session
	// safely.
	if (session != null) {
		synchronized (session) {
			session = super.findSession(session.getIdInternal());
			if (session != null) {
				// To keep any external calling code from messing up the
				// concurrency.
				session.access();
				session.endAccess();
			}
		}
	}
	if (session != null)
		return session;

	// See if the Session is in the Store
	session = swapIn(id);
	return session;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:35,代码来源:PersistentManagerBase.java

示例4: backsUpOnce_56698

import org.apache.catalina.Session; //导入方法依赖的package包/类
@Test
public void backsUpOnce_56698() throws IOException, LifecycleException,
        InterruptedException {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.setDistributable(true);

    Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
    ctx.addServletMapping("/dummy", "DummyServlet");

    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    tomcat.start();
    String sessionId = getUrl("http://localhost:" + getPort() + "/dummy")
            .toString();

    // Note: PersistenceManager.findSession() silently updates
    // session.lastAccessedTime, so call it only once before other work.
    Session session = manager.findSession(sessionId);

    // Wait until request processing ends, as Request.recycle() updates
    // session.lastAccessedTime via session.endAccess().
    waitWhileSessionIsActive((StandardSession) session);

    long lastAccessedTime = session.getLastAccessedTimeInternal();

    // Session should be idle at least for 0 second (maxIdleBackup)
    // to be eligible for persistence, thus no need to wait.

    // Waiting a bit, to catch changes in last accessed time of a session
    waitForClockUpdate();

    manager.processPersistenceChecks();
    Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
    Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());

    // session was not accessed, so no save will be performed
    waitForClockUpdate();
    manager.processPersistenceChecks();
    Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
    Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());

    // access session
    session.access();
    session.endAccess();

    // session was accessed, so it will be saved once again
    manager.processPersistenceChecks();
    Assert.assertEquals(Arrays.asList(sessionId, sessionId),
            store.getSavedIds());

    // session was not accessed, so once again no save will happen
    manager.processPersistenceChecks();
    Assert.assertEquals(Arrays.asList(sessionId, sessionId),
            store.getSavedIds());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:65,代码来源:TestPersistentManagerIntegration.java


注:本文中的org.apache.catalina.Session.endAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。