Fork me on GitHub

The CommandService service supports the CommandContext service such that Command objects (that reify the invocation of an action on a domain object into an object) can be persisted.

Persistent Commands support several use cases:

Screencast

The screencast provides a run-through of the command (profiling) service, auditing service, publishing service. It also shows how commands can be run in the background either explicitly by scheduling through the background service or implicitly by way of a framework annotation.

API

The CommandService service defines the following very simple API:

public interface CommandService {

    @Programmatic
    Command create();

    @Programmatic
    void startTransaction(final Command command, final UUID transactionId);

    @Programmatic
    void complete(final Command command);

    @Programmatic
    boolean persistIfPossible(Command command);

    }

where Command is defined as defined by the CommandContext service.

Implementation

CommandService (for persistent Commands)

The CommandService interface (defined in the Isis applib) is implemented within isis-module-command-jdo by:

There is also a supporting repository to query persisted Commands:

In addition, there is a supporting contributions service that contributes actions for searching for persisted Commands for any object:

Usage

Registering the Services

Assuming that the configuration-and-annotation services installer is configured:

isis.services-installer=configuration-and-annotation

then the CommandServiceJdo and CommandServiceJdoRepository services are automatically registered if the isis-module-command-jdo module is on the classpath. The CommandServiceJdoContributions service (because it influences the user interface) must be explicitly registered:

isis.services=...,\
              org.apache.isis.objectstore.jdo.applib.service.command.CommandServiceJdoContributions,\
              ...

Related Services

As discussed above, this service supports the CommandContext, providing the ability for Command objects to be persisted. This is closely related to the BackgroundCommandService that allows the BackgroundService) to schedule commands for background/asynchronous execution.

The implementations of CommandService and BackgroundCommandService are intended to go together, so that persistent parent Commands can be associated with their child background Commands.