use of org.jboss.as.ee.component.EEModuleDescription 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.as.ee.component.EEModuleDescription in project wildfly by wildfly.
the class TimerServiceJndiBindingProcessor method processComponentConfig.
@Override
protected void processComponentConfig(DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, CompositeIndex index, ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
if (!(componentDescription instanceof EJBComponentDescription)) {
// Only process EJBs
return;
}
// if the EJB is packaged in a .war, then we need to bind the java:comp/TimerService only once for the entire module
if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
// get the module description
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
// the java:module/TimerService binding configuration
// Note that we bind to java:module/TimerService since it's a .war. End users can still lookup java:comp/TimerService
// and that will internally get translated to java:module/TimerService for .war, since java:comp == java:module in
// a web ENC. So binding to java:module/TimerService is OK.
final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:module/TimerService", new TimerServiceBindingSource());
moduleDescription.getBindingConfigurations().add(timerServiceBinding);
} else {
// EJB packaged outside of a .war. So process normally.
// add the binding configuration to the component description
final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:comp/TimerService", new TimerServiceBindingSource());
componentDescription.getBindingConfigurations().add(timerServiceBinding);
}
}
use of org.jboss.as.ee.component.EEModuleDescription in project wildfly by wildfly.
the class EjbResourceInjectionAnnotationProcessor method deploy.
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer);
if (annotationTarget instanceof FieldInfo) {
processField(deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof MethodInfo) {
processMethod(deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof ClassInfo) {
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
}
final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
for (AnnotationInstance annotation : ejbsAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof ClassInfo) {
final AnnotationValue annotationValue = annotation.value();
final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer);
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
} else {
throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
}
}
}
use of org.jboss.as.ee.component.EEModuleDescription in project wildfly by wildfly.
the class IIOPJndiBindingProcessor method deploy.
@Override
public void deploy(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);
if (moduleDescription == null) {
return;
}
//do not bind if jacORB not present
if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
return;
}
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
bindService(serviceTarget, moduleContextServiceName, module);
}
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component.getNamingMode() == ComponentNamingMode.CREATE) {
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName());
bindService(serviceTarget, compContextServiceName, module);
}
}
}
use of org.jboss.as.ee.component.EEModuleDescription in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Only process EJB deployments
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
if (componentDescriptions != null) {
for (ComponentDescription componentDescription : componentDescriptions) {
// process only EJB session beans
if (componentDescription instanceof SessionBeanComponentDescription) {
this.setupJNDIBindings((EJBComponentDescription) componentDescription, deploymentUnit);
}
}
}
if (appclient) {
for (final ComponentDescription component : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
this.setupJNDIBindings((EJBComponentDescription) component, deploymentUnit);
}
}
}
Aggregations