use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class BinderServiceUtil method installAliasBinderService.
public static void installAliasBinderService(final ServiceTarget serviceTarget, final BindInfo bindInfo, final String alias) {
final BindInfo aliasBindInfo = ContextNames.bindInfoFor(alias);
final BinderService aliasBinderService = new BinderService(alias);
aliasBinderService.getManagedObjectInjector().inject(new AliasManagedReferenceFactory(bindInfo.getAbsoluteJndiName()));
serviceTarget.addService(aliasBindInfo.getBinderServiceName(), aliasBinderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, aliasBinderService.getNamingStoreInjector()).addDependency(bindInfo.getBinderServiceName()).addListener(new AbstractServiceListener<ManagedReferenceFactory>() {
@Override
public void transition(ServiceController<? extends ManagedReferenceFactory> controller, ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
ROOT_LOGGER.boundJndiName(alias);
break;
}
case STOPPING_to_DOWN:
{
ROOT_LOGGER.unboundJndiName(alias);
break;
}
case REMOVING_to_REMOVED:
{
ROOT_LOGGER.debugf("Removed messaging object [%s]", alias);
break;
}
}
}
}).install();
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class AbstractDataSourceAdd method secondRuntimeStep.
static void secondRuntimeStep(OperationContext context, ModelNode operation, ManagementResourceRegistration datasourceRegistration, ModelNode model, boolean isXa) throws OperationFailedException {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ModelNode address = operation.require(OP_ADDR);
final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString();
final ServiceRegistry registry = context.getServiceRegistry(true);
final List<ServiceName> serviceNames = registry.getServiceNames();
final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean();
final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class);
final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName);
final ExceptionSupplier<CredentialSource, Exception> credentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getCredentialSourceSupplierInjector().getOptionalValue() : null;
final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getRecoveryCredentialSourceSupplierInjector().getOptionalValue() : null;
final boolean jta;
if (isXa) {
jta = true;
final ModifiableXaDataSource dataSourceConfig;
try {
dataSourceConfig = xaFrom(context, model, dsName, credentialSourceExceptionExceptionSupplier, recoveryCredentialSourceExceptionExceptionSupplier);
} catch (ValidateException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("XaDataSource", operation, e.getLocalizedMessage()));
}
final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig);
final ServiceBuilder<?> builder = serviceTarget.addService(xaDataSourceConfigServiceName, xaDataSourceConfigService);
// add dependency on security domain service if applicable
final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
if (dsSecurityConfig != null) {
final String securityDomainName = dsSecurityConfig.getSecurityDomain();
if (!elytronEnabled && securityDomainName != null) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
}
}
// add dependency on security domain service if applicable for recovery config
if (dataSourceConfig.getRecovery() != null) {
final Credential credential = dataSourceConfig.getRecovery().getCredential();
if (credential != null) {
final String securityDomainName = credential.getSecurityDomain();
if (!RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && securityDomainName != null) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
}
}
}
int propertiesCount = 0;
for (ServiceName name : serviceNames) {
if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) {
final ServiceController<?> xaConfigPropertyController = registry.getService(name);
XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigPropertyController.getService();
if (!ServiceController.State.UP.equals(xaConfigPropertyController.getState())) {
propertiesCount++;
xaConfigPropertyController.setMode(ServiceController.Mode.ACTIVE);
builder.addDependency(name, String.class, xaDataSourceConfigService.getXaDataSourcePropertyInjector(xaPropService.getName()));
} else {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.xa-config-property", name));
}
}
}
if (propertiesCount == 0) {
throw ConnectorLogger.ROOT_LOGGER.xaDataSourcePropertiesNotPresent();
}
builder.install();
} else {
final ModifiableDataSource dataSourceConfig;
try {
dataSourceConfig = from(context, model, dsName, credentialSourceExceptionExceptionSupplier);
} catch (ValidateException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("DataSource", operation, e.getLocalizedMessage()));
}
jta = dataSourceConfig.isJTA();
final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig);
final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName, configService);
// add dependency on security domain service if applicable
final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
if (dsSecurityConfig != null) {
final String securityDomainName = dsSecurityConfig.getSecurityDomain();
if (!elytronEnabled && securityDomainName != null) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
}
}
for (ServiceName name : serviceNames) {
if (dataSourceCongServiceName.append("connection-properties").isParentOf(name)) {
final ServiceController<?> connPropServiceController = registry.getService(name);
ConnectionPropertiesService connPropService = (ConnectionPropertiesService) connPropServiceController.getService();
if (!ServiceController.State.UP.equals(connPropServiceController.getState())) {
connPropServiceController.setMode(ServiceController.Mode.ACTIVE);
builder.addDependency(name, String.class, configService.getConnectionPropertyInjector(connPropService.getName()));
} else {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.connectionProperty", name));
}
}
}
builder.install();
}
final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName).append(Constants.STATISTICS);
if (dataSourceController != null) {
if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
DataSourceStatisticsService statsService = new DataSourceStatisticsService(datasourceRegistration, statsEnabled);
serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService).addAliases(dataSourceServiceNameAlias).addDependency(dataSourceServiceName).addDependency(CommonDeploymentService.getServiceName(ContextNames.bindInfoFor(jndiName)), CommonDeployment.class, statsService.getCommonDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
dataSourceController.setMode(ServiceController.Mode.ACTIVE);
} else {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source", dsName));
}
} else {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceNotAvailable("Data-source", dsName));
}
final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(dsName);
final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, DataSource.class, referenceFactoryService.getDataSourceInjector());
referenceBuilder.install();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
final BinderService binderService = new BinderService(bindInfo.getBindName());
final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).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:
{
if (jta) {
SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
} else {
SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
}
break;
}
case STOPPING_to_DOWN:
{
if (jta) {
SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
} else {
SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
}
break;
}
case REMOVING_to_REMOVED:
{
SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName);
break;
}
}
}
});
binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
binderBuilder.install();
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class ModuleJndiBindingProcessor method addJndiBinding.
protected void addJndiBinding(final EEModuleConfiguration module, final BindingConfiguration bindingConfiguration, final DeploymentPhaseContext phaseContext, final List<ServiceName> dependencies) throws DeploymentUnitProcessingException {
// Gather information about the dependency
final String bindingName = bindingConfiguration.getName().startsWith("java:") ? bindingConfiguration.getName() : "java:module/env/" + bindingConfiguration.getName();
InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(true, module.getModuleName(), module.getModuleName(), module.getApplicationName());
// Check to see if this entry should actually be bound into JNDI.
if (bindingName != null) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(module.getApplicationName(), module.getModuleName(), module.getModuleName(), false, bindingName);
dependencies.add(bindInfo.getBinderServiceName());
if (bindingName.startsWith("java:comp") || bindingName.startsWith("java:module") || bindingName.startsWith("java:app")) {
//this is a binding that does not need to be shared.
try {
final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = phaseContext.getServiceTarget().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);
}
} else {
BinderService service;
try {
service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource(), true);
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = CurrentServiceContainer.getServiceContainer().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) {
final ServiceController<ManagedReferenceFactory> controller = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
if (controller == null)
throw e;
service = (BinderService) controller.getService();
if (!equals(service.getSource(), bindingConfiguration.getSource())) {
throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
}
}
//as these bindings are not child services
//we need to add a listener that released the service when the deployment stops
service.acquire();
ServiceController<?> unitService = CurrentServiceContainer.getServiceContainer().getService(phaseContext.getDeploymentUnit().getServiceName());
unitService.addListener(new BinderReleaseListener(service));
}
} else {
throw EeLogger.ROOT_LOGGER.nullBindingName(bindingConfiguration);
}
}
use of org.jboss.as.naming.service.BinderService 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.service.BinderService 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);
}
}
}
}
Aggregations