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