use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class BatchRuntimeHelper method event.
@Override
public void event(Event event) {
try {
if (event.is(EventTypes.SERVER_READY)) {
for (String appName : applicationRegistry.getAllApplicationNames()) {
ApplicationInfo applicationInfo = applicationRegistry.get(appName);
registerIfBatchJobsDirExists(applicationInfo);
}
} else if (event.is(Deployment.APPLICATION_LOADED)) {
if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
registerIfBatchJobsDirExists(applicationInfo);
}
}
if (event.is(Deployment.UNDEPLOYMENT_SUCCESS)) {
if (event.hook() != null && event.hook() instanceof DeploymentContextImpl) {
DeploymentContextImpl deploymentContext = (DeploymentContextImpl) event.hook();
Properties props = deploymentContext.getAppProps();
String appName = props.getProperty("defaultAppName");
if (!Boolean.parseBoolean(props.getProperty("retain-batch-jobs"))) {
String tagName = config.getName() + ":" + appName;
ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
try {
// set TCCL to ensure loading of the Joboperator
Thread.currentThread().setContextClassLoader(BatchSPIManager.class.getClassLoader());
BatchSPIManager batchSPIManager = BatchSPIManager.getInstance();
if (batchSPIManager.getBatchJobUtil() == null && tagNamesRequiringCleanup.contains(tagName)) {
// Force initialization of BatchRuntime
BatchRuntime.getJobOperator();
}
if (batchSPIManager.getBatchJobUtil() != null) {
batchSPIManager.getBatchJobUtil().purgeOwnedRepositoryData(tagName);
tagNamesRequiringCleanup.remove(tagName);
}
} catch (Exception ex) {
logger.log(Level.FINE, "Error while purging jobs", ex);
} finally {
Thread.currentThread().setContextClassLoader(prevCL);
}
}
}
}
} catch (Exception ex) {
logger.log(Level.FINE, "Exception while handling event: " + event, ex);
}
}
Aggregations