Class MessageEnvelope
java.lang.Object
dev.ua.theroer.magicutils.messaging.MessageEnvelope
Wire representation of a single message on the bus.
The envelope is transport-neutral: both the default plugin-messaging
transport and the Redis transport serialize it to bytes (via
MessageCodec) and reconstruct it on the receiving side. It carries the
logical channel, the addressing hint, the originating
MessageSource, and the already-serialized payload bytes so the
transport never needs to understand the user payload type.
-
Constructor Summary
ConstructorsConstructorDescriptionMessageEnvelope(UUID id, String channel, Target target, MessageSource source, byte[] payload, long timestamp) Creates an envelope. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptedBy(MessageSource self, Predicate<UUID> hostsPlayer) Decides whether a local member should accept this envelope given the target.channel()Returns the logical channel name.static MessageEnvelopecreate(String channel, Target target, MessageSource source, byte[] payload) Creates an envelope with a fresh id and the current timestamp.id()Returns the unique message id.byte[]payload()Returns the serialized payload bytes.source()Returns the originating member.target()Returns the addressing hint.longReturns the creation timestamp (epoch millis).
-
Constructor Details
-
MessageEnvelope
public MessageEnvelope(UUID id, String channel, Target target, MessageSource source, byte[] payload, long timestamp) Creates an envelope.- Parameters:
id- unique message id (for de-duplication / correlation)channel- logical channel nametarget- addressing hintsource- originating memberpayload- serialized payload bytestimestamp- epoch millis when the message was created
-
-
Method Details
-
create
public static MessageEnvelope create(String channel, Target target, MessageSource source, byte[] payload) Creates an envelope with a fresh id and the current timestamp.- Parameters:
channel- logical channel nametarget- addressing hintsource- originating memberpayload- serialized payload bytes- Returns:
- new envelope
-
id
-
channel
-
target
-
source
-
payload
public byte[] payload()Returns the serialized payload bytes.- Returns:
- payload bytes (do not mutate)
-
timestamp
public long timestamp()Returns the creation timestamp (epoch millis).- Returns:
- timestamp
-
acceptedBy
Decides whether a local member should accept this envelope given the target.Transports that cannot pre-filter (for example Redis pub/sub, which broadcasts to every subscriber) call this on receipt so addressing is honoured uniformly regardless of transport.
- Parameters:
self- the local memberhostsPlayer- predicate answering whether the local member hosts a player id; may be null on the proxy or when player hosting is unknown- Returns:
- true when the local member is an intended recipient
-