Search in sources :

Example 1 with SessionManagerConfiguration

use of org.wildfly.clustering.web.session.SessionManagerConfiguration in project wildfly by wildfly.

the class DistributableSessionManagerFactory method createSessionManager.

@Override
public io.undertow.server.session.SessionManager createSessionManager(final Deployment deployment) {
    DeploymentInfo info = deployment.getDeploymentInfo();
    boolean statisticsEnabled = info.getMetricsCollector() != null;
    RecordableInactiveSessionStatistics inactiveSessionStatistics = statisticsEnabled ? new RecordableInactiveSessionStatistics() : null;
    Supplier<String> factory = new IdentifierFactoryAdapter(info.getSessionIdGenerator());
    SessionExpirationListener expirationListener = new UndertowSessionExpirationListener(deployment, this.listeners);
    SessionManagerConfiguration<ServletContext> configuration = new SessionManagerConfiguration<ServletContext>() {

        @Override
        public ServletContext getServletContext() {
            return deployment.getServletContext();
        }

        @Override
        public Supplier<String> getIdentifierFactory() {
            return factory;
        }

        @Override
        public SessionExpirationListener getExpirationListener() {
            return expirationListener;
        }

        @Override
        public Recordable<ImmutableSessionMetaData> getInactiveSessionRecorder() {
            return inactiveSessionStatistics;
        }
    };
    SessionManager<Map<String, Object>, Batch> manager = this.factory.createSessionManager(configuration);
    Batcher<Batch> batcher = manager.getBatcher();
    info.addThreadSetupAction(new ThreadSetupHandler() {

        @Override
        public <T, C> Action<T, C> create(Action<T, C> action) {
            return new Action<T, C>() {

                @Override
                public T call(HttpServerExchange exchange, C context) throws Exception {
                    Batch batch = batcher.suspendBatch();
                    try (BatchContext ctx = batcher.resumeBatch(batch)) {
                        return action.call(exchange, context);
                    }
                }
            };
        }
    });
    SessionListeners listeners = this.listeners;
    RecordableSessionManagerStatistics statistics = (inactiveSessionStatistics != null) ? new DistributableSessionManagerStatistics(manager, inactiveSessionStatistics, this.config.getMaxActiveSessions()) : null;
    io.undertow.server.session.SessionManager result = new DistributableSessionManager(new DistributableSessionManagerConfiguration() {

        @Override
        public String getDeploymentName() {
            return info.getDeploymentName();
        }

        @Override
        public SessionManager<Map<String, Object>, Batch> getSessionManager() {
            return manager;
        }

        @Override
        public SessionListeners getSessionListeners() {
            return listeners;
        }

        @Override
        public RecordableSessionManagerStatistics getStatistics() {
            return statistics;
        }

        @Override
        public boolean isOrphanSessionAllowed() {
            // TODO Configure via DeploymentInfo
            return WildFlySecurityManager.doUnchecked(new PrivilegedAction<Boolean>() {

                @Override
                public Boolean run() {
                    return Boolean.getBoolean(ALLOW_ORPHAN_SESSION_PROPERTY);
                }
            });
        }
    });
    result.setDefaultSessionTimeout((int) this.config.getDefaultSessionTimeout().getSeconds());
    return result;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) SessionManagerConfiguration(org.wildfly.clustering.web.session.SessionManagerConfiguration) HttpServerExchange(io.undertow.server.HttpServerExchange) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) PrivilegedAction(java.security.PrivilegedAction) IdentifierFactoryAdapter(org.wildfly.clustering.web.undertow.IdentifierFactoryAdapter) ServletContext(javax.servlet.ServletContext) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SessionManager(org.wildfly.clustering.web.session.SessionManager) BatchContext(org.wildfly.clustering.ee.BatchContext) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Map(java.util.Map)

Aggregations

HttpServerExchange (io.undertow.server.HttpServerExchange)1 SessionListeners (io.undertow.server.session.SessionListeners)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 PrivilegedAction (java.security.PrivilegedAction)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1 Batch (org.wildfly.clustering.ee.Batch)1 BatchContext (org.wildfly.clustering.ee.BatchContext)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)1 SessionManager (org.wildfly.clustering.web.session.SessionManager)1 SessionManagerConfiguration (org.wildfly.clustering.web.session.SessionManagerConfiguration)1 IdentifierFactoryAdapter (org.wildfly.clustering.web.undertow.IdentifierFactoryAdapter)1