Skip to content
jesse-gallagher edited this page Sep 25, 2014 · 2 revisions

org.openntf.domino.xots.XotsBaseTasklet is the core class for all Xots Tasklets. It extends org.openntf.domino.thread.AbstractDominoRunnable, a class created in an earlier version of the API for multi-threading.

XotsAbstractTriggeredTasklet extends XotsBaseTasklet and allows handling of events. Extend that for triggered tasks that need to work on an IDominoEvent. Currently picks up a org.openntf.domino.xots.events.CustomNamedEvent that takes a name and payload.

XotsAbstractScheduledTasklet also extends XotsBaseTasklet and allows schedules to be set and retrieved. Extend that for scheduled tasks

JSR223Tasklet is intended for running tasklets with code written in any JSR-223-compliant language on the server.

Annotations

Trigger - e.g. @Trigger. Simple annotation used for triggered tasks Schedule - e.g. @Schedule(frequency = 1, timeunit = TimeUnit.MINUTES, weekdays = { Calendar.MONDAY, Calendar.FRIDAY }, starthour = 8, endhour = 16). Annotation for determining frequency, start hour, end hour, days. Defaults are all days, 0 to 23 hours. Persistent = @Persistent(scope = Scope.USER,context = Context.XSPFORCED). Annotation for determining scope for the persistence and context. Defaults are Scope.SERVER and Context.XOTS

Scopes - SERVER, TEMPLATE, APPLICATION, USER, OBJECT, NONE Contexts - XOTS, XSPBARE (just load bare minimum, sort of "XPages-aware agent"), XSPFORCED (run as if from browser, access to scopes), XSPSCOPED - pick up scopes for APPLICATION / USER

XotsNsfScanner is a built in Xots Tasklet, persistent and scheduled for every 4 hours, to scan all databases for Xots tasklets. Triggered from XotsDaemon in private constructor, scan and update methods. The Scanner iterates databases and looks in the Icon note for a $Xots field, which holds an array of XotsTasklets. It calls XotsService.getComponentModule() to check whether the NSFComponentModule has been added to the XotsService; if not, it adds it using the key "/" + databasePath.

It then calls loadXotsTasklets() which creates a new LoaderRunnable for the NSF containing the classes that are XotsTasklets - IS THIS WHERE WE NEED TO GET THE SCHEDULED ANNOTATIONS???

XotsDaemon is a singleton instantiated via XotsDaemon.getInstance() in OpenntfServiceFactory and quitted by the Activator. The constructor creates a XotsService tied to the current LCDEnvironment's List of HTTPServices, creates a new XotsNsfScanner, adds itself as an observer to the scanner, loads the scanner into a new NotesThread and starts the thread. That calls the run, which calls scan(), then flags the XotsNsfScanner as having changed and notifies its observer.

XotsDaemon also has a fireEvent() method, triggered from publishEvent() method. This loops through the Xots classes registered for the database, gets all tasks with an @Trigger - e.g. @Trigger("testEvent") - checks that the event extends CustomNamedEvent, and if the event passed to fireEvent() is the same as an event in the CustomNamedEvent, it queues a new TriggerRunnable for the class's ClassLoader.

XotsDaemon.queue methods are the ones that process the XotsTasklets. They pass in a Runnable using the Runnable's ClassLoader. THIS NEEDS TO CHECK THE CONTEXT, TO LOAD THE RELEVANT CLASSLOADER. Depending on DominoSessionType, it passes it to the relevant Runner (NAMED - XotsNamedRunner - RunAsID; NATIVE - XotsNativeRunner - Run as Server within NSF, MANUAL - DominoManualRunner - Run as Server within Domino Session, NONE - DominoNoneRunner - Run as Server without a Session). There's also DEFAULT and SIGNER.

getExecutor() creates a new XotsExecutor which executes the Runner (XotsNamedRunner, XotsNativeRunner etc). The executor extends TrustedDispatcher.TrusteExecutor creates a new XotsThreadFactory which makes a new XotsThread. There is also XotsScheduledExecutor which extends TrustedDispatcher.TrustedScheduledExecutor. Executor is called when tasklet runs by super.process().

XotsService extends NSFService. The existing XotsService can be accessed via getInstance(), which gets the XotsService that was created by the XotsDaemon constructor. addToQueue method looks to have been deprecated.

NEXT STEPS...

When checking tasks, look for annotations and work out if it needs to run in next four hours. If so, call some method like schedule(final Runnable runnable), which will need to call getScheduledExecutor to create a new XotsScheduledExecutor. That will need to call newTaskFor, passing the Runnable - WHAT IS final T value? It will also need to parse the Annotations to call schedule with the relevant delay. When the runs, it will need to update the schedule, checking annotations.