Search in sources :

Example 1 with DistributableSessionManagementProvider

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

the class DistributableWebDeploymentXMLReaderTestCase method testInfinispan.

@Test
public void testInfinispan() throws IOException, XMLStreamException {
    URL url = this.getClass().getResource(String.format("distributable-web-infinispan-%d.%d.xml", this.schema.major(), this.schema.minor()));
    XMLMapper mapper = XMLMapper.Factory.create();
    mapper.registerRootElement(this.schema.getRoot(), new DistributableWebDeploymentXMLReader(this.schema));
    try (InputStream input = url.openStream()) {
        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input);
        MutableDistributableDeploymentConfiguration config = new MutableDistributableDeploymentConfiguration();
        mapper.parseDocument(config, reader);
        Assert.assertNull(config.getSessionManagementName());
        DistributableSessionManagementProvider result = config.getSessionManagement();
        Assert.assertNotNull(result);
        Assert.assertTrue(result instanceof InfinispanSessionManagementProvider);
        InfinispanSessionManagementProvider provider = (InfinispanSessionManagementProvider) result;
        InfinispanSessionManagementConfiguration configuration = provider.getSessionManagementConfiguration();
        Assert.assertEquals("foo", configuration.getContainerName());
        Assert.assertEquals("bar", configuration.getCacheName());
        Assert.assertSame(SessionAttributePersistenceStrategy.FINE, configuration.getAttributePersistenceStrategy());
        if (this.schema.since(DistributableWebDeploymentSchema.VERSION_2_0)) {
            Assert.assertTrue(provider.getRouteLocatorServiceConfiguratorFactory() instanceof RankedRouteLocatorServiceConfiguratorFactory);
            RankedRoutingConfiguration routing = ((RankedRouteLocatorServiceConfiguratorFactory) provider.getRouteLocatorServiceConfiguratorFactory()).getConfiguration();
            Assert.assertEquals(":", routing.getDelimiter());
            Assert.assertEquals(4, routing.getMaxRoutes());
        } else {
            Assert.assertTrue(provider.getRouteLocatorServiceConfiguratorFactory() instanceof NullRouteLocatorServiceConfiguratorFactory);
        }
        Assert.assertNotNull(config.getImmutableClasses());
        Assert.assertEquals(Arrays.asList(Locale.class.getName(), UUID.class.getName()), config.getImmutableClasses());
    } finally {
        mapper.unregisterRootAttribute(this.schema.getRoot());
    }
}
Also used : XMLMapper(org.jboss.staxmapper.XMLMapper) RankedRouteLocatorServiceConfiguratorFactory(org.wildfly.clustering.web.infinispan.routing.RankedRouteLocatorServiceConfiguratorFactory) RankedRoutingConfiguration(org.wildfly.clustering.web.infinispan.routing.RankedRoutingConfiguration) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) InfinispanSessionManagementProvider(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagementProvider) InfinispanSessionManagementConfiguration(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagementConfiguration) URL(java.net.URL) NullRouteLocatorServiceConfiguratorFactory(org.wildfly.clustering.web.cache.routing.NullRouteLocatorServiceConfiguratorFactory) Test(org.junit.Test)

Example 2 with DistributableSessionManagementProvider

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

the class SessionManagementServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceName name = this.getServiceName();
    ServiceBuilder<?> builder = target.addService(name);
    Consumer<DistributableSessionManagementProvider> provider = this.factory.register(builder).provides(name);
    Service service = new FunctionalService<>(provider, Function.identity(), this);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) ServiceName(org.jboss.msc.service.ServiceName) DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service)

Example 3 with DistributableSessionManagementProvider

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

the class UndertowSessionManagementProviderFactory method createSessionManagementProvider.

@Override
public SessionManagementProvider createSessionManagementProvider(DeploymentUnit unit, ReplicationConfig config) {
    DistributableSessionManagementProvider provider = unit.getAttachment(DistributableSessionManagementProvider.ATTACHMENT_KEY);
    // For compatibility, honor legacy <replication-config/> over an attached provider
    if ((config != null) || (provider == null)) {
        if (provider != null) {
            UndertowClusteringLogger.ROOT_LOGGER.legacySessionManagementProviderOverride(unit.getName());
        } else {
            UndertowClusteringLogger.ROOT_LOGGER.legacySessionManagementProviderInUse(unit.getName());
        }
        // Fabricate DistributableSessionManagementProvider from legacy ReplicationConfig
        provider = this.legacyFactory.createSessionManagerProvider(config);
    }
    Module module = unit.getAttachment(Attachments.MODULE);
    List<String> immutableClasses = unit.getAttachmentList(DistributableSessionManagementProvider.IMMUTABILITY_ATTACHMENT_KEY);
    return new UndertowDistributableSessionManagementProvider(provider, new SimpleImmutability(module.getClassLoader(), immutableClasses));
}
Also used : SimpleImmutability(org.wildfly.clustering.ee.immutable.SimpleImmutability) DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) Module(org.jboss.modules.Module)

