use of org.apache.openejb.quartz.JobDataMap 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.JobDataMap in project tomee by apache.
the class EjbTimerServiceImpl method schedule.
/**
* Called from TimerData and start when a timer should be scheduled with the java.util.Timer.
*
* @param timerData the timer to schedule
*/
public void schedule(final TimerData timerData) throws TimerStoreException {
start();
if (scheduler == null) {
throw new TimerStoreException("Scheduler is not configured properly");
}
timerData.setScheduler(scheduler);
final Trigger trigger = timerData.getTrigger();
if (null == trigger) {
try {
if (!scheduler.isShutdown()) {
log.warning("Failed to schedule: " + timerData.getInfo());
}
} catch (final SchedulerException e) {
// Ignore
}
}
final AbstractTrigger<?> atrigger;
if (trigger instanceof AbstractTrigger) {
// is the case
atrigger = (AbstractTrigger<?>) trigger;
atrigger.setJobName(OPENEJB_TIMEOUT_JOB_NAME);
atrigger.setJobGroup(OPENEJB_TIMEOUT_JOB_GROUP_NAME);
} else {
throw new OpenEJBRuntimeException("the trigger was not an AbstractTrigger - Should not be possible: " + trigger);
}
final JobDataMap triggerDataMap = trigger.getJobDataMap();
triggerDataMap.put(EjbTimeoutJob.EJB_TIMERS_SERVICE, this);
triggerDataMap.put(EjbTimeoutJob.TIMER_DATA, timerData);
try {
final TriggerKey triggerKey = new TriggerKey(atrigger.getName(), atrigger.getGroup());
if (!scheduler.checkExists(triggerKey)) {
scheduler.scheduleJob(trigger);
} else if (Trigger.TriggerState.PAUSED.equals(scheduler.getTriggerState(triggerKey))) {
// redeployment
// more consistent in the semantic than a resume but resume would maybe be more relevant here
scheduler.unscheduleJob(triggerKey);
scheduler.scheduleJob(trigger);
}
} catch (final Exception e) {
// TODO Any other actions we could do ?
log.error("Could not schedule timer " + timerData, e);
}
}
use of org.apache.openejb.quartz.JobDataMap in project tomee by apache.
the class EjbTimerImplSerializableTest method jobDataMapSerial.
@Test
public void jobDataMapSerial() throws Exception {
final CalendarTimerData data = timerData();
final EjbTimerServiceImpl timerService = (EjbTimerServiceImpl) timerService();
data.setScheduler(timerService.getScheduler());
// small hack for the test
final Field preventSynch = TimerData.class.getDeclaredField("synchronizationRegistered");
preventSynch.setAccessible(true);
preventSynch.set(data, true);
data.newTimer();
final AbstractTrigger<?> trigger = (AbstractTrigger<?>) data.getTrigger();
trigger.setJobName("my-job");
trigger.setJobGroup("my-group");
final JobDataMap triggerDataMap = trigger.getJobDataMap();
triggerDataMap.put(EjbTimeoutJob.EJB_TIMERS_SERVICE, timerService);
triggerDataMap.put(EjbTimeoutJob.TIMER_DATA, data);
final byte[] serial = serialize(triggerDataMap);
final JobDataMap map = (JobDataMap) deserialize(serial);
assertTrue(map.containsKey(EjbTimeoutJob.EJB_TIMERS_SERVICE));
assertTrue(map.containsKey(EjbTimeoutJob.TIMER_DATA));
}
use of org.apache.openejb.quartz.JobDataMap in project tomee by apache.
the class EjbTimeoutJob method execute.
@Override
public void execute(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
final JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
final EjbTimerServiceImpl ejbTimerService = (EjbTimerServiceImpl) jobDataMap.get(EJB_TIMERS_SERVICE);
final TimerData timerData = (TimerData) jobDataMap.get(TIMER_DATA);
ejbTimerService.ejbTimeout(timerData);
}
Aggregations