Maybe I don't understand this right, but it's not documented with a sample, so I had to play with it. I created a class that will be used as a XOTS tasklet:
package org.sutol.demo.xots;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import org.openntf.domino.xots.Tasklet;
import org.openntf.domino.xsp.XspOpenLogUtil;
@Tasklet(session = Tasklet.Session.CLONE, schedule = "cron:0 */1 00-23 * * *")
public class PeriodicTask implements Callable<String> {
public String call() {
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss");
String result = "Message from PeriodicTask: " + formatter.format(now.getTime());
createOutput(result);
return result;
}
private void createOutput(String msg) {
System.out.println(msg);
XspOpenLogUtil.logEvent(null, msg, Level.INFO, null);
}
}
This class is used when I use the schedule method of the Xots object:
public static void testPeriodicTasklet() {
Xots.getService().schedule(new PeriodicTask(), 1, TimeUnit.SECONDS);
}
There are a couple of problems here:
- the tasklet is executed only once, not every second as I determined
- I get an error message on the server console
Error message on server console:
08.11.2015 18:59:39 HTTP JVM: ### LOGSTART
08.11.2015 18:59:39 HTTP JVM: Message from PeriodicTask: 08.11.2015, 18:59:39
08.11.2015 18:59:39 HTTP JVM: INIT
08.11.2015 18:59:39 [ODA::WARNING] null
08.11.2015 18:59:39 [ODA::WARNING] (source:org.openntf.domino.utils.DominoUtils$4.run - See IBM_TECHNICAL_SUPPORT\org.openntf.log.X.Y.txt for full stack trace.)
08.11.2015 18:59:39 HTTP JVM: ### LOGSUCCESS
This is the content of the log file:
2015-11-08T18:59:39 [WARNING]: com.ibm.xsp.util.FacesUtil.resolveVariable - null
java.lang.NullPointerException
at com.ibm.xsp.util.FacesUtil.resolveVariable(FacesUtil.java:1048)
at com.ibm.xsp.designer.context.XSPContext.getXSPContext(XSPContext.java:59)
at com.ibm.xsp.extlib.util.ExtLibUtil.getXspContext(ExtLibUtil.java:202)
at org.openntf.domino.xsp.XspOpenLogItem.setThisAgent(XspOpenLogItem.java:132)
at org.openntf.domino.xsp.XspOpenLogItem.getThisAgent(XspOpenLogItem.java:124)
at org.openntf.domino.xsp.XspOpenLogItem.writeToLog(XspOpenLogItem.java:419)
at org.openntf.domino.logging.BaseOpenLogItem.logEvent(BaseOpenLogItem.java:685)
at org.openntf.domino.xsp.XspOpenLogUtil.logEvent(XspOpenLogUtil.java:134)
at org.sutol.demo.xots.PeriodicTask.createOutput(PeriodicTask.java:24)
at org.sutol.demo.xots.PeriodicTask.call(PeriodicTask.java:18)
at org.sutol.demo.xots.PeriodicTask.call(PeriodicTask.java:1)
at org.openntf.domino.xsp.xots.XotsWrappedTask.invokeObject(XotsWrappedTask.java:145)
at org.openntf.domino.xsp.xots.XotsWrappedTask.invokeTasklet(XotsWrappedTask.java:125)
at org.openntf.domino.xsp.xots.XotsWrappedTask.callOrRun(XotsWrappedTask.java:55)
at org.openntf.domino.xsp.xots.XotsDominoExecutor$XotsWrappedCallable.call(XotsDominoExecutor.java:62)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at org.openntf.domino.thread.AbstractDominoExecutor$DominoFutureTask.run(AbstractDominoExecutor.java:235)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:583)
at java.security.AccessController.doPrivileged(AccessController.java:384)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:580)
at java.lang.Thread.run(Thread.java:767)
Can someone tell me a better sample or what I am doing wrong here? I'd like to click a button to start the periodic task (and of course I want to stop then with another button click, but this isn't something I figured out how to do that).