Source:
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().getDistributable() != null)) || (sharedConfig != null)) { 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; 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.getParent().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); builder.setInstance(Service.newInstance(injector, management)).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); } } }

Target:
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().getDistributable() != null)) || (sharedConfig != null)) { 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; 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); } } }