Search in sources :

Example 31 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class ModuleContextProcessor method deploy.

/**
     * 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 (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        return;
    }
    EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
    final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
    final NamingStoreService contextService = new NamingStoreService(true);
    serviceTarget.addService(moduleContextServiceName, contextService).install();
    final BinderService moduleNameBinder = new BinderService("ModuleName");
    final ServiceName moduleNameServiceName = moduleContextServiceName.append("ModuleName");
    serviceTarget.addService(moduleNameServiceName, moduleNameBinder).addInjection(moduleNameBinder.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(moduleDescription.getModuleName()))).addDependency(moduleContextServiceName, ServiceBasedNamingStore.class, moduleNameBinder.getNamingStoreInjector()).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, moduleNameServiceName);
    deploymentUnit.putAttachment(MODULE_CONTEXT_CONFIG, moduleContextServiceName);
    final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
    phaseContext.addDependency(appContextServiceName, NamingStore.class, selector.getAppContextInjector());
    phaseContext.addDependency(moduleContextServiceName, NamingStore.class, selector.getModuleContextInjector());
    phaseContext.addDependency(moduleContextServiceName, NamingStore.class, selector.getCompContextInjector());
    phaseContext.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getJbossContextInjector());
    phaseContext.addDependency(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getExportedContextInjector());
    phaseContext.addDependency(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getGlobalContextInjector());
    moduleDescription.setNamespaceContextSelector(selector);
    final Set<ServiceName> serviceNames = new HashSet<ServiceName>();
    serviceNames.add(appContextServiceName);
    serviceNames.add(moduleContextServiceName);
    serviceNames.add(ContextNames.JBOSS_CONTEXT_SERVICE_NAME);
    serviceNames.add(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME);
    // add the arquillian setup action, so the module namespace is available in arquillian tests
    final JavaNamespaceSetup setupAction = new JavaNamespaceSetup(selector, deploymentUnit.getServiceName());
    deploymentUnit.addToAttachmentList(SETUP_ACTIONS, setupAction);
    deploymentUnit.addToAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS, setupAction);
    deploymentUnit.putAttachment(Attachments.JAVA_NAMESPACE_SETUP_ACTION, setupAction);
}
Also used : NamingStoreService(org.jboss.as.naming.service.NamingStoreService) BinderService(org.jboss.as.naming.service.BinderService) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceTarget(org.jboss.msc.service.ServiceTarget) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Example 32 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class BinderServiceUtil method installBinderService.

/**
     * Install a binder service to bind the value of the {@code service} using the binding {@code name}.

     * @param serviceTarget
     * @param name the binding name
     * @param service the service whose value must be bound
     */
public static void installBinderService(final ServiceTarget serviceTarget, final String name, final Service<?> service, final ServiceName... dependencies) {
    final BindInfo bindInfo = ContextNames.bindInfoFor(name);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder serviceBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addInjection(binderService.getManagedObjectInjector(), new ValueManagedReferenceFactory(service)).setInitialMode(ServiceController.Mode.PASSIVE);
    if (dependencies != null && dependencies.length > 0) {
        serviceBuilder.addDependencies(dependencies);
    }
    serviceBuilder.install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 33 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class TransactionJndiBindingProcessor method bindServices.

/**
     * Binds the java:comp/UserTransaction service and the java:comp/TransactionSynchronizationRegistry
     *
     * @param deploymentUnit The deployment unit
     * @param serviceTarget The service target
     * @param contextServiceName The service name of the context to bind to
     */
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
    final ServiceName userTransactionServiceName = contextServiceName.append("UserTransaction");
    final UserTransactionBindingService userTransactionBindingService = new UserTransactionBindingService("UserTransaction");
    serviceTarget.addService(userTransactionServiceName, userTransactionBindingService).addDependency(UserTransactionAccessControlService.SERVICE_NAME, UserTransactionAccessControlService.class, userTransactionBindingService.getUserTransactionAccessControlServiceInjector()).addDependency(UserTransactionService.SERVICE_NAME, UserTransaction.class, new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector())).addDependency(contextServiceName, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector()).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, userTransactionServiceName);
    final ServiceName transactionSynchronizationRegistryName = contextServiceName.append("TransactionSynchronizationRegistry");
    BinderService transactionSyncBinderService = new BinderService("TransactionSynchronizationRegistry");
    serviceTarget.addService(transactionSynchronizationRegistryName, transactionSyncBinderService).addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, new ManagedReferenceInjector<TransactionSynchronizationRegistry>(transactionSyncBinderService.getManagedObjectInjector())).addDependency(contextServiceName, ServiceBasedNamingStore.class, transactionSyncBinderService.getNamingStoreInjector()).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, transactionSynchronizationRegistryName);
}
Also used : UserTransaction(javax.transaction.UserTransaction) BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) UserTransactionAccessControlService(org.jboss.as.txn.service.UserTransactionAccessControlService) UserTransactionBindingService(org.jboss.as.txn.service.UserTransactionBindingService)

Aggregations

BinderService (org.jboss.as.naming.service.BinderService)33 ServiceName (org.jboss.msc.service.ServiceName)18 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)17 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)14 ContextNames (org.jboss.as.naming.deployment.ContextNames)14 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)12 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ServiceController (org.jboss.msc.service.ServiceController)9 ImmediateValue (org.jboss.msc.value.ImmediateValue)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 BindInfo (org.jboss.as.naming.deployment.ContextNames.BindInfo)3 NamingStoreService (org.jboss.as.naming.service.NamingStoreService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ModelNode (org.jboss.dmr.ModelNode)3 Injector (org.jboss.msc.inject.Injector)3 HashSet (java.util.HashSet)2 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)2 UserTransaction (javax.transaction.UserTransaction)2 DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)2 DataSourceReferenceFactoryService (org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService)2