use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.
the class DistributableWebDeploymentDependencyProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
DeploymentUnit unit = context.getDeploymentUnit();
WarMetaData warMetaData = unit.getAttachment(WarMetaData.ATTACHMENT_KEY);
SharedSessionManagerConfig sharedConfig = unit.getAttachment(SharedSessionManagerConfig.ATTACHMENT_KEY);
if (((warMetaData != null) && (warMetaData.getMergedJBossWebMetaData() != null && warMetaData.getMergedJBossWebMetaData().getDistributable() != null)) || ((sharedConfig != null) && sharedConfig.isDistributable())) {
CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
DistributableWebDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY);
String name = (config != null) ? config.getSessionManagementName() : null;
DistributableSessionManagementProvider management = (name == null) && (config != null) ? config.getSessionManagement() : null;
List<String> immutableClasses = (config != null) ? config.getImmutableClasses() : Collections.emptyList();
for (String immutableClass : immutableClasses) {
unit.addToAttachmentList(DistributableSessionManagementProvider.IMMUTABILITY_ATTACHMENT_KEY, immutableClass);
}
if (management != null) {
LOGGER.debugf("%s will use a deployment-specific distributable session management provider", unit.getName());
ServiceTarget target = context.getServiceTarget();
DeploymentUnit parentUnit = unit.getParent();
String deploymentName = (parentUnit != null) ? parentUnit.getName() + "." + unit.getName() : unit.getName();
ServiceName serviceName = WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, deploymentName);
ServiceBuilder<?> builder = target.addService(serviceName);
Consumer<DistributableSessionManagementProvider> injector = builder.provides(serviceName);
Service service = Service.newInstance(injector, management);
builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
context.addDependency(serviceName, DistributableSessionManagementProvider.ATTACHMENT_KEY);
} else {
if (name != null) {
LOGGER.debugf("%s will use the '%s' distributable session management provider", unit.getName(), name);
} else {
LOGGER.debugf("%s will use the default distributable session management provider", unit.getName());
}
context.addDependency(WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, name), DistributableSessionManagementProvider.ATTACHMENT_KEY);
}
}
}
use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.
the class UndertowDistributableServerRuntimeHandler method execute.
@Override
public void execute(OperationContext context, String serverName) {
SupplierDependency<RoutingProvider> provider = getRoutingProvider(context, serverName);
if (provider != null) {
ServiceTarget target = context.getServiceTarget();
CapabilityServiceSupport support = context.getCapabilityServiceSupport();
SupplierDependency<Server> server = new ServiceSupplierDependency<>(UndertowUnaryRequirement.SERVER.getServiceName(context, serverName));
SupplierDependency<String> route = new FunctionSupplierDependency<>(server, Server::getRoute);
Consumer<ServiceTarget> installer = new Consumer<ServiceTarget>() {
@Override
public void accept(ServiceTarget target) {
for (CapabilityServiceConfigurator configurator : provider.get().getServiceConfigurators(serverName, route)) {
configurator.configure(support).build(target).install();
}
}
};
ServiceName name = ServiceName.JBOSS.append("clustering", "web", "undertow", "routing", serverName);
provider.register(target.addService(name)).setInstance(new ChildTargetService(installer)).install();
}
}
use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.
the class RaOperationUtil method activate.
public static void activate(OperationContext context, String raName, String archiveName) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(true);
ServiceController<?> inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(archiveName));
final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
if (inactiveRaController == null) {
inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(raName));
if (inactiveRaController == null) {
throw ConnectorLogger.ROOT_LOGGER.RARNotYetDeployed(raName);
}
}
InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment inactive = (InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment) inactiveRaController.getValue();
final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
Activation raxml = (Activation) RaxmlController.getValue();
RaServicesFactory.createDeploymentService(inactive.getRegistration(), inactive.getConnectorXmlDescriptor(), inactive.getModule(), inactive.getServiceTarget(), archiveName, inactive.getDeploymentUnitServiceName(), inactive.getDeployment(), raxml, inactive.getResource(), registry, support);
}
use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.
the class DataSourceDefinitionInjectionSource method getResourceValue.
// --- //
@Override
public void getResourceValue(ResolutionContext context, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = new AgroalConnectionFactoryConfigurationSupplier();
try {
Class<?> providerClass = phaseContext.getDeploymentUnit().getAttachment(MODULE).getClassLoader().loadClass(className);
if (providerClass != null && !DataSource.class.isAssignableFrom(providerClass) && !Driver.class.isAssignableFrom(providerClass)) {
throw AgroalLogger.SERVICE_LOGGER.invalidDeploymentConnectionProvider();
}
connectionFactoryConfiguration.connectionProviderClass(providerClass);
} catch (ClassNotFoundException e) {
throw AgroalLogger.SERVICE_LOGGER.loadClassDeploymentException(e, className);
}
for (Map.Entry<String, String> property : properties.entrySet()) {
connectionFactoryConfiguration.jdbcProperty(property.getKey(), property.getValue());
}
if (databaseName != null && !databaseName.isEmpty()) {
connectionFactoryConfiguration.jdbcProperty(DATABASE_NAME_PROP, databaseName);
}
if (description != null && !description.isEmpty()) {
connectionFactoryConfiguration.jdbcProperty(DESCRIPTION_PROP, description);
}
if (serverName != null && !serverName.isEmpty()) {
connectionFactoryConfiguration.jdbcProperty(SERVER_NAME_PROP, serverName);
}
if (portNumber >= 0) {
connectionFactoryConfiguration.jdbcProperty(PORT_NUMBER_PROP, Integer.toString(portNumber));
}
if (loginTimeout >= 0) {
connectionFactoryConfiguration.jdbcProperty(LOGIN_TIMEOUT_PROP, Integer.toString(loginTimeout));
}
if (maxStatements >= 0) {
connectionFactoryConfiguration.jdbcProperty(MAX_STATEMENTS_PROP, Integer.toString(maxStatements));
}
if (url != null && !url.isEmpty()) {
connectionFactoryConfiguration.jdbcUrl(url);
}
if (user != null && !user.isEmpty()) {
connectionFactoryConfiguration.principal(new NamePrincipal(user));
}
if (password != null && !password.isEmpty()) {
connectionFactoryConfiguration.credential(new SimplePassword(password));
}
connectionFactoryConfiguration.jdbcTransactionIsolation(AgroalConnectionFactoryConfiguration.TransactionIsolation.fromLevel(isolationLevel));
AgroalConnectionPoolConfigurationSupplier connectionPoolConfiguration = new AgroalConnectionPoolConfigurationSupplier();
connectionPoolConfiguration.connectionFactoryConfiguration(connectionFactoryConfiguration);
if (initialPoolSize >= 0) {
connectionPoolConfiguration.initialSize(initialPoolSize);
}
if (minPoolSize >= 0) {
connectionPoolConfiguration.minSize(minPoolSize);
}
if (maxPoolSize >= 0) {
connectionPoolConfiguration.maxSize(maxPoolSize);
}
if (maxIdleTime >= 0) {
connectionPoolConfiguration.reapTimeout(Duration.ofSeconds(maxIdleTime));
}
AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
dataSourceConfiguration.connectionPoolConfiguration(connectionPoolConfiguration);
ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
ServiceName dataSourceServiceName = DATASOURCE_DEFINITION_SERVICE_PREFIX.append(bindInfo.getBinderServiceName().getCanonicalName());
// This is the service responsible for the JNDI binding, with a dependency on the datasource service that acts as a ManagedReferenceFactory and is used as the injection source
BinderService binderService = new BinderService(bindInfo.getBindName(), this);
phaseContext.getServiceTarget().addService(bindInfo.getBinderServiceName(), binderService).addDependency(dataSourceServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
ServiceBuilder svcBuilder = phaseContext.getServiceTarget().addService(dataSourceServiceName);
Supplier<TransactionSynchronizationRegistry> tsrSupplier = null;
if (transactional) {
CapabilityServiceSupport css = phaseContext.getDeploymentUnit().getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
ServiceName tsrName = css.getCapabilityServiceName("org.wildfly.transactions.transaction-synchronization-registry");
// noinspection unchecked
tsrSupplier = (Supplier<TransactionSynchronizationRegistry>) svcBuilder.requires(tsrName);
}
DataSourceDefinitionService dataSourceService = new DataSourceDefinitionService(bindInfo, transactional, dataSourceConfiguration, tsrSupplier);
svcBuilder.setInstance(dataSourceService).install();
serviceBuilder.requires(bindInfo.getBinderServiceName());
serviceBuilder.addDependency(dataSourceServiceName, ManagedReferenceFactory.class, injector);
}
use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.
the class EJBComponentDescription method addRemoteTransactionsDependency.
/**
* Adds a dependency for the ComponentConfiguration on the remote transaction service if the EJB exposes at least one remote view
*/
protected void addRemoteTransactionsDependency() {
this.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration componentConfiguration) throws DeploymentUnitProcessingException {
if (this.hasRemoteView((EJBComponentDescription) description)) {
// add a dependency on local transaction service
componentConfiguration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {
@Override
public void configureDependency(ServiceBuilder<?> serviceBuilder, EJBComponentCreateService ejbComponentCreateService) throws DeploymentUnitProcessingException {
CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
// add dependency on the remote transaction service
serviceBuilder.requires(support.getCapabilityServiceName(REMOTE_TRANSACTION_SERVICE_CAPABILITY_NAME));
}
});
}
}
/**
* Returns true if the passed EJB component description has at least one remote view
* @param ejbComponentDescription
* @return
*/
private boolean hasRemoteView(final EJBComponentDescription ejbComponentDescription) {
final Set<ViewDescription> views = ejbComponentDescription.getViews();
for (final ViewDescription view : views) {
if (!(view instanceof EJBViewDescription)) {
continue;
}
final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
if (viewType == MethodIntf.REMOTE || viewType == MethodIntf.HOME) {
return true;
}
}
return false;
}
});
}
Aggregations