use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.
the class AbstractIntegrationProcessorJAXWS method registerView.
static ServiceName registerView(final ComponentDescription componentDescription, final String componentClassName) {
final ViewDescription pojoView = new ViewDescription(componentDescription, componentClassName);
componentDescription.getViews().add(pojoView);
pojoView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
// add WS POJO component instance associating interceptor
configuration.addViewInterceptor(WSComponentInstanceAssociationInterceptor.FACTORY, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
}
});
return pojoView.getServiceName();
}
use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.
the class ManagedBeanAnnotationProcessor method deploy.
/**
* Check the deployment annotation index for all classes with the @ManagedBean annotation. For each class with the
* annotation, collect all the required information to create a managed bean instance, and attach it to the context.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
if (compositeIndex == null) {
return;
}
final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
if (instances == null || instances.isEmpty()) {
return;
}
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
if (!(target instanceof ClassInfo)) {
throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target);
}
final ClassInfo classInfo = (ClassInfo) target;
// skip if it's not a valid managed bean class
if (!assertManagedBeanClassValidity(classInfo)) {
continue;
}
final String beanClassName = classInfo.name().toString();
// Get the managed bean name from the annotation
final AnnotationValue nameValue = instance.value();
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString());
final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
// Add the view
ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
viewDescription.getConfigurators().addFirst(new ViewConfigurator() {
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
// Add MB association interceptors
configuration.addClientPostConstructInterceptor(ManagedBeanCreateInterceptor.FACTORY, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
configuration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
}
});
viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
componentDescription.getViews().add(viewDescription);
moduleDescription.addComponent(componentDescription);
// register an EEResourceReferenceProcessor which can process @Resource references to this managed bean.
registry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
}
}
use of org.jboss.as.server.deployment.DeploymentPhaseContext in project wildfly by wildfly.
the class EEConcurrentContextProcessor method processComponentDescription.
private void processComponentDescription(final ComponentDescription componentDescription) {
final ComponentConfigurator componentConfigurator = new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final ConcurrentContext concurrentContext = configuration.getConcurrentContext();
// setup context
setupConcurrentContext(concurrentContext, description.getApplicationName(), description.getModuleName(), description.getComponentName(), configuration.getModuleClassLoader(), configuration.getNamespaceContextSelector(), context.getDeploymentUnit(), context.getServiceTarget());
// add the interceptor which manages the concurrent context
final ConcurrentContextInterceptor interceptor = new ConcurrentContextInterceptor(concurrentContext);
final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(interceptor);
configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.CONCURRENT_CONTEXT);
configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.CONCURRENT_CONTEXT);
if (description.isPassivationApplicable()) {
configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.CONCURRENT_CONTEXT);
configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.CONCURRENT_CONTEXT);
}
configuration.addComponentInterceptor(interceptorFactory, InterceptorOrder.Component.CONCURRENT_CONTEXT, false);
}
};
componentDescription.getConfigurators().add(componentConfigurator);
}
use of org.jboss.as.server.deployment.DeploymentPhaseContext 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.as.server.deployment.DeploymentPhaseContext 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);
}
});
}
});
}
}
}
}
Aggregations