use of org.jboss.as.ee.component.ComponentConfigurator in project wildfly by wildfly.
the class AsynchronousMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
final SessionBeanMetaData data = description.getDescriptorData();
final boolean elytronSecurityDomain = description.getSecurityDomainServiceName() != null;
if (data instanceof SessionBean31MetaData) {
final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
if (async != null) {
for (AsyncMethodMetaData method : async) {
final Collection<Method> methods = MethodResolutionUtils.resolveMethods(method.getMethodName(), method.getMethodParams(), componentClass, deploymentReflectionIndex);
for (final Method m : methods) {
description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
}
}
}
}
if (!description.getAsynchronousClasses().isEmpty() || !description.getAsynchronousMethods().isEmpty()) {
// setup a dependency on the executor service
description.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final SessionBeanComponentCreateService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(asynchronousThreadPoolService, ExecutorService.class, service.getAsyncExecutorService());
}
});
}
});
for (final ViewDescription view : description.getViews()) {
final EJBViewDescription ejbView = (EJBViewDescription) view;
ejbView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
// we need the component method to get the correct declaring class
final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method);
if (componentMethod != null) {
if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
addAsyncInterceptor(configuration, method, elytronSecurityDomain);
configuration.addAsyncMethod(method);
} else {
MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
if (componentDescription.getAsynchronousMethods().contains(id)) {
addAsyncInterceptor(configuration, method, elytronSecurityDomain);
configuration.addAsyncMethod(method);
}
}
}
}
}
});
}
}
}
use of org.jboss.as.ee.component.ComponentConfigurator in project wildfly by wildfly.
the class StartupAwaitDeploymentUnitProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component instanceof EJBComponentDescription) {
component.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
for (ViewConfiguration view : configuration.getViews()) {
EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
if (INTFS.contains(ejbView.getMethodIntf())) {
ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
}
}
}
});
}
}
}
use of org.jboss.as.ee.component.ComponentConfigurator in project wildfly by wildfly.
the class SessionBeanMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
if (SessionBean.class.isAssignableFrom(componentClass)) {
// add the setSessionContext(SessionContext) method invocation interceptor for session bean implementing the javax.ejb.SessionContext
// interface
description.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
if (SessionBean.class.isAssignableFrom(configuration.getComponentClass())) {
configuration.addPostConstructInterceptor(SessionBeanSetSessionContextMethodInvocationInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.EJB_SET_CONTEXT_METHOD_INVOCATION_INTERCEPTOR);
}
}
});
// now lifecycle callbacks
final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate");
final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate");
boolean ejbActivate = false, ejbPassivate = false, ejbRemove = false;
Class<?> c = componentClass;
while (c != null && c != Object.class) {
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
if (!ejbActivate) {
final Method method = index.getMethod(ejbActivateIdentifier);
if (method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPostActivate(ejbActivateIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbActivate = true;
}
}
if (!ejbPassivate) {
final Method method = index.getMethod(ejbPassivateIdentifier);
if (method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPrePassivate(ejbPassivateIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbPassivate = true;
}
}
if (!ejbRemove) {
final Method method = index.getMethod(ejbRemoveIdentifier);
if (method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPreDestroy(ejbRemoveIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbRemove = true;
}
}
c = c.getSuperclass();
}
}
}
use of org.jboss.as.ee.component.ComponentConfigurator in project wildfly by wildfly.
the class SingletonComponentDescription method createConfiguration.
@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
ComponentConfiguration singletonComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
// setup the component create service
singletonComponentConfiguration.setComponentCreateServiceFactory(new SingletonComponentCreateServiceFactory(this.isInitOnStartup(), dependsOn));
final String definedSecurityDomain = getDefinedSecurityDomain();
final boolean securityRequired = hasBeanLevelSecurityMetadata();
if (securityRequired) {
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
String contextID = deploymentUnit.getName();
if (deploymentUnit.getParent() != null) {
contextID = deploymentUnit.getParent().getName() + "!" + contextID;
}
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
if (getSecurityDomainServiceName() != null) {
ejbComponentDescription.setSecurityRequired(securityRequired);
final HashMap<Integer, InterceptorFactory> elytronInterceptorFactories = getElytronInterceptorFactories(contextID, ejbComponentDescription.requiresJacc(), false);
elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> configuration.addPostConstructInterceptor(elytronInterceptorFactory, priority));
} else if (definedSecurityDomain != null) {
throw ROOT_LOGGER.legacySecurityUnsupported(definedSecurityDomain);
}
}
});
}
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
if (isInitOnStartup()) {
final StartupCountdown startupCountdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new StartupCountDownInterceptor(startupCountdown)), InterceptorOrder.ComponentPostConstruct.STARTUP_COUNTDOWN_INTERCEPTOR);
}
}
});
if (getTransactionManagementType().equals(TransactionManagementType.CONTAINER)) {
// we need to add the transaction interceptor to the lifecycle methods
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
}
});
} else {
// add the bmt interceptor
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addPostConstructInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
configuration.addPreDestroyInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
// add the bmt interceptor factory
configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
}
});
}
return singletonComponentConfiguration;
}
use of org.jboss.as.ee.component.ComponentConfigurator in project wildfly by wildfly.
the class MessageDrivenComponentDescription method createConfiguration.
@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
final ComponentConfiguration mdbComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
// setup the component create service
final Class<?> messageListenerInterface;
try {
messageListenerInterface = Class.forName(getMessageListenerInterfaceName(), true, moduleClassLoader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
mdbComponentConfiguration.setComponentCreateServiceFactory(new MessageDrivenComponentCreateServiceFactory(messageListenerInterface));
final MessageDrivenComponentDescription mdbComponentDescription = (MessageDrivenComponentDescription) mdbComponentConfiguration.getComponentDescription();
// setup a configurator to inject the PoolConfig in the MessageDrivenComponentCreateService
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
// get CapabilitySupport to resolve service names
final CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT);
MessageDrivenComponentDescription mdbDescription = (MessageDrivenComponentDescription) description;
configuration.getCreateDependencies().add(new DependencyConfigurator<Service<Component>>() {
@Override
public void configureDependency(ServiceBuilder<?> serviceBuilder, Service<Component> service) throws DeploymentUnitProcessingException {
// add any dependencies here
final MessageDrivenComponentCreateService mdbComponentCreateService = (MessageDrivenComponentCreateService) service;
final String poolName = mdbComponentDescription.getPoolConfigName();
// If the default mdb pool config itself is not configured, then pooling is disabled for the bean
if (poolName == null) {
if (mdbComponentDescription.isDefaultMdbPoolAvailable()) {
ServiceName defaultPoolConfigServiceName = support.getCapabilityServiceName(DEFAULT_MDB_POOL_CONFIG_CAPABILITY_NAME);
serviceBuilder.addDependency(defaultPoolConfigServiceName, PoolConfig.class, mdbComponentCreateService.getPoolConfigInjector());
}
} else {
// pool name has been explicitly set so the pool config is a required dependency
ServiceName poolConfigServiceName = support.getCapabilityServiceName(STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, poolName);
serviceBuilder.addDependency(poolConfigServiceName, PoolConfig.class, mdbComponentCreateService.getPoolConfigInjector());
}
}
});
}
});
// set up a configurator to inject ResourceAdapterService dependencies into the MessageDrivenComponentCreateService
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
// get CapabilitySupport to resolve service names
final CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT);
configuration.getCreateDependencies().add(new DependencyConfigurator<MessageDrivenComponentCreateService>() {
@Override
public void configureDependency(ServiceBuilder<?> serviceBuilder, MessageDrivenComponentCreateService service) throws DeploymentUnitProcessingException {
final ServiceName raServiceName = ConnectorServices.getResourceAdapterServiceName(MessageDrivenComponentDescription.this.resourceAdapterName);
// add the dependency on the RA service
serviceBuilder.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, service.getResourceAdapterRepositoryInjector());
serviceBuilder.addDependency(raServiceName, ResourceAdapter.class, service.getResourceAdapterInjector());
}
});
}
});
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final ServiceName suspendControllerName = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName("org.wildfly.server.suspend-controller");
configuration.getCreateDependencies().add(new DependencyConfigurator<MessageDrivenComponentCreateService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final MessageDrivenComponentCreateService mdbComponentCreateService) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(suspendControllerName, SuspendController.class, mdbComponentCreateService.getSuspendControllerInjectedValue());
}
});
}
});
// add the BMT interceptor
if (TransactionManagementType.BEAN.equals(this.getTransactionManagementType())) {
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
// add the bmt interceptor factory
configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
}
});
} else {
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
}
});
}
return mdbComponentConfiguration;
}
Aggregations