Actions & Conditions

Ressor provides you with the opportunity to perform several actions upon the reload process. This actions can also abort current reload, if some conditions are not met.

Action is represented by ReloadAction interface, and is executed right before the data reload from the source.

There are some number of built-in actions, which are described in the next paragraphs.

Predicates

Abort service reload if some condition is not met:

import static xyz.ressor.service.action.Actions.*;
ressor.actions().onReload(isbn, abortIf(rs -> someCondition()))

There is also same predicate, but which provides old and new version of the resource:

import static xyz.ressor.service.action.Actions.*;
ressor.actions().onReload(isbn, abortIf(
(oldVersion, newVersion) -> isForbidden(newVersion))

Service Dependencies

  • When isbn service is being reloaded, trigger asynchronous reload of books service and proceed immediately:

    import static xyz.ressor.service.action.Actions.*;
    ressor.actions().onReload(isbn,
    triggerReload(books));
    ressor.poll(isbn).every(5, SECONDS);
  • When isbn service is being reloaded, trigger and wait synchronously for the reload of books service. This way, books service will always be reloaded strictly prior to isbn service:

    import static xyz.ressor.service.action.Actions.*;
    ressor.actions().onReload(isbn,
    triggerAndWaitReload(books));
    ressor.poll(isbn).every(5, SECONDS);

Logical Operations

You can union multiple actions in logical conditions like math OR, AND:

import static xyz.ressor.service.action.Actions.*;
// if either action1 or action2 return positive value
// service1 will be reloaded
ressor.actions().onReload(service1, or(action1, action2));
// if both action3 or action4 return positive value
// service2 will be reloaded
ressor.actions().onReload(service2, and(action3, action4));

Since the action itself can be blocking operation, you can take profit from parallel implementations of such logical conditions.

For example, when isbn service is reloaded, reload in parallel books and dvds services and wait for the positive result from both. In that case, reload isbn:

import static xyz.ressor.service.action.Actions.*;
ressor.actions().onReload(isbn,
andParallel(triggerAndWaitReload(books),
triggerAndWaitReload(dvds)));
ressor.poll(isbn).every(5, SECONDS);