@SPI
@FunctionalInterface
public interface BusFilter<E extends MessageEnvelope<?,?,?>>
extends java.lang.AutoCloseable
A bus may have several filters which can prevent a message from being posted.
Modifier and Type | Method and Description |
---|---|
default void |
close() |
java.util.Optional<io.spine.core.Ack> |
filter(E envelope)
Accepts or rejects a passed message.
|
default java.util.Optional<io.spine.core.Ack> |
letPass()
Lets the message pass the filter.
|
default java.util.Optional<io.spine.core.Ack> |
reject(E envelope)
Rejects the message with the
OK status. |
default java.util.Optional<io.spine.core.Ack> |
reject(E envelope,
io.spine.base.Error cause)
Rejects the message with an
Error status. |
default java.util.Optional<io.spine.core.Ack> |
reject(E envelope,
io.spine.base.ThrowableMessage cause)
Rejects the message with a rejection status.
|
java.util.Optional<io.spine.core.Ack> filter(E envelope)
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;
envelope
- the envelope with the message to filterOptional.empty()
if the message passes the filter,
posting result with either status otherwisedefault java.util.Optional<io.spine.core.Ack> letPass()
This method is a shortcut which can be used in BusFilter.filter(MessageEnvelope)
when this
filter shouldn't prevent the message from being posted.
default java.util.Optional<io.spine.core.Ack> reject(E envelope)
OK
status.
This method is a shortcut which can be used in BusFilter.filter(MessageEnvelope)
when the
message does not pass the filter and this is expected.
envelope
- the envelope with the message to filterOptional.of(Ack)
signaling that the message does not pass the filterdefault java.util.Optional<io.spine.core.Ack> reject(E envelope, io.spine.base.Error cause)
Error
status.
This method is a shortcut which can be used in BusFilter.filter(MessageEnvelope)
when the
message does not pass the filter due to a technical error or inconsistency in model
data.
envelope
- the envelope with the message to filtercause
- the cause of the rejectionOptional.of(Ack)
signaling that the message does not pass the filterdefault java.util.Optional<io.spine.core.Ack> reject(E envelope, io.spine.base.ThrowableMessage cause)
This method is a shortcut which can be used in BusFilter.filter(MessageEnvelope)
when the
message does not pass the filter due to a business rejection.
Such rejection method can be used when no technical error occurs but due to the business rules the command should be immediately disqualified from being executed. A typical scenario would be when the permissions of the user who made the request aren't broad enough.
envelope
- the envelope with the message to filtercause
- the cause of the rejectionOptional.of(Ack)
signaling that the message does not pass the filterjava.lang.IllegalArgumentException
- if the filtered envelope
is not a
commanddefault void close() throws java.lang.Exception
By default, performs no action.
close
in interface java.lang.AutoCloseable
java.lang.Exception