use of org.jboss.as.ejb3.component.TimerServiceRegistry 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);
// support for using capabilities to resolve service names
CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
ServiceName defaultTimerPersistenceService = getTimerPersistenceServiceName(capabilityServiceSupport, 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;
// determine the per-EJB timer persistence service names required
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 = getTimerPersistenceServiceName(capabilityServiceSupport, data.getDataStoreName());
} else {
timerPersistenceServices.put(data.getEjbName(), getTimerPersistenceServiceName(capabilityServiceSupport, data.getDataStoreName()));
}
}
}
}
final ServiceName finalDefaultTimerPersistenceService = defaultTimerPersistenceService;
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
// set up the per-EJB timer persistence service dependencies
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;
// install the timed object invoker service
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 for this EJB
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(capabilityServiceSupport.getCapabilityServiceName(TimerServiceResourceDefinition.TIMER_SERVICE_CAPABILITY_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.requires(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.requires(nonFunctionalTimerServiceName);
}
});
}
});
}
}
}
}
use of org.jboss.as.ejb3.component.TimerServiceRegistry in project wildfly by wildfly.
the class TimerServiceImpl method start.
@Override
public synchronized void start(final StartContext context) throws StartException {
if (EJB3_TIMER_LOGGER.isDebugEnabled()) {
EJB3_TIMER_LOGGER.debug("Starting timerservice for timedObjectId: " + getInvoker().getTimedObjectId());
}
final EJBComponent component = ejbComponentInjectedValue.getValue();
this.tsr = component.getTransactionSynchronizationRegistry();
final TimedObjectInvoker invoker = timedObjectInvoker.getValue();
if (invoker == null) {
throw EJB3_TIMER_LOGGER.invokerIsNull();
}
started = true;
timerPersistence.getValue().timerDeployed(timedObjectInvoker.getValue().getTimedObjectId());
// register ourselves to the TimerServiceRegistry (if any)
if (timerServiceRegistry != null) {
timerServiceRegistry.registerTimerService(this);
}
listenerHandle = timerPersistence.getValue().registerChangeListener(getInvoker().getTimedObjectId(), new TimerRefreshListener());
}
Aggregations