Use Quartz Scheduler in IBM Domino Application

懵懂的女人 提交于 2020-01-03 01:31:08

问题


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.


回答1:


I have created a plugin, you can find it here: https://github.com/hasselbach/domino-quartz

The feature project and the updatesite project are missing.

You have to install the plugin on the server and in the DDE and activate it in your XPages application.




回答2:


You have a set of hurdles to overcome here:

  1. Your scheduler needs to run "forever", so you need to run it from where it doesn't die. That place is an OSGi plugin. The place for your scheduler would be the activator class. something along those lines:
import java.util.logging.Logger;

import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator extends Plugin implements BundleActivator {

 @Override
    public void start(final BundleContext context) throws Exception {
       // Here you start your scheduler
    }

}
  1. You need to call it from somewhere (and that shouldn't be SSJS). So you would create a managed bean that can access the plugins activator. Put the bean code into the plug-in. Once you have defined it you can call the bean method in your button

  2. Your scheduler runs a token refresh. What is supposed to happen with the refreshed token?


Having said all this. You probably can get away with a much simpler solution (unless your token needs millisecond precision):

  • Create a managed bean for the session context (Each bean is individually instantiated per user).
  • In the bean have a method you will call from your button (or elsewhere) that kicks of a new thread. That thread sleeps for a while before you execute again. Check for a property of being shut down, so you can terminate gracefully.

Hope that helps



来源:https://stackoverflow.com/questions/59125483/use-quartz-scheduler-in-ibm-domino-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!