Package de.javakaffee.web.msm.MemcachedSessionService

Examples of de.javakaffee.web.msm.MemcachedSessionService.SessionManager


        _daemon3 = createDaemon( address3 );
        _daemon3.start();

        final String memcachedNodes = MEMCACHED_NODES + "," + NODE_ID_3 + ":localhost:" + MEMCACHED_PORT_3;

        final SessionManager manager = _tomcat1.getManager();
        manager.setMaxInactiveInterval( 5 );
        manager.setMemcachedNodes(memcachedNodes);
        manager.getMemcachedSessionService().setSessionBackupAsync(false);

        waitForReconnect(manager.getMemcachedSessionService().getMemcached(), 3, 1000);

        final NodeIdList nodeIdList = NodeIdList.create(NODE_ID_1, NODE_ID_2, NODE_ID_3);
        final Map<String, MemCacheDaemon<?>> memcachedsByNodeId = new HashMap<String, MemCacheDaemon<?>>();
        memcachedsByNodeId.put(NODE_ID_1, _daemon1);
        memcachedsByNodeId.put(NODE_ID_2, _daemon2);
View Full Code Here


        _request = mock( Request.class );
        _response = mock( Response.class );

        final Context _contextContainer = mock(Context.class);
        final Host _hostContainer = mock(Host.class);
        final SessionManager _manager = mock(SessionManager.class);

        when(_service.getManager()).thenReturn(_manager);
        when(_manager.getContainer()).thenReturn(_contextContainer);
        when(_contextContainer.getParent()).thenReturn(_hostContainer);
        when(_contextContainer.getPath()).thenReturn("/");

        _sessionTrackerValve = createSessionTrackerValve();
        _nextValve = mock( Valve.class );
View Full Code Here

    @Test( enabled = true )
    public void testHttpSessionActivationListenersNotifiedOnLoadWithJvmRoute() throws Exception {



        final SessionManager manager1 = _tomcat1.getManager();
        final SessionManager manager2 = _tomcat2.getManager();

        final SessionIdFormat format = new SessionIdFormat();

        final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertEquals( format.extractJvmRoute( sessionId1 ), JVM_ROUTE_1 );

        final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 );
        session.setAttribute( "listener", new RecordingSessionActivationListener() );

        get( _httpClient, TC_PORT_1, sessionId1 );

        final String sessionId2 = get( _httpClient, TC_PORT_2, sessionId1 ).getSessionId();
        assertEquals( format.stripJvmRoute( sessionId2 ), format.stripJvmRoute( sessionId1 ) );
        assertEquals( format.extractJvmRoute( sessionId2 ), JVM_ROUTE_2 );

        final MemcachedBackupSession loaded = (MemcachedBackupSession) manager2.findSession( sessionId2 );
        assertNotNull( loaded );
        final RecordingSessionActivationListener listener = (RecordingSessionActivationListener) loaded.getAttribute( "listener" );
        assertNotNull( listener );

        final String notifiedSessionId = listener.getSessionDidActivate();
View Full Code Here

        _tomcat2.stop();

        _tomcat1 = startTomcat( TC_PORT_1, null );
        _tomcat2 = startTomcat( TC_PORT_2, null );

        final SessionManager manager1 = _tomcat1.getManager();
        final SessionManager manager2 = _tomcat2.getManager();

        final SessionIdFormat format = new SessionIdFormat();

        final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertNull( format.extractJvmRoute( sessionId1 ) );

        final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 );
        session.setAttribute( "listener", new RecordingSessionActivationListener() );

        get( _httpClient, TC_PORT_1, sessionId1 );

        final String sessionId2 = get( _httpClient, TC_PORT_2, sessionId1 ).getSessionId();
        assertEquals( sessionId2, sessionId1 );

        final MemcachedBackupSession loaded = (MemcachedBackupSession) manager2.findSession( sessionId2 );
        assertNotNull( loaded );
        final RecordingSessionActivationListener listener = (RecordingSessionActivationListener) loaded.getAttribute( "listener" );
        assertNotNull( listener );

        final String notifiedSessionId = listener.getSessionDidActivate();
View Full Code Here

    @SuppressWarnings("unchecked")
    @BeforeMethod
    public void setup() throws Exception {

        final SessionManager manager = createSessionManager();

        _service = manager.getMemcachedSessionService();
        _service.setMemcachedNodes( "n1:127.0.0.1:11211" );
        _service.setSessionBackupAsync( false );
        _service.setSticky( true );

        final StandardContext context = createContext();
        context.setBackgroundProcessorDelay( 1 ); // needed for test of updateExpiration
        manager.setContainer( context );

        _memcachedMock = mock( MemcachedClient.class );

        final OperationFuture<Boolean> setResultMock = mock( OperationFuture.class );
        when( setResultMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.TRUE );
View Full Code Here

        tomcat.addUser(USER_NAME,PASSWORD);
        tomcat.addRole(USER_NAME,ROLE_NAME);

        // brings logging.properties
        tomcat.setBaseDir(docBase);
        final SessionManager sessionManager = createSessionManager();


        Context context;
        try {
            context = tomcat.addWebapp(CONTEXT_PATH, docBase + fileSeparator + "webapp");
        } catch (ServletException e) {
            throw new IllegalStateException(e);
        }

        context.setManager( sessionManager );
        context.setBackgroundProcessorDelay( 1 );
        context.setCookies(cookies);

        if ( loginType != null ) {
            context.addConstraint( createSecurityConstraint( "/*", ROLE_NAME ) );
            context.addSecurityRole( ROLE_NAME );
            final LoginConfig loginConfig = loginType == LoginType.FORM
                    ? new LoginConfig( "FORM", null, "/login", "/error" )
                    : new LoginConfig( "BASIC", null, null, null );
            context.setLoginConfig( loginConfig );
        }

        /* we must set the maxInactiveInterval after the context,
         * as setContainer(context) uses the session timeout set on the context
         */
        sessionManager.getMemcachedSessionService().setMemcachedNodes( memcachedNodes );
        sessionManager.getMemcachedSessionService().setFailoverNodes( failoverNodes );
        sessionManager.getMemcachedSessionService().setEnabled(enabled);
        sessionManager.getMemcachedSessionService().setSticky(sticky);
        if(lockingMode != null) {
            sessionManager.getMemcachedSessionService().setLockingMode(lockingMode.name());
        }
        sessionManager.getMemcachedSessionService().setMemcachedProtocol(memcachedProtocol);
        sessionManager.getMemcachedSessionService().setUsername(username);
        sessionManager.setMaxInactiveInterval( sessionTimeout ); // 1 second
        sessionManager.getMemcachedSessionService().setSessionBackupAsync( false );
        sessionManager.getMemcachedSessionService().setSessionBackupTimeout( 100 );
        sessionManager.setProcessExpiresFrequency( 1 ); // 1 second (factor for context.setBackgroundProcessorDelay)
        sessionManager.getMemcachedSessionService().setTranscoderFactoryClass( transcoderFactoryClassName != null ? transcoderFactoryClassName : DEFAULT_TRANSCODER_FACTORY );
        sessionManager.getMemcachedSessionService().setRequestUriIgnorePattern(".*\\.(png|gif|jpg|css|js|ico)$");
        sessionManager.getMemcachedSessionService().setStorageKeyPrefix(storageKeyPrefix);

        return tomcat;
    }
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.MemcachedSessionService.SessionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.