Search in sources :

Example 1 with SessionPersistedObjectAnalyzer

use of org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer in project tapestry-5 by apache.

the class SessionImplTest method dirty_persisted_object_is_forced_to_update.

@Test
public void dirty_persisted_object_is_forced_to_update() {
    HttpSession hs = mockHttpSession();
    HttpServletRequest hsr = mockHttpServletRequest();
    SessionPersistedObjectAnalyzer analyzer = newMock(SessionPersistedObjectAnalyzer.class);
    Object dirty = new Object();
    SessionLock lock = mockLock();
    lock.acquireWriteLock();
    train_getAttribute(hs, "dirty", dirty);
    replay();
    Session session = new ClusteredSessionImpl(hsr, hs, lock, analyzer);
    assertSame(session.getAttribute("dirty"), dirty);
    verify();
    expect(analyzer.checkAndResetDirtyState(dirty)).andReturn(true);
    train_getSession(hsr, false, hs);
    lock.acquireWriteLock();
    hs.setAttribute("dirty", dirty);
    replay();
    session.restoreDirtyObjects();
    verify();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionPersistedObjectAnalyzer(org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) HttpSession(javax.servlet.http.HttpSession) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 2 with SessionPersistedObjectAnalyzer

use of org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer in project tapestry-5 by apache.

the class TapestryHttpModule method contributeSessionPersistedObjectAnalyzer.

/**
 * Identifies String, Number and Boolean as immutable objects, a catch-all
 * handler for Object (that understands
 * the {@link org.apache.tapestry5.http.annotations.ImmutableSessionPersistedObject} annotation),
 * and a handler for {@link org.apache.tapestry5.http.OptimizedSessionPersistedObject}.
 *
 * @since 5.1.0.0
 */
@SuppressWarnings("rawtypes")
public static void contributeSessionPersistedObjectAnalyzer(MappedConfiguration<Class, SessionPersistedObjectAnalyzer> configuration) {
    configuration.add(Object.class, new DefaultSessionPersistedObjectAnalyzer());
    SessionPersistedObjectAnalyzer<Object> immutable = new SessionPersistedObjectAnalyzer<Object>() {

        public boolean checkAndResetDirtyState(Object sessionPersistedObject) {
            return false;
        }
    };
    configuration.add(String.class, immutable);
    configuration.add(Number.class, immutable);
    configuration.add(Boolean.class, immutable);
    configuration.add(OptimizedSessionPersistedObject.class, new OptimizedSessionPersistedObjectAnalyzer());
}
Also used : SessionPersistedObjectAnalyzer(org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer) DefaultSessionPersistedObjectAnalyzer(org.apache.tapestry5.http.internal.services.DefaultSessionPersistedObjectAnalyzer) OptimizedSessionPersistedObjectAnalyzer(org.apache.tapestry5.http.internal.services.OptimizedSessionPersistedObjectAnalyzer) DefaultSessionPersistedObjectAnalyzer(org.apache.tapestry5.http.internal.services.DefaultSessionPersistedObjectAnalyzer) OptimizedSessionPersistedObject(org.apache.tapestry5.http.OptimizedSessionPersistedObject) OptimizedSessionPersistedObjectAnalyzer(org.apache.tapestry5.http.internal.services.OptimizedSessionPersistedObjectAnalyzer)

Aggregations

SessionPersistedObjectAnalyzer (org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 OptimizedSessionPersistedObject (org.apache.tapestry5.http.OptimizedSessionPersistedObject)1 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)1 DefaultSessionPersistedObjectAnalyzer (org.apache.tapestry5.http.internal.services.DefaultSessionPersistedObjectAnalyzer)1 OptimizedSessionPersistedObjectAnalyzer (org.apache.tapestry5.http.internal.services.OptimizedSessionPersistedObjectAnalyzer)1 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)1 Session (org.apache.tapestry5.http.services.Session)1 Test (org.testng.annotations.Test)1