I'm very new to Quartz, but know 3 simple things which you have to have in order to make it work. These are jobs, triggers and scheduler.
Now, in our domino application we have to use it for refreshing a token.
I've created 3 basic classes for it.
The job:
public class RefreshEGRZTokenJob implements Job
{
public void execute(JobExecutionContext arg0) throws JobExecutionException
{
System.out.println("stub for refreshing a token");
}
}
The trigger and something like main
:
public class RefreshEGRZTokenExecutor
{
private static String REFRESH_TOKEN_JOB = "refreshTokenJob";
public static void executeAndScheduleRefreshToken(int timeInSeconds) throws SchedulerException
{
JobDetail job = JobBuilder.newJob(RefreshEGRZTokenJob.class)
.withIdentity(REFRESH_TOKEN_JOB).build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity(REFRESH_TOKEN_JOB)
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(timeInSeconds).repeatForever())
.build();
QuartzScheduler.getInstance().scheduleJob(job, trigger);
}
public static void pauseScheduler() throws SchedulerException
{
QuartzScheduler.getInstance().standby();
}
}
And the scheduler:
public final class QuartzScheduler
{
private static Scheduler quartzSchedulerInstance;
public static Scheduler getInstance() throws SchedulerException
{
if (quartzSchedulerInstance == null)
{
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
quartzSchedulerInstance = scheduler;
}
return quartzSchedulerInstance;
}
}
The call I make is from a button (in production it'll execute shortly after the user authorized)
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
ru.lanit.egrz.scheduler.RefreshEGRZTokenExecutor.executeAndScheduleRefreshToken(30);
}]]>
</xp:this.action>
</xp:eventHandler>
Well, quartz scheduler is initilized and the job is set but doesn't execute the job (I know this because if I press the same button twice, it'll give me an exeption that the job already exists).
I guess Domino's JVM doesn't let the scheduler run indefinitely.
The reason why I don't use standard IBM's agent is simple - it doesn't allow to use Java code in Code
section. You have to either import and duplicate everything you have so far or to compile it into jar and import. But if you decide to change anything in your sources you'll have to recompile the entire jar (with new source code) and re-import that.
Has anybody integrated Domino JVM and Quartz?
If so, please tell me the best practices and how to make it work.
Thanks in advance.