/** @author <a href="mailto:[email protected]">David M. Lloyd</a> */ public final class LogServices { public static final ServiceName JBOSS_LOGGING = ServiceName.JBOSS.append("logging"); public static final ServiceName LOGGER = JBOSS_LOGGING.append("logger"); public static final ServiceName ROOT_LOGGER = JBOSS_LOGGING.append("root-logger"); public static final ServiceName LOGGER_HANDLER = JBOSS_LOGGING.append("logger-handler"); public static final ServiceName ROOT_LOGGER_HANDLER = JBOSS_LOGGING.append("root-logger-handler"); public static final ServiceName HANDLER = JBOSS_LOGGING.append("handler"); private LogServices() {} public static ServiceName loggerName(final String name) { return "".equals(name) ? ROOT_LOGGER : LOGGER.append(name); } public static ServiceName loggerHandlerName(final String loggerName, final String handlerName) { return loggerName.length() == 0 ? ROOT_LOGGER_HANDLER.append(handlerName) : LOGGER_HANDLER.append(loggerName, handlerName); } public static ServiceName handlerName(final String name) { return HANDLER.append(name); } }
/** * Get the service name of a context, or {@code null} if there is no service mapping for the * context name. * * @param app the application name * @param module the module name * @param comp the component name * @param context the context to check * @return the service name or {@code null} if there is no service */ public static ServiceName serviceNameOfContext( String app, String module, String comp, String context) { if (context.startsWith("java:")) { final String namespace; final int i = context.indexOf('/'); if (i == -1) { namespace = context.substring(5); } else { namespace = context.substring(5, i); } if (namespace.equals("global")) { return GLOBAL_CONTEXT_SERVICE_NAME.append(context.substring(12)); } else if (namespace.equals("jboss")) { return JBOSS_CONTEXT_SERVICE_NAME.append(context.substring(11)); } else if (namespace.equals("app")) { return contextServiceNameOfApplication(app).append(context.substring(9)); } else if (namespace.equals("module")) { return contextServiceNameOfModule(app, module).append(context.substring(12)); } else if (namespace.equals("comp")) { return contextServiceNameOfComponent(app, module, comp).append(context.substring(10)); } else { return JAVA_CONTEXT_SERVICE_NAME.append(context); } } else { return null; } }
/** * Add a ContextService for this module. * * @param phaseContext the deployment unit context * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (isEarDeployment(deploymentUnit)) { return; } final ServiceTarget serviceTarget = phaseContext.getServiceTarget(); final ServiceName moduleContextServiceName = ContextServiceNameBuilder.module(deploymentUnit); final RootContextService contextService = new RootContextService(); serviceTarget.addService(moduleContextServiceName, contextService).install(); final BinderService<String> moduleNameBinder = new BinderService<String>( "ModuleName", Values.immediateValue(getModuleName(deploymentUnit))); serviceTarget .addService(moduleContextServiceName.append("ModuleName"), moduleNameBinder) .addDependency( moduleContextServiceName, Context.class, moduleNameBinder.getContextInjector()) .install(); final ContextService envContextService = new ContextService("env"); serviceTarget .addService(moduleContextServiceName.append("env"), envContextService) .addDependency( moduleContextServiceName, Context.class, envContextService.getParentContextInjector()) .install(); phaseContext .getDeploymentUnit() .putAttachment( Attachments.MODULE_CONTEXT_CONFIG, new NamingContextConfig(moduleContextServiceName)); }
/** * Check the deployment annotation index for all classes with the @ManagedBean annotation. For * each class with the annotation, collect all the required information to create a managed bean * instance, and attach it to the context. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final String applicationName = moduleDescription.getAppName(); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; } final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; } for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw new DeploymentUnitProcessingException( "The ManagedBean annotation is only allowed at the class level: " + target); } final ClassInfo classInfo = (ClassInfo) target; final String beanClassName = classInfo.name().toString(); // Get the managed bean name from the annotation final AnnotationValue nameValue = instance.value(); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString(); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription( beanName, beanClassName, moduleDescription.getModuleName(), applicationName); final ServiceName baseName = deploymentUnit.getServiceName().append("component").append(beanName); // Add the view componentDescription.getViewClassNames().add(beanClassName); // Bind the view to its two JNDI locations // TODO - this should be a bit more elegant final BindingDescription moduleBinding = new BindingDescription(); moduleBinding.setAbsoluteBinding(true); moduleBinding.setBindingName("java:module/" + beanName); moduleBinding.setBindingType(beanClassName); moduleBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(moduleBinding); final BindingDescription appBinding = new BindingDescription(); appBinding.setAbsoluteBinding(true); appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName); appBinding.setBindingType(beanClassName); appBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(appBinding); moduleDescription.addComponent(componentDescription); } }
/** @author Emanuel Muckenhuber */ public final class PlayServices { /** The service name of the play framework configuration. */ public static final ServiceName PLAY = ServiceName.JBOSS.append("play"); public static final ServiceName PLAY_DEPLOYMENT = PLAY.append("deployment"); /** internal name for the framework path service name. */ static final ServiceName PLAY_PATH = PLAY.append("path"); }
private static ServiceName getCacheServiceName(String cacheName) { ServiceName baseServiceName = CacheContainerServiceName.CACHE_CONTAINER .getServiceName(DEFAULT_CACHE_CONTAINER) .getParent(); ServiceName serviceName = ServiceName.parse((cacheName != null) ? cacheName : DEFAULT_CACHE_CONTAINER); if (!baseServiceName.isParentOf(serviceName)) { serviceName = baseServiceName.append(serviceName); } return (serviceName.length() < 4) ? serviceName.append(SubGroupServiceNameFactory.DEFAULT_SUB_GROUP) : serviceName; }
private static ServiceName installSessionManagerFactory( ServiceTarget target, ServiceName deploymentServiceName, String deploymentName, Module module, JBossWebMetaData metaData) { ServiceName name = deploymentServiceName.append("session"); if (metaData.getDistributable() != null) { DistributableSessionManagerFactoryBuilder sessionManagerFactoryBuilder = new DistributableSessionManagerFactoryBuilderValue().getValue(); if (sessionManagerFactoryBuilder != null) { sessionManagerFactoryBuilder .build( target, name, new SimpleDistributableSessionManagerConfiguration( metaData, deploymentName, module)) .setInitialMode(Mode.ON_DEMAND) .install(); return name; } // Fallback to local session manager if server does not support clustering UndertowLogger.ROOT_LOGGER.clusteringNotSupported(); } Integer maxActiveSessions = metaData.getMaxActiveSessions(); InMemorySessionManagerFactory factory = (maxActiveSessions != null) ? new InMemorySessionManagerFactory(maxActiveSessions.intValue()) : new InMemorySessionManagerFactory(); target .addService(name, new ValueService<>(new ImmediateValue<>(factory))) .setInitialMode(Mode.ON_DEMAND) .install(); return name; }
@Override public void deploy(DeploymentPhaseContext context) { DeploymentUnit unit = context.getDeploymentUnit(); final ServiceName name = unit.getServiceName(); EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (moduleDescription == null) { return; } final ServiceTarget target = context.getServiceTarget(); @SuppressWarnings("rawtypes") final InjectedValue<CacheFactoryBuilderRegistry> registry = new InjectedValue<>(); Service<Void> service = new AbstractService<Void>() { @Override public void start(StartContext context) { // Install dependencies for each registered cache factory builder Collection<CacheFactoryBuilder<?, ?>> builders = registry.getValue().getBuilders(); for (CacheFactoryBuilder<?, ?> builder : builders) { builder.installDeploymentUnitDependencies(target, name); } } }; target .addService(name.append("cache-dependencies-installer"), service) .addDependency( CacheFactoryBuilderRegistryService.SERVICE_NAME, CacheFactoryBuilderRegistry.class, registry) .install(); // Install versioned marshalling configuration InjectedValue<ModuleDeployment> deployment = new InjectedValue<>(); Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); Value<ModuleLoader> moduleLoader = new ImmediateValue<>(module.getModuleLoader()); target .addService( VersionedMarshallingConfigurationService.getServiceName(name), new VersionedMarshallingConfigurationService(deployment, moduleLoader)) .addDependency( name.append(ModuleDeployment.SERVICE_NAME), ModuleDeployment.class, deployment) .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); }
private ServiceName buildServiceName(final Name name) { final Enumeration<String> parts = name.getAll(); ServiceName current = serviceNameBase; while (parts.hasMoreElements()) { final String currentPart = parts.nextElement(); if (!currentPart.isEmpty()) { current = current.append(currentPart); } } return current; }
@Override public ServiceName getServiceName(Deployment dep, int state) { // Currently the bundleId is needed for uniqueness because of // [MSC-97] Cannot re-install service with same name Long bundleId = dep.getAttachment(Long.class); ServiceName serviceName = ServiceName.of( BUNDLE_BASE_NAME, "" + bundleId, "" + dep.getSymbolicName(), "" + dep.getVersion()); if (state == Bundle.INSTALLED || state == Bundle.RESOLVED || state == Bundle.ACTIVE) { serviceName = serviceName.append(ConstantsHelper.bundleState(state)); } return serviceName; }
private void bindServices( DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) { final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName"); final BinderService instanceNameService = new BinderService("InstanceName"); serviceTarget .addService(instanceNameServiceName, instanceNameService) .addDependency( contextServiceName, ServiceBasedNamingStore.class, instanceNameService.getNamingStoreInjector()) .addDependency( ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, new Injector<ServerEnvironment>() { @Override public void inject(final ServerEnvironment serverEnvironment) throws InjectionException { instanceNameService .getManagedObjectInjector() .inject( new ManagedReferenceFactory() { @Override public ManagedReference getReference() { return new ManagedReference() { @Override public void release() {} @Override public Object getInstance() { final String nodeName = serverEnvironment.getNodeName(); return nodeName == null ? "" : nodeName; } }; } }); } @Override public void uninject() { instanceNameService.getManagedObjectInjector().uninject(); } }) .install(); deploymentUnit.addToAttachmentList( org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName); }
private void bindBeanManager( ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName, final Collection<ServiceName> dependencies, final ServiceRegistry serviceRegistry) { final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager"); dependencies.add(beanManagerBindingServiceName); BinderService beanManagerBindingService = new BinderService("BeanManager"); final BeanManagerManagedReferenceFactory referenceFactory = new BeanManagerManagedReferenceFactory(); serviceTarget .addService(beanManagerBindingServiceName, beanManagerBindingService) .addInjection(beanManagerBindingService.getManagedObjectInjector(), referenceFactory) .addDependency( contextServiceName, ServiceBasedNamingStore.class, beanManagerBindingService.getNamingStoreInjector()) .addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager) .install(); }
public class ServicesServices { private ServicesServices() {} public static final ServiceName TORQUEBOX = ServiceName.of("torquebox"); public static final ServiceName SERVICES = TORQUEBOX.append("services"); public static ServiceName serviceComponentResolver(DeploymentUnit unit, String serviceName) { return unit.getServiceName().append("component_resolver").append(serviceName); } public static ServiceName serviceCreateRubyService(DeploymentUnit unit, String serviceName) { return unit.getServiceName().append("service").append(serviceName).append("create"); } public static ServiceName serviceStartRubyService(DeploymentUnit unit, String serviceName) { return unit.getServiceName().append("service").append(serviceName); } public static ServiceName serviceInjectableService(DeploymentUnit unit, String serviceName) { return serviceStartRubyService(unit, serviceName).append("injectable"); } }
private static ServiceName installSessionIdentifierCodec( ServiceTarget target, ServiceName deploymentServiceName, String deploymentName, JBossWebMetaData metaData) { ServiceName name = deploymentServiceName.append("codec"); if (metaData.getDistributable() != null) { DistributableSessionIdentifierCodecBuilder sessionIdentifierCodecBuilder = new DistributableSessionIdentifierCodecBuilderValue().getValue(); if (sessionIdentifierCodecBuilder != null) { sessionIdentifierCodecBuilder .build(target, name, deploymentName) .setInitialMode(Mode.ON_DEMAND) .install(); return name; } // Fallback to simple codec if server does not support clustering } SimpleSessionIdentifierCodecService.build(target, name) .setInitialMode(Mode.ON_DEMAND) .install(); return name; }
/** @author <a href="mailto:[email protected]">David M. Lloyd</a> */ public final class LogServices { public static final ServiceName JBOSS_LOGGING = ServiceName.JBOSS.append("logging"); public static final ServiceName LOGGER = JBOSS_LOGGING.append("logger"); public static final ServiceName ROOT_LOGGER = JBOSS_LOGGING.append("root-logger", CommonAttributes.ROOT_LOGGER_NAME); public static final ServiceName LOGGER_HANDLER = JBOSS_LOGGING.append("logger-handler"); public static final ServiceName ROOT_LOGGER_HANDLER = JBOSS_LOGGING.append("root-logger-handler"); public static final ServiceName HANDLER = JBOSS_LOGGING.append("handler"); public static final ServiceName HANDLER_FILE = JBOSS_LOGGING.append("handler-file"); private LogServices() {} public static ServiceName loggerName(final String name) { return CommonAttributes.ROOT_LOGGER_NAME.equals(name) ? ROOT_LOGGER : LOGGER.append(name); } public static ServiceName loggerHandlerName(final String loggerName, final String handlerName) { return CommonAttributes.ROOT_LOGGER_NAME.equals(loggerName) ? ROOT_LOGGER_HANDLER.append(CommonAttributes.ROOT_LOGGER_NAME, handlerName) : LOGGER_HANDLER.append(loggerName, handlerName); } public static ServiceName handlerName(final String name) { return HANDLER.append(name); } public static ServiceName handlerFileName(final String handlerName) { return HANDLER_FILE.append(handlerName); } }
private void processDeployment( final WarMetaData warMetaData, final DeploymentUnit deploymentUnit, final ServiceTarget serviceTarget, String hostName) throws DeploymentUnitProcessingException { ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot(); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); if (module == null) { throw new DeploymentUnitProcessingException( UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit)); } final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData(); final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS); metaData.resolveRunAs(); ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY); final Set<ServiceName> dependentComponents = new HashSet<>(); // see AS7-2077 // basically we want to ignore components that have failed for whatever reason // if they are important they will be picked up when the web deployment actually starts final List<ServiceName> components = deploymentUnit.getAttachmentList(WebComponentDescription.WEB_COMPONENTS); final Set<ServiceName> failed = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.FAILED_COMPONENTS); for (final ServiceName component : components) { if (!failed.contains(component)) { dependentComponents.add(component); } } boolean componentRegistryExists = true; ComponentRegistry componentRegistry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.COMPONENT_REGISTRY); if (componentRegistry == null) { componentRegistryExists = false; // we do this to avoid lots of other null checks // this will only happen if the EE subsystem is not installed componentRegistry = new ComponentRegistry(null); } final WebInjectionContainer injectionContainer = new WebInjectionContainer(module.getClassLoader(), componentRegistry); String jaccContextId = metaData.getJaccContextID(); if (jaccContextId == null) { jaccContextId = deploymentUnit.getName(); } if (deploymentUnit.getParent() != null) { jaccContextId = deploymentUnit.getParent().getName() + "!" + jaccContextId; } String deploymentName; if (deploymentUnit.getParent() == null) { deploymentName = deploymentUnit.getName(); } else { deploymentName = deploymentUnit.getParent().getName() + "." + deploymentUnit.getName(); } final String pathName = pathNameOfDeployment(deploymentUnit, metaData); boolean securityEnabled = deploymentUnit.hasAttachment(SecurityAttachments.SECURITY_ENABLED); String metaDataSecurityDomain = metaData.getSecurityDomain(); if (metaDataSecurityDomain == null) { metaDataSecurityDomain = getJBossAppSecurityDomain(deploymentUnit); } if (metaDataSecurityDomain != null) { metaDataSecurityDomain = metaDataSecurityDomain.trim(); } final String securityDomain; if (securityEnabled) { securityDomain = metaDataSecurityDomain == null ? SecurityConstants.DEFAULT_APPLICATION_POLICY : SecurityUtil.unprefixSecurityDomain(metaDataSecurityDomain); } else { securityDomain = null; } String serverInstanceName = metaData.getServerInstanceName() == null ? defaultServer : metaData.getServerInstanceName(); final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName); final Set<ServiceName> additionalDependencies = new HashSet<>(); for (final SetupAction setupAction : setupActions) { Set<ServiceName> dependencies = setupAction.dependencies(); if (dependencies != null) { additionalDependencies.addAll(dependencies); } } SharedSessionManagerConfig sharedSessionManagerConfig = deploymentUnit.getParent() != null ? deploymentUnit .getParent() .getAttachment(UndertowAttachments.SHARED_SESSION_MANAGER_CONFIG) : null; if (!deploymentResourceRoot.isUsePhysicalCodeSource()) { try { deploymentUnit.addToAttachmentList( ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute( Constants.CODE_SOURCE_ATTRIBUTE_NAME, deploymentRoot.toURL())); } catch (MalformedURLException e) { throw new DeploymentUnitProcessingException(e); } } deploymentUnit.addToAttachmentList( ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute( Constants.PERMISSION_COLLECTION_ATTRIBUTE_NAME, deploymentUnit.getAttachment(Attachments.MODULE_PERMISSIONS))); additionalDependencies.addAll(warMetaData.getAdditionalDependencies()); final ServiceName hostServiceName = UndertowService.virtualHostName(serverInstanceName, hostName); TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY); UndertowDeploymentInfoService undertowDeploymentInfoService = UndertowDeploymentInfoService.builder() .setAttributes(deploymentUnit.getAttachmentList(ServletContextAttribute.ATTACHMENT_KEY)) .setTopLevelDeploymentName( deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName()) .setContextPath(pathName) .setDeploymentName( deploymentName) // todo: is this deployment name concept really applicable? .setDeploymentRoot(deploymentRoot) .setMergedMetaData(warMetaData.getMergedJBossWebMetaData()) .setModule(module) .setScisMetaData(scisMetaData) .setJaccContextId(jaccContextId) .setSecurityDomain(securityDomain) .setSharedTlds( tldsMetaData == null ? Collections.<TldMetaData>emptyList() : tldsMetaData.getSharedTlds(deploymentUnit)) .setTldsMetaData(tldsMetaData) .setSetupActions(setupActions) .setSharedSessionManagerConfig(sharedSessionManagerConfig) .setOverlays(warMetaData.getOverlays()) .setExpressionFactoryWrappers( deploymentUnit.getAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY)) .setPredicatedHandlers( deploymentUnit.getAttachment( UndertowHandlersDeploymentProcessor.PREDICATED_HANDLERS)) .setInitialHandlerChainWrappers( deploymentUnit.getAttachmentList( UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS)) .setInnerHandlerChainWrappers( deploymentUnit.getAttachmentList( UndertowAttachments.UNDERTOW_INNER_HANDLER_CHAIN_WRAPPERS)) .setOuterHandlerChainWrappers( deploymentUnit.getAttachmentList( UndertowAttachments.UNDERTOW_OUTER_HANDLER_CHAIN_WRAPPERS)) .setThreadSetupActions( deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_THREAD_SETUP_ACTIONS)) .setServletExtensions( deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_SERVLET_EXTENSIONS)) .setExplodedDeployment(ExplodedDeploymentMarker.isExplodedDeployment(deploymentUnit)) .setWebSocketDeploymentInfo( deploymentUnit.getAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO)) .setTempDir(warMetaData.getTempDir()) .setExternalResources( deploymentUnit.getAttachmentList(UndertowAttachments.EXTERNAL_RESOURCES)) .createUndertowDeploymentInfoService(); final ServiceName deploymentInfoServiceName = deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME); ServiceBuilder<DeploymentInfo> infoBuilder = serviceTarget .addService(deploymentInfoServiceName, undertowDeploymentInfoService) .addDependency( UndertowService.SERVLET_CONTAINER.append(defaultContainer), ServletContainerService.class, undertowDeploymentInfoService.getContainer()) .addDependency( UndertowService.UNDERTOW, UndertowService.class, undertowDeploymentInfoService.getUndertowService()) .addDependencies(deploymentUnit.getAttachmentList(Attachments.WEB_DEPENDENCIES)) .addDependency(hostServiceName, Host.class, undertowDeploymentInfoService.getHost()) .addDependency( SuspendController.SERVICE_NAME, SuspendController.class, undertowDeploymentInfoService.getSuspendControllerInjectedValue()) .addDependencies(additionalDependencies); if (securityDomain != null) { infoBuilder.addDependency( SecurityDomainService.SERVICE_NAME.append(securityDomain), SecurityDomainContext.class, undertowDeploymentInfoService.getSecurityDomainContextValue()); } if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) { String topLevelName; if (deploymentUnit.getParent() == null) { topLevelName = deploymentUnit.getName(); } else { topLevelName = deploymentUnit.getParent().getName(); } infoBuilder.addDependency( ControlPointService.serviceName(topLevelName, UndertowExtension.SUBSYSTEM_NAME), ControlPoint.class, undertowDeploymentInfoService.getControlPointInjectedValue()); } final Set<String> seenExecutors = new HashSet<String>(); if (metaData.getExecutorName() != null) { final InjectedValue<Executor> executor = new InjectedValue<Executor>(); infoBuilder.addDependency( IOServices.WORKER.append(metaData.getExecutorName()), Executor.class, executor); undertowDeploymentInfoService.addInjectedExecutor(metaData.getExecutorName(), executor); seenExecutors.add(metaData.getExecutorName()); } if (metaData.getServlets() != null) { for (JBossServletMetaData servlet : metaData.getServlets()) { if (servlet.getExecutorName() != null && !seenExecutors.contains(servlet.getExecutorName())) { final InjectedValue<Executor> executor = new InjectedValue<Executor>(); infoBuilder.addDependency( IOServices.WORKER.append(servlet.getExecutorName()), Executor.class, executor); undertowDeploymentInfoService.addInjectedExecutor(servlet.getExecutorName(), executor); seenExecutors.add(servlet.getExecutorName()); } } } if (componentRegistryExists) { infoBuilder.addDependency( ComponentRegistry.serviceName(deploymentUnit), ComponentRegistry.class, undertowDeploymentInfoService.getComponentRegistryInjectedValue()); } else { undertowDeploymentInfoService .getComponentRegistryInjectedValue() .setValue(new ImmediateValue<>(componentRegistry)); } if (sharedSessionManagerConfig != null) { infoBuilder.addDependency( deploymentUnit .getParent() .getServiceName() .append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME), SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector()); infoBuilder.addDependency( deploymentUnit .getParent() .getServiceName() .append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME), SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector()); } else { ServiceName sessionManagerFactoryServiceName = installSessionManagerFactory( serviceTarget, deploymentServiceName, deploymentName, module, metaData); infoBuilder.addDependency( sessionManagerFactoryServiceName, SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector()); ServiceName sessionIdentifierCodecServiceName = installSessionIdentifierCodec( serviceTarget, deploymentServiceName, deploymentName, metaData); infoBuilder.addDependency( sessionIdentifierCodecServiceName, SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector()); } infoBuilder.install(); final boolean isWebappBundle = deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST); final UndertowDeploymentService service = new UndertowDeploymentService(injectionContainer, !isWebappBundle); final ServiceBuilder<UndertowDeploymentService> builder = serviceTarget .addService(deploymentServiceName, service) .addDependencies(dependentComponents) .addDependency( UndertowService.SERVLET_CONTAINER.append(defaultContainer), ServletContainerService.class, service.getContainer()) .addDependency(hostServiceName, Host.class, service.getHost()) .addDependencies(deploymentUnit.getAttachmentList(Attachments.WEB_DEPENDENCIES)) .addDependency( deploymentInfoServiceName, DeploymentInfo.class, service.getDeploymentInfoInjectedValue()); // inject the server executor which can be used by the WebDeploymentService for blocking tasks // in start/stop // of that service Services.addServerExecutorDependency(builder, service.getServerExecutorInjector(), false); deploymentUnit.addToAttachmentList( Attachments.DEPLOYMENT_COMPLETE_SERVICES, deploymentServiceName); // adding JACC service if (securityEnabled) { AbstractSecurityDeployer<WarMetaData> deployer = new WarJACCDeployer(); JaccService<WarMetaData> jaccService = deployer.deploy(deploymentUnit, jaccContextId); if (jaccService != null) { final ServiceName jaccServiceName = deploymentUnit.getServiceName().append(JaccService.SERVICE_NAME); ServiceBuilder<?> jaccBuilder = serviceTarget.addService(jaccServiceName, jaccService); if (deploymentUnit.getParent() != null) { // add dependency to parent policy final DeploymentUnit parentDU = deploymentUnit.getParent(); jaccBuilder.addDependency( parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class, jaccService.getParentPolicyInjector()); } // add dependency to web deployment service jaccBuilder.addDependency(deploymentServiceName); jaccBuilder.setInitialMode(Mode.PASSIVE).install(); } } // OSGi web applications are activated in {@link WebContextActivationProcessor} according to // bundle lifecycle changes if (isWebappBundle) { UndertowDeploymentService.ContextActivatorImpl activator = new UndertowDeploymentService.ContextActivatorImpl(builder.install()); deploymentUnit.putAttachment(ContextActivator.ATTACHMENT_KEY, activator); deploymentUnit.addToAttachmentList( Attachments.BUNDLE_ACTIVE_DEPENDENCIES, deploymentServiceName); } else { builder.install(); } // Process the web related mgmt information final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT); final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME); node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).set("".equals(pathName) ? "/" : pathName); node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).set(hostName); node.get(DeploymentDefinition.SERVER.getName()).set(serverInstanceName); processManagement(deploymentUnit, metaData); }
public static ServiceName handlerFileName(final String handlerName) { return HANDLER_FILE.append(handlerName); }
public static ServiceName handlerName(final String name) { return HANDLER.append(name); }
public static ServiceName loggerHandlerName(final String loggerName, final String handlerName) { return CommonAttributes.ROOT_LOGGER_NAME.equals(loggerName) ? ROOT_LOGGER_HANDLER.append(CommonAttributes.ROOT_LOGGER_NAME, handlerName) : LOGGER_HANDLER.append(loggerName, handlerName); }
public static ServiceName loggerName(final String name) { return CommonAttributes.ROOT_LOGGER_NAME.equals(name) ? ROOT_LOGGER : LOGGER.append(name); }
private static ServiceName newServiceName(final String name) { if (name == null) { throw SarLogger.ROOT_LOGGER.nullVar("name"); } return MBEAN_SERVICE_NAME_BASE.append(name); }
/** * Get the base service name of an application's JNDI namespace. * * @param app the application name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfApplication(String app) { return APPLICATION_CONTEXT_SERVICE_NAME.append(app); }
public static ServiceName getServiceName(String contextName) { ServiceName deploymentServiceName = Services.deploymentUnitName(contextName); return SERVICE_NAME_BASE.append(deploymentServiceName.getSimpleName()); }
public static ServiceName getServiceName(String id) { return SERVICE_NAME.append((id != null) ? id : DEFAULT); }
/** @author John Bailey */ public class ContextNames { /** Parent ServiceName for all naming services. */ public static final ServiceName NAMING = ServiceName.JBOSS.append("naming"); /** ServiceName for java: namespace */ public static final ServiceName JAVA_CONTEXT_SERVICE_NAME = NAMING.append("context", "java"); /** Parent ServiceName for java:comp namespace */ public static final ServiceName COMPONENT_CONTEXT_SERVICE_NAME = JAVA_CONTEXT_SERVICE_NAME.append("comp"); /** Jndi name for java: namespace */ public static final JndiName JAVA_CONTEXT_NAME = JndiName.of("java:"); /** Jndi name for java:jboss namespace */ public static final JndiName JBOSS_CONTEXT_NAME = JndiName.of("java:jboss"); /** ServiceName for java:jboss namespace */ public static final ServiceName JBOSS_CONTEXT_SERVICE_NAME = JAVA_CONTEXT_SERVICE_NAME.append("jboss"); /** Jndi name for java:global namespace */ public static final JndiName GLOBAL_CONTEXT_NAME = JndiName.of("java:global"); /** ServiceName for java:global namespace */ public static final ServiceName GLOBAL_CONTEXT_SERVICE_NAME = JAVA_CONTEXT_SERVICE_NAME.append("global"); /** Jndi name for java:app namespace */ public static final JndiName APPLICATION_CONTEXT_NAME = JndiName.of("java:app"); /** Parent ServiceName for java:app namespace */ public static final ServiceName APPLICATION_CONTEXT_SERVICE_NAME = JAVA_CONTEXT_SERVICE_NAME.append("app"); /** Jndi name for java:module namespace */ public static final JndiName MODULE_CONTEXT_NAME = JndiName.of("java:module"); /** Parent ServiceName for java:module namespace */ public static final ServiceName MODULE_CONTEXT_SERVICE_NAME = JAVA_CONTEXT_SERVICE_NAME.append("module"); /** Jndi name for java:comp namespace */ public static final JndiName COMPONENT_CONTEXT_NAME = JndiName.of("java:comp"); /** * Get the base service name of a component's JNDI namespace. * * @param app the application name (must not be {@code null}) * @param module the module name (must not be {@code null}) * @param comp the component name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfComponent(String app, String module, String comp) { return COMPONENT_CONTEXT_SERVICE_NAME.append(app, module, comp); } /** * Get the base service name of a module's JNDI namespace. * * @param app the application name (must not be {@code null}) * @param module the module name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfModule(String app, String module) { return MODULE_CONTEXT_SERVICE_NAME.append(app, module); } /** * Get the base service name of an application's JNDI namespace. * * @param app the application name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfApplication(String app) { return APPLICATION_CONTEXT_SERVICE_NAME.append(app); } /** * Get the service name of a context, or {@code null} if there is no service mapping for the * context name. * * @param app the application name * @param module the module name * @param comp the component name * @param context the context to check * @return the service name or {@code null} if there is no service */ public static ServiceName serviceNameOfContext( String app, String module, String comp, String context) { if (context.startsWith("java:")) { final String namespace; final int i = context.indexOf('/'); if (i == -1) { namespace = context.substring(5); } else { namespace = context.substring(5, i); } if (namespace.equals("global")) { return GLOBAL_CONTEXT_SERVICE_NAME.append(context.substring(12)); } else if (namespace.equals("jboss")) { return JBOSS_CONTEXT_SERVICE_NAME.append(context.substring(11)); } else if (namespace.equals("app")) { return contextServiceNameOfApplication(app).append(context.substring(9)); } else if (namespace.equals("module")) { return contextServiceNameOfModule(app, module).append(context.substring(12)); } else if (namespace.equals("comp")) { return contextServiceNameOfComponent(app, module, comp).append(context.substring(10)); } else { return JAVA_CONTEXT_SERVICE_NAME.append(context); } } else { return null; } } /** * Get the service name of a NamingStore * * @param app the application name * @param module the module name * @param comp the component name * @param context the context to check * @return the service name or {@code null} if there is no service */ public static ServiceName serviceNameOfNamingStore( String app, String module, String comp, String context) { if (context.startsWith("java:")) { final String namespace; final int i = context.indexOf('/'); if (i == -1) { namespace = context.substring(5); } else { namespace = context.substring(5, i); } if (namespace.equals("global")) { return GLOBAL_CONTEXT_SERVICE_NAME; } else if (namespace.equals("jboss")) { return JBOSS_CONTEXT_SERVICE_NAME; } else if (namespace.equals("app")) { return contextServiceNameOfApplication(app); } else if (namespace.equals("module")) { return contextServiceNameOfModule(app, module); } else if (namespace.equals("comp")) { return contextServiceNameOfComponent(app, module, comp); } else { return JAVA_CONTEXT_SERVICE_NAME; } } else { return null; } } /** * Get the service name of an environment entry * * @param app the application name * @param module the module name * @param comp the component name * @param useCompNamespace If the component has its own comp namespace * @param envEntryName The env entry name * @return the service name or {@code null} if there is no service */ public static ServiceName serviceNameOfEnvEntry( String app, String module, String comp, boolean useCompNamespace, final String envEntryName) { if (envEntryName.startsWith("java:")) { if (useCompNamespace) { return serviceNameOfContext(app, module, comp, envEntryName); } else { return serviceNameOfContext(app, module, module, envEntryName); } } else { if (useCompNamespace) { return serviceNameOfContext(app, module, comp, "java:comp/env/" + envEntryName); } else { return serviceNameOfContext(app, module, module, "java:module/env/" + envEntryName); } } } }
static void installRuntimeServices( OperationContext context, PathAddress address, ModelNode fullModel, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> controllers) throws OperationFailedException { String name = address.getLastElement().getValue(); final String jndiName = getJndiName(fullModel, context); final ServiceTarget serviceTarget = context.getServiceTarget(); final MailSessionConfig config = from(context, fullModel); final MailSessionService service = new MailSessionService(config); final ServiceName serviceName = MAIL_SESSION_SERVICE_NAME.append(name); final ServiceBuilder<?> mailSessionBuilder = serviceTarget.addService(serviceName, service); addOutboundSocketDependency(service, mailSessionBuilder, config.getImapServer()); addOutboundSocketDependency(service, mailSessionBuilder, config.getPop3Server()); addOutboundSocketDependency(service, mailSessionBuilder, config.getSmtpServer()); for (CustomServerConfig server : config.getCustomServers()) { if (server.getOutgoingSocketBinding() != null) { addOutboundSocketDependency(service, mailSessionBuilder, server); } } final ManagedReferenceFactory valueManagedReferenceFactory = new MailSessionManagedReferenceFactory(service); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final BinderService binderService = new BinderService(bindInfo.getBindName()); final ServiceBuilder<?> binderBuilder = serviceTarget .addService(bindInfo.getBinderServiceName(), binderService) .addInjection(binderService.getManagedObjectInjector(), valueManagedReferenceFactory) .addDependency( bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()) .addListener( new AbstractServiceListener<Object>() { public void transition( final ServiceController<? extends Object> controller, final ServiceController.Transition transition) { switch (transition) { case STARTING_to_UP: { MailLogger.ROOT_LOGGER.boundMailSession(jndiName); break; } case START_REQUESTED_to_DOWN: { MailLogger.ROOT_LOGGER.unboundMailSession(jndiName); break; } case REMOVING_to_REMOVED: { MailLogger.ROOT_LOGGER.removedMailSession(jndiName); break; } } } }); mailSessionBuilder .setInitialMode(ServiceController.Mode.ACTIVE) .addListener(verificationHandler); binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).addListener(verificationHandler); controllers.add(mailSessionBuilder.install()); controllers.add(binderBuilder.install()); }
/** * Service that manages an EJBClientContext * * @author Stuart Douglas */ public class DefaultEjbClientContextService implements Service<EJBClientContext> { private static final Logger logger = Logger.getLogger(DefaultEjbClientContextService.class); /** The base service name for these services */ public static final ServiceName BASE_SERVICE_NAME = ServiceName.JBOSS.append("ejb3", "ejbClientContext"); /** The default service name. There will always be a service registered under this name */ public static final ServiceName DEFAULT_SERVICE_NAME = BASE_SERVICE_NAME.append("default"); // setup the EJB client context selector in a static block so that the service restart // doesn't run into trouble while resetting a selector, since the ability to switch the // selector will be locked https://issues.jboss.org/browse/AS7-2998 static { // setup the selector AccessController.doPrivileged(new SetSelectorAction(TCCLEJBClientContextSelector.INSTANCE)); } private final InjectedValue<TCCLEJBClientContextSelectorService> tcclEJBClientContextSelector = new InjectedValue<TCCLEJBClientContextSelectorService>(); private final InjectedValue<LocalEjbReceiver> defaultLocalEJBReceiver = new InjectedValue<LocalEjbReceiver>(); /** The client context */ private volatile EJBClientContext context; private final boolean lockSelectorOnStart; /** * @param lockEJBClientContextSelectorOnStart True if the EJB client context selector should be * locked on start of this service. False otherwise. */ public DefaultEjbClientContextService(final boolean lockEJBClientContextSelectorOnStart) { this.lockSelectorOnStart = lockEJBClientContextSelectorOnStart; } @Override public synchronized void start(final StartContext context) throws StartException { final EJBClientContext clientContext = EJBClientContext.create(new LocalOnlyEjbClientConfiguration()); // register the default local EJB receiver (if present - app clients don't have local EJB // receivers) final LocalEjbReceiver localEjbReceiver = this.defaultLocalEJBReceiver.getOptionalValue(); if (localEjbReceiver != null) { clientContext.registerEJBReceiver(localEjbReceiver); } this.context = clientContext; if (this.lockSelectorOnStart) { // lock the EJB client context selector AccessController.doPrivileged(new LockSelectorAction()); } // the EJBClientContext selector is set to TCCLEJBClientContextSelector and is *locked* once // (in a static block of this service) so that restarting this service will not cause failures // related // to resetting the selector. The TCCLEJBClientContextSelector is backed by a // TCCLEJBClientContextSelectorService // which is what we set here during the service start, so that the selector has the correct // service to return the // EJBClientContext. @see https://issues.jboss.org/browse/AS7-2998 for details TCCLEJBClientContextSelector.INSTANCE.setup( this.tcclEJBClientContextSelector.getValue(), this.context); } @Override public synchronized void stop(final StopContext context) { this.context = null; TCCLEJBClientContextSelector.INSTANCE.destroy(); } @Override public EJBClientContext getValue() throws IllegalStateException, IllegalArgumentException { return context; } public Injector<TCCLEJBClientContextSelectorService> getTCCLBasedEJBClientContextSelectorInjector() { return this.tcclEJBClientContextSelector; } public Injector<LocalEjbReceiver> getDefaultLocalEJBReceiverInjector() { return this.defaultLocalEJBReceiver; } private static final class SetSelectorAction implements PrivilegedAction<ContextSelector<EJBClientContext>> { private final ContextSelector<EJBClientContext> selector; private SetSelectorAction(final ContextSelector<EJBClientContext> selector) { this.selector = selector; } @Override public ContextSelector<EJBClientContext> run() { return EJBClientContext.setSelector(selector); } } private static final class LockSelectorAction implements PrivilegedAction<Void> { @Override public Void run() { EJBClientContext.lockSelector(); return null; } } /** * A {@link EJBClientConfiguration} which is applicable only for a {@link EJBClientContext} * consisting of just the {@link LocalEjbReceiver}. i.e. this client configuration cannot be used * for setting up connections to remote servers */ class LocalOnlyEjbClientConfiguration implements EJBClientConfiguration { private final DeploymentNodeSelector localPreferringDeploymentNodeSelector = new LocalEJBReceiverPreferringDeploymentNodeSelector(); @Override public String getEndpointName() { // This client configuration will *not* be used to create endpoints return null; } @Override public OptionMap getEndpointCreationOptions() { // This client configuration will *not* be used to create endpoints return OptionMap.EMPTY; } @Override public OptionMap getRemoteConnectionProviderCreationOptions() { // This client configuration will *not* be used to register connection providers return OptionMap.EMPTY; } @Override public CallbackHandler getCallbackHandler() { // This client configuration is not applicable for registering remote connections return null; } @Override public Iterator<RemotingConnectionConfiguration> getConnectionConfigurations() { // This client configuration will *not* be used for auto creating connections to remote // servers. return Collections.EMPTY_SET.iterator(); } @Override public Iterator<ClusterConfiguration> getClusterConfigurations() { return Collections.EMPTY_SET.iterator(); } @Override public ClusterConfiguration getClusterConfiguration(String nodeName) { return null; } @Override public long getInvocationTimeout() { return 0; } @Override public long getReconnectTasksTimeout() { return 0; } @Override public DeploymentNodeSelector getDeploymentNodeSelector() { return this.localPreferringDeploymentNodeSelector; } } }
/** * Get the base service name of a component's JNDI namespace. * * @param app the application name (must not be {@code null}) * @param module the module name (must not be {@code null}) * @param comp the component name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfComponent(String app, String module, String comp) { return COMPONENT_CONTEXT_SERVICE_NAME.append(app, module, comp); }
public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) { return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName()); }
/** * Get the base service name of a module's JNDI namespace. * * @param app the application name (must not be {@code null}) * @param module the module name (must not be {@code null}) * @return the base service name */ public static ServiceName contextServiceNameOfModule(String app, String module) { return MODULE_CONTEXT_SERVICE_NAME.append(app, module); }