Search in sources :

Example 1 with DistributableSessionManagerFactoryBuilder

use of org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder in project wildfly by wildfly.

the class SharedSessionManagerDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    SharedSessionManagerConfig sharedConfig = deploymentUnit.getAttachment(UndertowAttachments.SHARED_SESSION_MANAGER_CONFIG);
    if (sharedConfig == null) {
        return;
    }
    ServiceTarget target = phaseContext.getServiceTarget();
    ServiceName deploymentServiceName = deploymentUnit.getServiceName();
    ServiceName managerServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME);
    DistributableSessionManagerFactoryBuilder builder = new DistributableSessionManagerFactoryBuilderValue().getValue();
    if (builder != null) {
        CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        builder.build(support, target, managerServiceName, new SimpleDistributableSessionManagerConfiguration(sharedConfig, deploymentUnit.getName(), module)).setInitialMode(Mode.ON_DEMAND).install();
    } else {
        InMemorySessionManager manager = new InMemorySessionManager(deploymentUnit.getName(), sharedConfig.getMaxActiveSessions());
        if (sharedConfig.getSessionConfig() != null) {
            if (sharedConfig.getSessionConfig().getSessionTimeoutSet()) {
                manager.setDefaultSessionTimeout(sharedConfig.getSessionConfig().getSessionTimeout());
            }
        }
        SessionManagerFactory factory = new ImmediateSessionManagerFactory(manager);
        target.addService(managerServiceName, new ValueService<>(new ImmediateValue<>(factory))).setInitialMode(Mode.ON_DEMAND).install();
    }
    ServiceName codecServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME);
    DistributableSessionIdentifierCodecBuilder sessionIdentifierCodecBuilder = new DistributableSessionIdentifierCodecBuilderValue().getValue();
    if (sessionIdentifierCodecBuilder != null) {
        sessionIdentifierCodecBuilder.build(target, codecServiceName, deploymentUnit.getName()).setInitialMode(Mode.ON_DEMAND).install();
    } else {
        // Fallback to simple codec if server does not support clustering
        SimpleSessionIdentifierCodecService.build(target, codecServiceName).setInitialMode(Mode.ON_DEMAND).install();
    }
}
Also used : DistributableSessionIdentifierCodecBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilderValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) DistributableSessionManagerFactoryBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilderValue) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ImmediateValue(org.jboss.msc.value.ImmediateValue) DistributableSessionIdentifierCodecBuilder(org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilder) SharedSessionManagerConfig(org.wildfly.extension.undertow.session.SharedSessionManagerConfig) SimpleDistributableSessionManagerConfiguration(org.wildfly.extension.undertow.session.SimpleDistributableSessionManagerConfiguration) DistributableSessionManagerFactoryBuilder(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder) ServiceName(org.jboss.msc.service.ServiceName) SessionManagerFactory(io.undertow.servlet.api.SessionManagerFactory) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InMemorySessionManager(io.undertow.server.session.InMemorySessionManager)

Example 2 with DistributableSessionManagerFactoryBuilder

use of org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder in project wildfly by wildfly.

the class UndertowDeploymentProcessor method installSessionManagerFactory.

private static ServiceName installSessionManagerFactory(CapabilityServiceSupport support, ServiceTarget target, ServiceName deploymentServiceName, String deploymentName, Module module, JBossWebMetaData metaData, ServletContainerService servletContainerService) {
    Integer maxActiveSessions = metaData.getMaxActiveSessions();
    if (maxActiveSessions == null && servletContainerService != null) {
        maxActiveSessions = servletContainerService.getMaxSessions();
    }
    ServiceName name = deploymentServiceName.append("session");
    if (metaData.getDistributable() != null) {
        DistributableSessionManagerFactoryBuilder sessionManagerFactoryBuilder = new DistributableSessionManagerFactoryBuilderValue().getValue();
        if (sessionManagerFactoryBuilder != null) {
            sessionManagerFactoryBuilder.build(support, target, name, new SimpleDistributableSessionManagerConfiguration(maxActiveSessions, metaData.getReplicationConfig(), deploymentName, module)).setInitialMode(Mode.ON_DEMAND).install();
            return name;
        }
        // Fallback to local session manager if server does not support clustering
        UndertowLogger.ROOT_LOGGER.clusteringNotSupported();
    }
    InMemorySessionManagerFactory factory = (maxActiveSessions != null) ? new InMemorySessionManagerFactory(maxActiveSessions) : new InMemorySessionManagerFactory();
    target.addService(name, new ValueService<>(new ImmediateValue<>(factory))).setInitialMode(Mode.ON_DEMAND).install();
    return name;
}
Also used : SimpleDistributableSessionManagerConfiguration(org.wildfly.extension.undertow.session.SimpleDistributableSessionManagerConfiguration) DistributableSessionManagerFactoryBuilder(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder) ServiceName(org.jboss.msc.service.ServiceName) InMemorySessionManagerFactory(io.undertow.servlet.core.InMemorySessionManagerFactory) DistributableSessionManagerFactoryBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilderValue) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

ServiceName (org.jboss.msc.service.ServiceName)2 ImmediateValue (org.jboss.msc.value.ImmediateValue)2 DistributableSessionManagerFactoryBuilder (org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder)2 DistributableSessionManagerFactoryBuilderValue (org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilderValue)2 SimpleDistributableSessionManagerConfiguration (org.wildfly.extension.undertow.session.SimpleDistributableSessionManagerConfiguration)2 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)1 SessionManagerFactory (io.undertow.servlet.api.SessionManagerFactory)1 InMemorySessionManagerFactory (io.undertow.servlet.core.InMemorySessionManagerFactory)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 Module (org.jboss.modules.Module)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 DistributableSessionIdentifierCodecBuilder (org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilder)1 DistributableSessionIdentifierCodecBuilderValue (org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilderValue)1 SharedSessionManagerConfig (org.wildfly.extension.undertow.session.SharedSessionManagerConfig)1