use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.
the class SessionBeanHomeProcessor method configureHome.
private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
homeView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
//loop over methods looking for create methods:
for (Method method : configuration.getProxyFactory().getCachedMethods()) {
if (method.getName().startsWith("create")) {
//we have a create method
if (ejbObjectView == null) {
throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
}
Method initMethod = resolveInitMethod(ejbComponentDescription, method);
final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
//add a dependency on the view to create
configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
final Class<?> ejbObjectClass;
try {
ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
}
final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
//add a dependency on the view to create
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
} else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
}
}
}
});
}
use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.
the class TimerServiceDeploymentProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
ServiceName defaultTimerPersistenceService = TimerPersistence.SERVICE_NAME.append(defaultTimerDataStore);
final Map<String, ServiceName> timerPersistenceServices = new HashMap<String, ServiceName>();
// if this is an EJB deployment then create an EJB module level TimerServiceRegistry which can be used by the timer services
// of all EJB components that belong to this EJB module.
final TimerServiceRegistry timerServiceRegistry = EjbDeploymentMarker.isEjbDeployment(deploymentUnit) ? new TimerServiceRegistry() : null;
if (ejbJarMetaData != null && ejbJarMetaData.getAssemblyDescriptor() != null) {
List<TimerServiceMetaData> timerService = ejbJarMetaData.getAssemblyDescriptor().getAny(TimerServiceMetaData.class);
if (timerService != null) {
for (TimerServiceMetaData data : timerService) {
if (data.getEjbName().equals("*")) {
defaultTimerPersistenceService = TimerPersistence.SERVICE_NAME.append(data.getDataStoreName());
} else {
timerPersistenceServices.put(data.getEjbName(), TimerPersistence.SERVICE_NAME.append(data.getDataStoreName()));
}
}
}
}
final ServiceName finalDefaultTimerPersistenceService = defaultTimerPersistenceService;
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription.isTimerServiceApplicable()) {
if (componentDescription.isTimerServiceRequired()) {
//the component has timeout methods, it needs a 'real' timer service
final String deploymentName;
if (moduleDescription.getDistinctName() == null || moduleDescription.getDistinctName().length() == 0) {
deploymentName = moduleDescription.getApplicationName() + "." + moduleDescription.getModuleName();
} else {
deploymentName = moduleDescription.getApplicationName() + "." + moduleDescription.getModuleName() + "." + moduleDescription.getDistinctName();
}
ROOT_LOGGER.debugf("Installing timer service for component %s", componentDescription.getComponentName());
componentDescription.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
final ServiceName invokerServiceName = ejbComponentDescription.getServiceName().append(TimedObjectInvokerImpl.SERVICE_NAME);
final TimedObjectInvokerImpl invoker = new TimedObjectInvokerImpl(deploymentName, module);
context.getServiceTarget().addService(invokerServiceName, invoker).addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, invoker.getEjbComponent()).install();
//install the timer create service
final ServiceName serviceName = componentDescription.getServiceName().append(TimerServiceImpl.SERVICE_NAME);
final TimerServiceImpl service = new TimerServiceImpl(ejbComponentDescription.getScheduleMethods(), serviceName, timerServiceRegistry);
final ServiceBuilder<javax.ejb.TimerService> createBuilder = context.getServiceTarget().addService(serviceName, service);
createBuilder.addDependency(TIMER_SERVICE_NAME, Timer.class, service.getTimerInjectedValue());
createBuilder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
createBuilder.addDependency(timerServiceThreadPool, ExecutorService.class, service.getExecutorServiceInjectedValue());
if (timerPersistenceServices.containsKey(ejbComponentDescription.getEJBName())) {
createBuilder.addDependency(timerPersistenceServices.get(ejbComponentDescription.getEJBName()), TimerPersistence.class, service.getTimerPersistence());
} else {
createBuilder.addDependency(finalDefaultTimerPersistenceService, TimerPersistence.class, service.getTimerPersistence());
}
createBuilder.addDependency(invokerServiceName, TimedObjectInvoker.class, service.getTimedObjectInvoker());
createBuilder.install();
ejbComponentDescription.setTimerService(service);
//inject the timer service directly into the start service
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(serviceName);
}
});
}
});
} else {
//the EJB is of a type that could have a timer service, but has no timer methods.
//just bind the non-functional timer service
componentDescription.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
final ServiceName nonFunctionalTimerServiceName = NonFunctionalTimerService.serviceNameFor(ejbComponentDescription);
final NonFunctionalTimerService nonFunctionalTimerService;
if (ejbComponentDescription instanceof StatefulComponentDescription) {
// for stateful beans, use a different error message that gets thrown from the NonFunctionalTimerService
nonFunctionalTimerService = new NonFunctionalTimerService(EjbLogger.ROOT_LOGGER.timerServiceMethodNotAllowedForSFSB(ejbComponentDescription.getComponentName()), timerServiceRegistry);
} else {
nonFunctionalTimerService = new NonFunctionalTimerService(EjbLogger.ROOT_LOGGER.ejbHasNoTimerMethods(), timerServiceRegistry);
}
// add the non-functional timer service as a MSC service
context.getServiceTarget().addService(nonFunctionalTimerServiceName, nonFunctionalTimerService).install();
// set the timer service in the EJB component
ejbComponentDescription.setTimerService(nonFunctionalTimerService);
// now we want the EJB component to depend on this non-functional timer service to start
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(nonFunctionalTimerServiceName);
}
});
}
});
}
}
}
}
use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.
the class RemoveOnCancelScheduledExecutorServiceBuilder method build.
@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
Supplier<ScheduledExecutorService> supplier = () -> {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
};
Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.
the class RaOperationUtil method installRaServicesAndDeployFromModule.
public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
final boolean resolveProperties = true;
final ServiceTarget serviceTarget = context.getServiceTarget();
final String moduleName;
//load module
String slot = "main";
if (fullModuleName.contains(":")) {
slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
} else {
moduleName = fullModuleName;
}
Module module;
try {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
}
URL path = module.getExportedResource("META-INF/ra.xml");
Closeable closable = null;
try {
VirtualFile child;
if (path.getPath().contains("!")) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
} else {
child = VFS.getChild(path.getPath().split("META-INF")[0]);
closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
}
//final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists())
return;
ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
RaNativeProcessor.process(deploymentRoot);
Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
ResourceRootIndexer.indexResourceRoot(resourceRoot);
Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
annotationIndexes.put(resourceRoot, index);
}
if (ironJacamarXmlDescriptor != null) {
ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
ironJacamarXmlDescriptor = null;
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
if (deployerService == null) {
ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null);
newControllers.add(builder.addDependency(raServiceName).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
String rarName = resourceAdapter.getArchive();
if (fullModuleName.equals(rarName)) {
ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
} catch (Exception e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
} finally {
if (closable != null) {
try {
closable.close();
} catch (IOException e) {
}
}
}
}
use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.
the class RaOperationUtil method installRaServices.
public static ServiceName installRaServices(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, final List<ServiceController<?>> newControllers) {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceController<?> resourceAdaptersService = context.getServiceRegistry(false).getService(ConnectorServices.RESOURCEADAPTERS_SERVICE);
if (resourceAdaptersService == null) {
newControllers.add(serviceTarget.addService(ConnectorServices.RESOURCEADAPTERS_SERVICE, new ResourceAdaptersService()).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, name);
final ServiceController<?> service = context.getServiceRegistry(true).getService(raServiceName);
if (service == null) {
ResourceAdapterService raService = new ResourceAdapterService(resourceAdapter, name);
ServiceBuilder builder = serviceTarget.addService(raServiceName, raService).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(ConnectorServices.RESOURCEADAPTERS_SERVICE, ResourceAdaptersService.ModifiableResourceAdaptors.class, raService.getResourceAdaptersInjector()).addDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, CopyOnWriteArrayListMultiMap.class, raService.getResourceAdaptersMapInjector());
// add dependency on security domain service if applicable for recovery config
for (ConnectionDefinition cd : resourceAdapter.getConnectionDefinitions()) {
Security security = cd.getSecurity();
if (security != null) {
final boolean elytronEnabled = (security instanceof SecurityMetadata && ((SecurityMetadata) security).isElytronEnabled());
if (security.getSecurityDomain() != null) {
if (!elytronEnabled) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(security.getSecurityDomain()));
} else {
builder.addDependency(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomain(), AuthenticationContext.class));
}
}
if (security.getSecurityDomainAndApplication() != null) {
if (!elytronEnabled) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(security.getSecurityDomainAndApplication()));
} else {
builder.addDependency(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomainAndApplication(), AuthenticationContext.class));
}
}
if (cd.getRecovery() != null && cd.getRecovery().getCredential() != null && cd.getRecovery().getCredential().getSecurityDomain() != null) {
if (!elytronEnabled) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(cd.getRecovery().getCredential().getSecurityDomain()));
} else {
builder.addDependency(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, cd.getRecovery().getCredential().getSecurityDomain(), AuthenticationContext.class));
}
}
}
}
if (resourceAdapter.getWorkManager() != null) {
final WorkManagerSecurity workManagerSecurity = resourceAdapter.getWorkManager().getSecurity();
if (workManagerSecurity != null) {
final boolean elytronEnabled = (workManagerSecurity instanceof org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) && ((org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) workManagerSecurity).isElytronEnabled();
final String securityDomainName = workManagerSecurity.getDomain();
if (securityDomainName != null) {
if (!elytronEnabled) {
builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
} else {
builder.addDependency(context.getCapabilityServiceName(ELYTRON_SECURITY_DOMAIN_CAPABILITY, securityDomainName, SecurityDomain.class));
}
}
}
}
newControllers.add(builder.install());
}
return raServiceName;
}
Aggregations