Search in sources :

Example 6 with ImmediateValue

use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.

the class CacheDependenciesProcessor method deploy.

@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 CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    final ServiceTarget target = context.getServiceTarget();
    @SuppressWarnings("rawtypes") Collection<ValueDependency<CacheFactoryBuilder>> cacheDependencies = moduleDescription.getComponentDescriptions().stream().filter(StatefulComponentDescription.class::isInstance).map(description -> new InjectedValueDependency<>(getCacheFactoryBuilderServiceName((StatefulComponentDescription) description), CacheFactoryBuilder.class)).distinct().collect(Collectors.toList());
    Service<Void> service = new AbstractService<Void>() {

        @Override
        public void start(StartContext context) {
            // Install dependencies for each distinct cache factory builder referenced by the deployment
            cacheDependencies.stream().map(Value::getValue).distinct().forEach(builder -> builder.installDeploymentUnitDependencies(support, target, name));
        }
    };
    ServiceBuilder<Void> builder = target.addService(name.append("cache-dependencies-installer"), service);
    cacheDependencies.forEach(dependency -> dependency.register(builder));
    builder.install();
    // Install versioned marshalling configuration
    InjectedValue<ModuleDeployment> deployment = new InjectedValue<>();
    Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    target.addService(MarshallingConfigurationRepositoryValue.getServiceName(name), new ValueService<>(new MarshallingConfigurationRepositoryValue(deployment, new ImmediateValue<>(module)))).addDependency(name.append(ModuleDeployment.SERVICE_NAME), ModuleDeployment.class, deployment).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) MarshallingConfigurationRepositoryValue(org.jboss.as.ejb3.component.stateful.MarshallingConfigurationRepositoryValue) AbstractService(org.jboss.msc.service.AbstractService) ValueDependency(org.wildfly.clustering.service.ValueDependency) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ValueService(org.jboss.msc.service.ValueService) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) CacheFactoryBuilder(org.jboss.as.ejb3.cache.CacheFactoryBuilder) ImmediateValue(org.jboss.msc.value.ImmediateValue) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) StartContext(org.jboss.msc.service.StartContext) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) Value(org.jboss.msc.value.Value) ImmediateValue(org.jboss.msc.value.ImmediateValue) MarshallingConfigurationRepositoryValue(org.jboss.as.ejb3.component.stateful.MarshallingConfigurationRepositoryValue) InjectedValue(org.jboss.msc.value.InjectedValue) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 7 with ImmediateValue

use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.

the class BeanValidationFactoryDeployer method bindServices.

/**
     *
     * @param factory The ValidatorFactory to bind
     * @param serviceTarget The service target
     * @param contextServiceName The service name of the context to bind to
     */
private void bindServices(LazyValidatorFactory factory, ServiceTarget serviceTarget, EEModuleDescription description, String componentName, ServiceName contextServiceName) {
    BinderService validatorFactoryBindingService = new BinderService("ValidatorFactory");
    validatorFactoryBindingService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(factory)));
    serviceTarget.addService(contextServiceName.append("ValidatorFactory"), validatorFactoryBindingService).addDependency(contextServiceName, ServiceBasedNamingStore.class, validatorFactoryBindingService.getNamingStoreInjector()).install();
    BinderService validatorBindingService = new BinderService("Validator");
    validatorBindingService.getManagedObjectInjector().inject(new ValidatorJndiInjectable(factory));
    serviceTarget.addService(contextServiceName.append("Validator"), validatorBindingService).addDependency(contextServiceName, ServiceBasedNamingStore.class, validatorBindingService.getNamingStoreInjector()).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 8 with ImmediateValue

use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.

the class NamingBindingAdd method doRebind.

