Database Reference
In-Depth Information
* persistent storage.
*
* @return true if a checkpoint should be generated, false otherwise
*/
boolean
afterCheckpoint
();
You also need to provide the actual work of the system task job in the form of imple‐
menting the function:
/**
* Called when the system task is executed in protected mode.
* Constitutes the work unit of the system task.
*
* @param broker A database broker that can be used to access the database.
*
* @throws ExistException You may throw this to indicate an error and abruptly
* abort executing of the system task. If the task is managed by the
* scheduler, this will not affect its future schedule.
*/
void
execute
(
DBBroker
broker
)
throws
EXistException
;
System tasks do not need to acquire locks on collections and docu‐
ments, as they are operating in protected mode—in fact, they
should not attempt to do so! Invalid management of locks in a sys‐
tem task can lead to deadlock situations.
If you wish to acquire collections and documents without locks,
you can use the
getCollection(XmldbURI)
method on
org.exist.storage.DBBroker
and then subsequently the
collec
tionIteratorNoLock(DBBroker)
and
iteratorNoLock(DBBroker)
methods on
org.exist.collections.Collection
.
Database stats scheduled system task.
An example class implementing
SystemTask
called
exist.book.example.scheduler.system.StatsSystemTask
is supplied in the
folder
chapters/advanced-topics/scheduler-java-job/stats-system-task-example
of the
book-code
Git repository (see
“Getting the Source Code” on page 15
). The example
simply generates statistics about the current content of the database and stores them
into a new document in a configured database collection. When the system task is
scheduled, this allows you to build a collection of statistics about the content of the
database over time, which could potentially be used by other XQueries to generate
reports and/or graphs about database usage. The use of a system task here allows us
to guarantee that our statistics represent the
exact state of the database at a particular
point in time
, due to execution happening while the database is in protected mode.
To compile the example, enter the
scheduler-java-job
folder and run
mvn package
;
the system task job example can be found in the subfolder
stats-system-task-example
.
Search WWH ::
Custom Search