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