use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class ComponentInstallProcessor method deployComponent.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void deployComponent(final DeploymentPhaseContext phaseContext, final ComponentConfiguration configuration, final List<ServiceName> jndiDependencies, final ServiceName bindingDependencyService) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final String applicationName = configuration.getApplicationName();
final String moduleName = configuration.getModuleName();
final String componentName = configuration.getComponentName();
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
//create additional injectors
final ServiceName createServiceName = configuration.getComponentDescription().getCreateServiceName();
final ServiceName startServiceName = configuration.getComponentDescription().getStartServiceName();
final BasicComponentCreateService createService = configuration.getComponentCreateServiceFactory().constructService(configuration);
final ServiceBuilder<Component> createBuilder = serviceTarget.addService(createServiceName, createService);
// inject the DU
createBuilder.addDependency(deploymentUnit.getServiceName(), DeploymentUnit.class, createService.getDeploymentUnitInjector());
final ComponentStartService startService = new ComponentStartService();
final ServiceBuilder<Component> startBuilder = serviceTarget.addService(startServiceName, startService);
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_COMPLETE_SERVICES, startServiceName);
//WFLY-1402 we don't add the bindings to the jndi dependencies list directly, instead
//the bindings depend on the this artificial service
ServiceName jndiDepServiceName = configuration.getComponentDescription().getServiceName().append(JNDI_BINDINGS_SERVICE);
final ServiceBuilder<Void> jndiDepServiceBuilder = serviceTarget.addService(jndiDepServiceName, Service.NULL);
jndiDependencies.add(jndiDepServiceName);
// Add all service dependencies
for (DependencyConfigurator configurator : configuration.getCreateDependencies()) {
configurator.configureDependency(createBuilder, createService);
}
for (DependencyConfigurator configurator : configuration.getStartDependencies()) {
configurator.configureDependency(startBuilder, startService);
}
// START depends on CREATE
startBuilder.addDependency(createServiceName, BasicComponent.class, startService.getComponentInjector());
Services.addServerExecutorDependency(startBuilder, startService.getExecutorInjector(), false);
//don't start components until all bindings are up
startBuilder.addDependency(bindingDependencyService);
final ServiceName contextServiceName;
//set up the naming context if necessary
if (configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE) {
final NamingStoreService contextService = new NamingStoreService(true);
serviceTarget.addService(configuration.getComponentDescription().getContextServiceName(), contextService).install();
}
final InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.USE_MODULE, configuration.getComponentName(), configuration.getModuleName(), configuration.getApplicationName());
// Iterate through each view, creating the services for each
for (ViewConfiguration viewConfiguration : configuration.getViews()) {
final ServiceName serviceName = viewConfiguration.getViewServiceName();
final ViewService viewService = new ViewService(viewConfiguration);
final ServiceBuilder<ComponentView> componentViewServiceBuilder = serviceTarget.addService(serviceName, viewService);
componentViewServiceBuilder.addDependency(createServiceName, Component.class, viewService.getComponentInjector());
for (final DependencyConfigurator<ViewService> depConfig : viewConfiguration.getDependencies()) {
depConfig.configureDependency(componentViewServiceBuilder, viewService);
}
componentViewServiceBuilder.install();
startBuilder.addDependency(serviceName);
// The bindings for the view
for (BindingConfiguration bindingConfiguration : viewConfiguration.getBindingConfigurations()) {
final String bindingName = bindingConfiguration.getName();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(applicationName, moduleName, componentName, bindingName);
final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
//these bindings should never be merged, if a view binding is duplicated it is an error
jndiDepServiceBuilder.addDependency(bindInfo.getBinderServiceName());
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), service);
bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
serviceBuilder.install();
}
}
if (configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE) {
// The bindings for the component
final Set<ServiceName> bound = new HashSet<ServiceName>();
processBindings(phaseContext, configuration, serviceTarget, resolutionContext, configuration.getComponentDescription().getBindingConfigurations(), jndiDepServiceBuilder, bound);
//class level bindings should be ignored if the deployment is metadata complete
if (!MetadataCompleteMarker.isMetadataComplete(phaseContext.getDeploymentUnit())) {
// The bindings for the component class
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
protected void handle(final Class<?> clazz, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
if (classDescription != null) {
processBindings(phaseContext, configuration, serviceTarget, resolutionContext, classDescription.getBindingConfigurations(), jndiDepServiceBuilder, bound);
}
}
}.run();
for (InterceptorDescription interceptor : configuration.getComponentDescription().getAllInterceptors()) {
final Class<?> interceptorClass;
try {
interceptorClass = module.getClassLoader().loadClass(interceptor.getInterceptorClassName());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptor.getInterceptorClassName(), configuration.getComponentClass());
}
if (interceptorClass != null) {
new ClassDescriptionTraversal(interceptorClass, applicationClasses) {
@Override
protected void handle(final Class<?> clazz, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
if (classDescription != null) {
processBindings(phaseContext, configuration, serviceTarget, resolutionContext, classDescription.getBindingConfigurations(), jndiDepServiceBuilder, bound);
}
}
}.run();
}
}
}
}
createBuilder.install();
startBuilder.install();
jndiDepServiceBuilder.install();
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class ComponentInstallProcessor method processBindings.
@SuppressWarnings("unchecked")
private void processBindings(DeploymentPhaseContext phaseContext, ComponentConfiguration configuration, ServiceTarget serviceTarget, InjectionSource.ResolutionContext resolutionContext, List<BindingConfiguration> bindings, final ServiceBuilder<?> jndiDepServiceBuilder, final Set<ServiceName> bound) throws DeploymentUnitProcessingException {
//we only handle java:comp bindings for components that have their own namespace here, the rest are processed by ModuleJndiBindingProcessor
for (BindingConfiguration bindingConfiguration : bindings) {
if (bindingConfiguration.getName().startsWith("java:comp") || !bindingConfiguration.getName().startsWith("java:")) {
final String bindingName = bindingConfiguration.getName().startsWith("java:comp") ? bindingConfiguration.getName() : "java:comp/env/" + bindingConfiguration.getName();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(configuration.getApplicationName(), configuration.getModuleName(), configuration.getComponentName(), configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE, bindingName);
if (bound.contains(bindInfo.getBinderServiceName())) {
continue;
}
bound.add(bindInfo.getBinderServiceName());
try {
final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
jndiDepServiceBuilder.addDependency(bindInfo.getBinderServiceName());
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), service);
bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
serviceBuilder.install();
} catch (DuplicateServiceException e) {
ServiceController<ManagedReferenceFactory> registered = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
if (registered == null)
throw e;
BinderService service = (BinderService) registered.getService();
if (!service.getSource().equals(bindingConfiguration.getSource()))
throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
} catch (CircularDependencyException e) {
throw EeLogger.ROOT_LOGGER.circularDependency(bindingName);
}
}
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class EEConcurrentAbstractService method bindValueToJndi.
private void bindValueToJndi(final StartContext context) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
final BinderService binderService = new BinderService(bindInfo.getBindName());
final ImmediateManagedReferenceFactory managedReferenceFactory = new ImmediateManagedReferenceFactory(getValue());
context.getChildTarget().addService(bindInfo.getBinderServiceName(), binderService).addInjectionValue(binderService.getManagedObjectInjector(), new ImmediateValue<ManagedReferenceFactory>(managedReferenceFactory)).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class LookupInjectionSource method getResourceValue.
/**
* {@inheritDoc}
*/
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
final String applicationName = resolutionContext.getApplicationName();
final String moduleName = resolutionContext.getModuleName();
final String componentName = resolutionContext.getComponentName();
final boolean compUsesModule = resolutionContext.isCompUsesModule();
final String scheme = org.jboss.as.naming.InitialContext.getURLScheme(lookupName);
if (scheme == null) {
// relative name, build absolute name and setup normal lookup injection
if (componentName != null && !compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:comp/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else if (compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:jboss/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
if (scheme.equals("java")) {
// an absolute java name, setup normal lookup injection
if (compUsesModule && lookupName.startsWith("java:comp/")) {
// switch "comp" with "module"
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/" + lookupName.substring(10)).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
// an absolute non java name
final ManagedReferenceFactory managedReferenceFactory;
if (URL_SCHEMES.contains(scheme)) {
// a Java EE Standard Resource Manager Connection Factory for URLs, using lookup to define value of URL, inject factory that creates URL instances
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new URL(lookupName));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
};
} else {
// lookup for a non java jndi resource, inject factory which does a true jndi lookup
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new InitialContext().lookup(lookupName));
} catch (NamingException e) {
EeLogger.ROOT_LOGGER.tracef(e, "failed to lookup %s", lookupName);
return null;
}
}
};
}
injector.inject(managedReferenceFactory);
}
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class EjbLookupInjectionSource method getResourceValue.
@Override
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final Class<?> type;
if (targetType != null) {
type = targetType;
} else if (targetTypeName != null) {
try {
type = ClassLoadingUtils.loadClass(targetTypeName, phaseContext.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
type = null;
}
injector.inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
final Object value = new InitialContext().lookup(lookup);
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
if (type != null && value instanceof org.omg.CORBA.Object) {
return PortableRemoteObject.narrow(value, type);
} else {
return value;
}
}
};
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
});
}
Aggregations