void doRebind(OperationContext context, ModelNode model, BinderService service) throws OperationFailedException {
    ManagedReferenceFactory ref = service.getManagedObjectInjector().getValue();
    if (ref instanceof MutableManagedReferenceFactory) {
        MutableManagedReferenceFactory factory = (MutableManagedReferenceFactory) ref;
        final BindingType type = BindingType.forName(NamingBindingResourceDefinition.BINDING_TYPE.resolveModelAttribute(context, model).asString());
        if (type == BindingType.SIMPLE) {
            Object bindValue = createSimpleBinding(context, model);
            factory.setFactory(new ValueManagedReferenceFactory(new ImmediateValue<Object>(bindValue)));
            service.setSource(bindValue);
        } else if (type == BindingType.OBJECT_FACTORY) {
            final ObjectFactory objectFactoryClassInstance = createObjectFactory(context, model);
            final Hashtable<String, String> environment = getObjectFactoryEnvironment(context, model);
            factory.setFactory(new ObjectFactoryManagedReference(objectFactoryClassInstance, service.getName(), environment));
            service.setSource(objectFactoryClassInstance);
        } else if (type == BindingType.LOOKUP) {
            final String lookup = NamingBindingResourceDefinition.LOOKUP.resolveModelAttribute(context, model).asString();
            factory.setFactory(new LookupManagedReferenceFactory(lookup));
            service.setSource(null);
        } else if (type == BindingType.EXTERNAL_CONTEXT) {
            throw NamingLogger.ROOT_LOGGER.cannotRebindExternalContext();
        } else {
            throw NamingLogger.ROOT_LOGGER.unknownBindingType(type.toString());
        }
    } else {
        throw NamingLogger.ROOT_LOGGER.cannotRebindExternalContext();
    }
}
Also used : ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) Hashtable(java.util.Hashtable) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 9 with ImmediateValue

use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.

the class WritableServiceBasedNamingStore method rebind.

public void rebind(Name name, Object object) throws NamingException {
    final Object owner = requireOwner();
    // re-set the existent binder service injected value
    final ServiceName bindName = buildServiceName(name);
    final ServiceController<?> controller = getServiceRegistry().getService(bindName);
    if (controller == null) {
        bind(name, object, owner, bindName);
    } else {
        final BinderService binderService = (BinderService) controller.getService();
        if (owner instanceof ServiceName) {
            final ServiceName deploymentUnitServiceName = (ServiceName) owner;
            binderService.acquire();
            final RuntimeBindReleaseService.References duBindingReferences = (RuntimeBindReleaseService.References) controller.getServiceContainer().getService(JndiNamingDependencyProcessor.serviceName(deploymentUnitServiceName)).getValue();
            duBindingReferences.add(binderService);
        }
        binderService.getManagedObjectInjector().setValue(new ImmediateValue(new ImmediateManagedReferenceFactory(object)));
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 10 with ImmediateValue

use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method entityManagerBind.

private static void entityManagerBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, final PersistenceUnitMetadata pu, ServiceName puServiceName, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
    if (pu.getProperties().containsKey(ENTITYMANAGER_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGER_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the transaction scoped entity manager to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(new TransactionScopedEntityManager(pu.getScopedPersistenceUnitName(), Collections.emptyMap(), value.getEntityManagerFactory(), SynchronizationType.SYNCHRONIZED, transactionSynchronizationRegistry, transactionManager))));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) TransactionScopedEntityManager(org.jboss.as.jpa.container.TransactionScopedEntityManager) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

ImmediateValue (org.jboss.msc.value.ImmediateValue)20 BinderService (org.jboss.as.naming.service.BinderService)6 ServiceName (org.jboss.msc.service.ServiceName)6 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)5 Method (java.lang.reflect.Method)3 ContextNames (org.jboss.as.naming.deployment.ContextNames)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 ArrayList (java.util.ArrayList)2 ObjectName (javax.management.ObjectName)2 ClassLoaderThreadFactory (org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)2 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)2 JBossServiceDependencyConfig (org.jboss.as.service.descriptor.JBossServiceDependencyConfig)2 Module (org.jboss.modules.Module)2 CastingInjector (org.jboss.msc.inject.CastingInjector)2