Example 4 with DistributableSessionManagementProvider

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

the class DistributableWebDeploymentDependencyProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = context.getDeploymentUnit();
    WarMetaData warMetaData = unit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    SharedSessionManagerConfig sharedConfig = unit.getAttachment(SharedSessionManagerConfig.ATTACHMENT_KEY);
    if (((warMetaData != null) && (warMetaData.getMergedJBossWebMetaData() != null && warMetaData.getMergedJBossWebMetaData().getDistributable() != null)) || ((sharedConfig != null) && sharedConfig.isDistributable())) {
        CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        DistributableWebDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY);
        String name = (config != null) ? config.getSessionManagementName() : null;
        DistributableSessionManagementProvider management = (name == null) && (config != null) ? config.getSessionManagement() : null;
        List<String> immutableClasses = (config != null) ? config.getImmutableClasses() : Collections.emptyList();
        for (String immutableClass : immutableClasses) {
            unit.addToAttachmentList(DistributableSessionManagementProvider.IMMUTABILITY_ATTACHMENT_KEY, immutableClass);
        }
        if (management != null) {
            LOGGER.debugf("%s will use a deployment-specific distributable session management provider", unit.getName());
            ServiceTarget target = context.getServiceTarget();
            DeploymentUnit parentUnit = unit.getParent();
            String deploymentName = (parentUnit != null) ? parentUnit.getName() + "." + unit.getName() : unit.getName();
            ServiceName serviceName = WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, deploymentName);
            ServiceBuilder<?> builder = target.addService(serviceName);
            Consumer<DistributableSessionManagementProvider> injector = builder.provides(serviceName);
            Service service = Service.newInstance(injector, management);
            builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
            context.addDependency(serviceName, DistributableSessionManagementProvider.ATTACHMENT_KEY);
        } else {
            if (name != null) {
                LOGGER.debugf("%s will use the '%s' distributable session management provider", unit.getName(), name);
            } else {
                LOGGER.debugf("%s will use the default distributable session management provider", unit.getName());
            }
            context.addDependency(WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, name), DistributableSessionManagementProvider.ATTACHMENT_KEY);
        }
    }
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) WarMetaData(org.jboss.as.web.common.WarMetaData) DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) Service(org.jboss.msc.Service) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) SharedSessionManagerConfig(org.jboss.as.web.session.SharedSessionManagerConfig) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 5 with DistributableSessionManagementProvider

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

the class DistributableWebDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = context.getDeploymentUnit();
    DistributableSessionManagementProvider provider = context.getAttachment(DistributableSessionManagementProvider.ATTACHMENT_KEY);
    if (provider != null) {
        unit.putAttachment(DistributableSessionManagementProvider.ATTACHMENT_KEY, provider);
    }
}
Also used : DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

DistributableSessionManagementProvider (org.wildfly.clustering.web.session.DistributableSessionManagementProvider)6 InputStream (java.io.InputStream)2 URL (java.net.URL)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Service (org.jboss.msc.Service)2 ServiceName (org.jboss.msc.service.ServiceName)2 XMLMapper (org.jboss.staxmapper.XMLMapper)2 Test (org.junit.Test)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 WarMetaData (org.jboss.as.web.common.WarMetaData)1 SharedSessionManagerConfig (org.jboss.as.web.session.SharedSessionManagerConfig)1 Module (org.jboss.modules.Module)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 SimpleImmutability (org.wildfly.clustering.ee.immutable.SimpleImmutability)1 FunctionalService (org.wildfly.clustering.service.FunctionalService)1 NullRouteLocatorServiceConfiguratorFactory (org.wildfly.clustering.web.cache.routing.NullRouteLocatorServiceConfiguratorFactory)1 HotRodSessionManagementConfiguration (org.wildfly.clustering.web.hotrod.session.HotRodSessionManagementConfiguration)1 HotRodSessionManagementProvider (org.wildfly.clustering.web.hotrod.session.HotRodSessionManagementProvider)1 RankedRouteLocatorServiceConfiguratorFactory (org.wildfly.clustering.web.infinispan.routing.RankedRouteLocatorServiceConfiguratorFactory)1