use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.
the class JobCleanUpService method scheduleCleanUp.
/**
* This will schedule a cleanup of expired jobs based on configurable values
*/
private void scheduleCleanUp() {
if (managedJobConfig == null) {
managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
bean.addListener(this);
}
logger.fine(KernelLoggerInfo.schedulingCleanup);
// default values to 20 minutes for delayBetweenRuns and initialDelay
long delayBetweenRuns = 1200000;
long initialDelay = 1200000;
delayBetweenRuns = jobManagerService.convert(managedJobConfig.getPollInterval());
initialDelay = jobManagerService.convert(managedJobConfig.getInitialDelay());
ScheduledFuture<?> cleanupFuture = scheduler.scheduleAtFixedRate(new JobCleanUpTask(), initialDelay, delayBetweenRuns, TimeUnit.MILLISECONDS);
}
use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.
the class JobManagerService method getExpiredJobs.
/**
* This will return a list of jobs which have crossed the JOBS_RETENTION_PERIOD
* and need to be purged
* @return list of jobs to be purged
*/
public ArrayList<JobInfo> getExpiredJobs(File file) {
ArrayList<JobInfo> expiredJobs = new ArrayList<JobInfo>();
synchronized (file) {
JobInfos jobInfos = getCompletedJobs(file);
for (JobInfo job : jobInfos.getJobInfoList()) {
long executedTime = job.commandExecutionDate;
long currentTime = System.currentTimeMillis();
long jobsRetentionPeriod = 86400000;
managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
jobsRetentionPeriod = convert(managedJobConfig.getJobRetentionPeriod());
if (currentTime - executedTime > jobsRetentionPeriod && (job.state.equals(AdminCommandState.State.COMPLETED.name()) || job.state.equals(AdminCommandState.State.REVERTED.name()))) {
expiredJobs.add(job);
}
}
}
return expiredJobs;
}
use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.
the class ConfigureManagedJobs method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
ManagedJobConfig managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
if (managedJobConfig == null) {
logger.warning(KernelLoggerInfo.getFailManagedJobConfig);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(KernelLoggerInfo.getLogger().getResourceBundle().getString(KernelLoggerInfo.getFailManagedJobConfig));
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<ManagedJobConfig>() {
@Override
public Object run(ManagedJobConfig param) throws PropertyVetoException, TransactionFailure {
if (inMemoryRetentionPeriod != null)
param.setInMemoryRetentionPeriod(inMemoryRetentionPeriod);
if (jobRetentionPeriod != null)
param.setJobRetentionPeriod(jobRetentionPeriod);
if (pollInterval != null)
param.setPollInterval(pollInterval);
if (initialDelay != null)
param.setInitialDelay(initialDelay);
return param;
}
}, managedJobConfig);
} catch (TransactionFailure e) {
logger.warning(KernelLoggerInfo.configFailManagedJobConfig);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.
the class JobCleanUpService method postConstruct.
@Override
public void postConstruct() {
logger.log(Level.FINE, KernelLoggerInfo.initializingJobCleanup);
scheduler = Executors.newScheduledThreadPool(10, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread result = new Thread(r);
result.setDaemon(true);
return result;
}
});
if (Version.getFullVersion().contains("Micro")) {
// if Micro we don't have any jobs to cleanup
return;
}
managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
bean.addListener(this);
scheduleCleanUp();
}
Aggregations