use of org.jberet.spi.ArtifactFactory in project wildfly by wildfly.
the class BatchEnvironmentProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
BatchLogger.LOGGER.tracef("Processing deployment '%s' for the batch environment.", deploymentUnit.getName());
// Configure and attach the job resolver for all deployments
final WildFlyJobXmlResolver jobXmlResolver = WildFlyJobXmlResolver.forDeployment(deploymentUnit);
// Skip the rest of the processing for EAR's, only sub-deployments need an environment configured
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit))
return;
// Get the class loader
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ClassLoader moduleClassLoader = module.getClassLoader();
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
JobRepository jobRepository = null;
String jobRepositoryName = null;
String dataSourceName = null;
String jobExecutorName = null;
Boolean restartJobsOnResume = null;
// Check for a deployment descriptor
BatchEnvironmentMetaData metaData = deploymentUnit.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
if (metaData == null) {
// Check the parent
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
metaData = parent.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
}
}
if (metaData != null) {
jobRepository = metaData.getJobRepository();
jobRepositoryName = metaData.getJobRepositoryName();
dataSourceName = metaData.getDataSourceName();
jobExecutorName = metaData.getExecutorName();
restartJobsOnResume = metaData.getRestartJobsOnResume();
}
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final String deploymentName = deploymentUnit.getName();
// Create the job operator service used interact with a deployments batch job
final JobOperatorService jobOperatorService = new JobOperatorService(restartJobsOnResume, deploymentName, jobXmlResolver);
// Create the batch environment
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final NamespaceContextSelector namespaceContextSelector = eeModuleDescription == null ? null : eeModuleDescription.getNamespaceContextSelector();
final BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, jobXmlResolver, deploymentName, namespaceContextSelector);
final ServiceBuilder<SecurityAwareBatchEnvironment> serviceBuilder = serviceTarget.addService(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), service);
// Add a dependency to the thread-pool
if (jobExecutorName != null) {
// Register the named thread-pool capability
serviceBuilder.addDependency(Capabilities.THREAD_POOL_CAPABILITY.getCapabilityServiceName(jobExecutorName), JobExecutor.class, service.getJobExecutorInjector());
}
// Register the required services
serviceBuilder.addDependency(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getCapabilityServiceName(), BatchConfiguration.class, service.getBatchConfigurationInjector());
// Ensure local transaction support is started
serviceBuilder.requires(support.getCapabilityServiceName(Capabilities.LOCAL_TRANSACTION_PROVIDER_CAPABILITY));
final ServiceName artifactFactoryServiceName = BatchServiceNames.batchArtifactFactoryServiceName(deploymentUnit);
final ArtifactFactoryService artifactFactoryService = new ArtifactFactoryService();
final ServiceBuilder<ArtifactFactory> artifactFactoryServiceBuilder = serviceTarget.addService(artifactFactoryServiceName, artifactFactoryService);
// Register the bean manager if this is a Jakarta Contexts and Dependency Injection deployment
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
if (api.isPartOfWeldDeployment(deploymentUnit)) {
BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
api.addBeanManagerService(deploymentUnit, artifactFactoryServiceBuilder, artifactFactoryService.getBeanManagerInjector());
}
}
artifactFactoryServiceBuilder.install();
serviceBuilder.addDependency(artifactFactoryServiceName, WildFlyArtifactFactory.class, service.getArtifactFactoryInjector());
if (jobRepositoryName != null) {
// Register a named job repository
serviceBuilder.addDependency(support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), jobRepositoryName), JobRepository.class, service.getJobRepositoryInjector());
} else if (dataSourceName != null) {
// Register a jdbc job repository with data-source
final JdbcJobRepositoryService jdbcJobRepositoryService = new JdbcJobRepositoryService();
final ServiceName jobRepositoryServiceName = support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), deploymentName);
final ServiceBuilder<JobRepository> jobRepositoryServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(jobRepositoryServiceName, jdbcJobRepositoryService), jdbcJobRepositoryService.getExecutorServiceInjector()).addDependency(support.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY, dataSourceName), DataSource.class, jdbcJobRepositoryService.getDataSourceInjector());
jobRepositoryServiceBuilder.install();
serviceBuilder.addDependency(jobRepositoryServiceName, JobRepository.class, service.getJobRepositoryInjector());
} else if (jobRepository != null) {
// Use the job repository as defined in the deployment descriptor
service.getJobRepositoryInjector().setValue(new ImmediateValue<>(jobRepository));
}
if (rcPresent) {
serviceBuilder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjector());
}
// Install the batch environment service
serviceBuilder.install();
// Install the JobOperatorService
ServiceName jobOperatorServiceName = BatchServiceNames.jobOperatorServiceName(deploymentUnit);
Services.addServerExecutorDependency(serviceTarget.addService(jobOperatorServiceName, jobOperatorService).addDependency(support.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName()), BatchConfiguration.class, jobOperatorService.getBatchConfigurationInjector()).addDependency(support.getCapabilityServiceName(Capabilities.SUSPEND_CONTROLLER_CAPABILITY), SuspendController.class, jobOperatorService.getSuspendControllerInjector()).addDependency(support.getCapabilityServiceName(Capabilities.PROCESS_STATE_NOTIFIER_CAPABILITY), ProcessStateNotifier.class, jobOperatorService.getProcessStateInjector()).addDependency(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), SecurityAwareBatchEnvironment.class, jobOperatorService.getBatchEnvironmentInjector()), jobOperatorService.getExecutorServiceInjector()).install();
// Add the JobOperatorService to the deployment unit
deploymentUnit.putAttachment(BatchAttachments.JOB_OPERATOR, jobOperatorService);
deploymentUnit.addToAttachmentList(DEPLOYMENT_COMPLETE_SERVICES, jobOperatorServiceName);
// Add the JobOperator to the context selector
selector.registerContext(moduleClassLoader, JobOperatorContext.create(jobOperatorService));
}
}
Aggregations