Search in sources :

Example 11 with DeploymentContextImpl

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);
    }
}
Also used : ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) NamingException(javax.naming.NamingException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Aggregations

DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)11 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)9 ActionReport (org.glassfish.api.ActionReport)7 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)7 IOException (java.io.IOException)6 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)6 File (java.io.File)5 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)5 Properties (java.util.Properties)4 Application (com.sun.enterprise.deployment.Application)2 ArrayList (java.util.ArrayList)2 Logger (java.util.logging.Logger)2 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)2 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)2 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)2 Transaction (org.jvnet.hk2.config.Transaction)2 HTMLActionReporter (com.sun.enterprise.admin.report.HTMLActionReporter)1 PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)1 Application (com.sun.enterprise.config.serverbeans.Application)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1