Class DefaultMessage
- All Implemented Interfaces:
Message
All Messages have a messageId and a routing stack. Many have a payload. A message can retain a history of where its been. The top of the route stack is popped just before a message is processed by an actor. A message is enforced to be immutable once it has been sent. A New message can be created from an immutable message, including the same messageId. Additionally, multiple messages can be created from a single immutable message typically for a fan-out fan-in flow.
Implementation note: The only interesting part of the route stack is the top of stack. And, since messages are serialized and sent frequently, we need to serialize and store/transmit the route stack as efficiently as possible. Therefore, don't bother serializing or deserializing most of the route stack for each message invocation. When creating a message, serialize all but the top of stack to a string and and prepend it to the existing serialized string. When processing a message popRoute, pop the (only) route from the top of stack and then peel off the first route in the string and add it to the real stack. In this way, the materialized stack is just a scalar route plus the string carrying the rest of the stack.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopyRoutesFrom
(Message inbound) Copy guts of provided message into this message but don't copy routes.Find the info with the matching name (case insensitive).<T> T
getActorId
(String key) Find the Info record the matching name (case insensitive) and return its String ContentsReturn a copy of the message routing historyint
getInteger
(String key) Find the integer Info matching the name (case insensitive) and return its Integer ContentsPeek at the next verb or null if there's no more routes.Get a fresh copy of the payload of this messagegetRoute()
Get the current routeFind the Info record the matching name (case insensitive) and return its String ContentsGet the target actorId of the current route.getVerb()
Get the verb of the current route.boolean
keepHistory
(boolean keepHistory) notImplemented
(Config config, Actor actor) This method is called when a message is sent to an Actor but the Actor has not overriden the processMessage method.Peek at the next route or null if there's no more routes in the message.popRoute()
Popping a route sets the current route in the message and it also renders the message immutable.boolean
postprocess
(Config config, Actor actor) This method is called when a message is sent by an Actor.protected Route
boolean
preprocess
(Config config, Actor actor) This method is called after a message is deserialized and ready to be processed by the target actor.void
print
(PrintStream out) void
Put new Integer entry in payload.Add an Info entry to payload, see convenience methods as well.Put new String entry in payload.Put new entry in payload convenience for an ActorIdRemove entry from payloadvoid
This method is called when a message is sent by an Actor and the message as no further routes this it will be destroyed just after this method is called.void
toJson
(PrintStream out) toString()
trace
(boolean trace) boolean
validateMessage
(Config config) If nothing to do in the message, return false.
-
Constructor Details
-
DefaultMessage
public DefaultMessage() -
DefaultMessage
-
DefaultMessage
-
-
Method Details
-
from
Copy guts of provided message into this message but don't copy routes. If keepHistory is false but there is lingering history from the original message, the history is NOT brought forward. The messageId is brought forward. Payload is brought forward. This method is used to broadcast messages, with the same id, to multiple actors in parallel. The single messageId allows for correlation of messages when needed. -
validateMessage
If nothing to do in the message, return false. Otherwise, check and throw exception if issues.- Parameters:
config
-- Returns:
- true if the message is valid
-
getMessageId
- Specified by:
getMessageId
in interfaceMessage
-
getTimestamp
- Specified by:
getTimestamp
in interfaceMessage
-
getHistory
Description copied from interface:Message
Return a copy of the message routing history- Specified by:
getHistory
in interfaceMessage
- Returns:
-
getRoute
Get the current route -
getTarget
Description copied from interface:Message
Get the target actorId of the current route. This is the route that gave rise to this call to processMessage -
getVerb
Description copied from interface:Message
Get the verb of the current route. This is the route that gave rise to this call to processMessage -
getRoutes
-
getNextActorId
- Specified by:
getNextActorId
in interfaceMessage
-
getNextVerb
Peek at the next verb or null if there's no more routes.- Specified by:
getNextVerb
in interfaceMessage
-
peekRoute
Peek at the next route or null if there's no more routes in the message. -
peekTailRoute
-
popRoute
Popping a route sets the current route in the message and it also renders the message immutable. -
pushRoute
-
keepHistory
- Specified by:
keepHistory
in interfaceMessage
-
isKeepHistory
public boolean isKeepHistory()- Specified by:
isKeepHistory
in interfaceMessage
-
trace
-
copyRoutesFrom
- Specified by:
copyRoutesFrom
in interfaceMessage
-
prepareBuildRoute
-
ask
-
ask
-
to
-
toJson
-
toString
-
print
-
getPayload
Get a fresh copy of the payload of this message- Specified by:
getPayload
in interfaceMessage
- Returns:
-
remove
Description copied from interface:Message
Remove entry from payload -
put
Add an Info entry to payload, see convenience methods as well. -
put
Put new String entry in payload. Convenience for a String -
put
Put new Integer entry in payload. Convenience for an Integer -
put
Put new entry in payload convenience for an ActorId -
get
Description copied from interface:Message
Find the info with the matching name (case insensitive). -
get
-
getString
Find the Info record the matching name (case insensitive) and return its String Contents -
getInteger
Description copied from interface:Message
Find the integer Info matching the name (case insensitive) and return its Integer Contents- Specified by:
getInteger
in interfaceMessage
- Parameters:
key
-- Returns:
-
getActorId
Find the Info record the matching name (case insensitive) and return its String Contents- Specified by:
getActorId
in interfaceMessage
- Parameters:
key
-- Returns:
-
preprocess
Description copied from interface:Message
This method is called after a message is deserialized and ready to be processed by the target actor. The default implementation does nothing. This method can be overridden in a Message subclass to provide fine-grained tracing or additional message validation.This method executes in the Actor's thread.
- Specified by:
preprocess
in interfaceMessage
- Parameters:
config
-actor
- The Actor that is about to process this message- Returns:
- true if the message should be processed
-
postprocess
Description copied from interface:Message
This method is called when a message is sent by an Actor. This happens just before the message is serialized for transport to its current destination. A subclass of a default message can use this method to evaluate the message as well as the Actor that created or forwarded the message. This method can be overridden in a Message subclass to provide fine-grained tracing.This method executes in the Actor's thread.
- Specified by:
postprocess
in interfaceMessage
- Parameters:
config
-actor
- The Actor that just processed this message- Returns:
- true if the message should be processed
-
notImplemented
Description copied from interface:Message
This method is called when a message is sent to an Actor but the Actor has not overriden the processMessage method. The default behavior is to return an empty Stage. An alternate would be to put the inbound message back into the Stage (it will be sent to the next item in the Route stack, if any). A subclass of a default message can use this method to provide alternate behavior or to forwarded the message.This method executes in the Actor's thread.
- Specified by:
notImplemented
in interfaceMessage
- Parameters:
config
-actor
- The Actor that received (but didn't process) this message- Returns:
- The Stage to be processed
-
terminal
Description copied from interface:Message
This method is called when a message is sent by an Actor and the message as no further routes this it will be destroyed just after this method is called. A subclass of a default message can use this method to evaluate the message as well as the Actor that created or forwarded the message to ensure that its demise is justified.This method executes in the Actor's thread.
-