use of org.apache.openejb.quartz.Scheduler in project tomee by apache.
the class QuartzResourceAdapter method stop.
@Override
public void stop() {
final Scheduler s = scheduler.getAndSet(null);
if (null != s) {
if (null != startThread.get()) {
startThread.get().interrupt();
}
long timeout = SystemInstance.get().getOptions().get(QuartzResourceAdapter.OPENEJB_QUARTZ_TIMEOUT, 10000L);
if (timeout < 1000L) {
timeout = 1000L;
}
if (timeout > 60000L) {
timeout = 60000L;
}
final CountDownLatch shutdownWait = new CountDownLatch(1);
Thread stopThread = new Thread("Quartz Scheduler Requested Stop") {
@Override
public void run() {
try {
s.getListenerManager().addSchedulerListener(new SchedulerListenerSupport() {
@Override
public void schedulerShutdown() {
shutdownWait.countDown();
}
});
// Shutdown, but give running jobs a chance to complete.
// User scheduled jobs should really implement InterruptableJob
s.shutdown(true);
} catch (final Throwable e) {
QuartzResourceAdapter.this.ex.set(e);
shutdownWait.countDown();
}
}
};
stopThread.setDaemon(true);
stopThread.start();
boolean stopped = false;
try {
stopped = shutdownWait.await(timeout, TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
// Ignore
}
try {
if (!stopped || !s.isShutdown()) {
stopThread = new Thread("Quartz Scheduler Forced Stop") {
@Override
public void run() {
try {
// Force a shutdown without waiting for jobs to complete.
s.shutdown(false);
Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources").warning("Forced Quartz stop - Jobs may be incomplete");
} catch (final Throwable e) {
QuartzResourceAdapter.this.ex.set(e);
}
}
};
stopThread.setDaemon(true);
stopThread.start();
try {
// Give the forced shutdown a chance to complete
stopThread.join(timeout);
} catch (final InterruptedException e) {
// Ignore
}
}
} catch (final Throwable e) {
ex.set(e);
}
}
this.bootstrapContext.set(null);
if (null != ex.get()) {
Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources").warning("Error stopping Quartz Scheduler", ex.get());
} else {
Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources").info("Stopped Quartz Scheduler");
}
}
use of org.apache.openejb.quartz.Scheduler in project tomee by apache.
the class QuartzResourceAdapter method endpointActivation.
@Override
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
final Scheduler s = scheduler.get();
if (null == s) {
throw new ResourceException("Quartz Scheduler is not available");
}
try {
final JobSpec spec = (JobSpec) activationSpec;
final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
spec.setEndpoint(endpoint);
final Job job = (Job) endpoint;
final JobDataMap jobDataMap = spec.getDetail().getJobDataMap();
jobDataMap.put(Data.class.getName(), new Data(job));
s.scheduleJob(spec.getDetail(), spec.getTrigger());
} catch (final SchedulerException e) {
throw new ResourceException("Failed to schedule job", e);
}
}
use of org.apache.openejb.quartz.Scheduler in project tomee by apache.
the class QuartzResourceAdapter method endpointDeactivation.
@Override
public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
final Scheduler s = scheduler.get();
if (null == s) {
throw new IllegalStateException("Quartz Scheduler is not available");
}
JobSpec spec = null;
try {
spec = (JobSpec) activationSpec;
s.deleteJob(spec.jobKey());
} catch (final SchedulerException e) {
throw new IllegalStateException("Failed to delete job", e);
} finally {
if (null != spec) {
spec.getEndpoint().release();
}
}
}
use of org.apache.openejb.quartz.Scheduler in project tomee by apache.
the class TimerData method stop.
public void stop() {
if (trigger != null) {
try {
final Scheduler s = timerService.getScheduler();
if (!s.isShutdown()) {
if (!isPersistent()) {
s.unscheduleJob(trigger.getKey());
} else {
s.pauseTrigger(trigger.getKey());
}
}
} catch (final SchedulerException e) {
throw new EJBException("fail to cancel the timer", e);
}
}
cancelled = true;
stopped = true;
}
use of org.apache.openejb.quartz.Scheduler in project tomee by apache.
the class TimerData method cancel.
public void cancel() {
if (stopped) {
return;
}
timerService.cancelled(TimerData.this);
if (trigger != null) {
try {
final Scheduler s = timerService.getScheduler();
if (!s.isShutdown()) {
s.unscheduleJob(trigger.getKey());
}
} catch (final SchedulerException e) {
throw new EJBException("fail to cancel the timer", e);
}
}
cancelled = true;
try {
registerTimerDataSynchronization();
} catch (final TimerStoreException e) {
throw new EJBException("Failed to register timer data synchronization on cancel", e);
}
}
Aggregations