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;
}
Aggregations