public abstract class CommandScheduler extends java.lang.Object implements BusFilter<CommandEnvelope>, Closeable
Modifier | Constructor and Description |
---|---|
protected |
CommandScheduler() |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected CommandBus |
commandBus()
Obtains
CommandBus associated with this scheduler. |
protected abstract void |
doSchedule(io.spine.core.Command command)
Schedules a command and delivers it to the target according to
the scheduling options set to a context.
|
java.util.Optional<io.spine.core.Ack> |
filter(CommandEnvelope envelope)
Accepts or rejects a passed message.
|
boolean |
isOpen()
Tells if the object is still open.
|
protected void |
post(io.spine.core.Command command)
Delivers a scheduled command to a target.
|
void |
schedule(io.spine.core.Command command)
Schedules a command and delivers it to the target according to the scheduling options.
|
void |
shutdown()
Initiates an orderly shutdown in which previously scheduled commands will be delivered later,
but no new commands will be accepted.
|
public java.util.Optional<io.spine.core.Ack> filter(CommandEnvelope envelope)
BusFilter
A filter can:
Optional.empty()
);
Error
status, for example, if
it fails to pass the validation;
OK
status. For example, a scheduled command may not
pass a filter;
filter
in interface BusFilter<CommandEnvelope>
envelope
- the envelope with the message to filterOptional.empty()
if the message passes the filter,
posting result with either status otherwisepublic boolean isOpen()
Closeable
Implementations must return false
after AutoCloseable.close()
is invoked.
public void close()
BusFilter
By default, performs no action.
close
in interface BusFilter<CommandEnvelope>
close
in interface java.lang.AutoCloseable
public void schedule(io.spine.core.Command command)
A command with the same ID cannot be scheduled again.
command
- a command to deliver laterjava.lang.IllegalStateException
- if the scheduler is shut downprotected CommandBus commandBus()
CommandBus
associated with this scheduler.java.lang.IllegalStateException
- if CommandBus
was not set prior
to calling this methodprotected abstract void doSchedule(io.spine.core.Command command)
command
- a command to deliver laterCommandScheduler.post(Command)
protected void post(io.spine.core.Command command)
command
- a command to deliverpublic void shutdown()
Invocation has no effect if the scheduler is already shut down.