Class ActorMessage
java.lang.Object
com.scivicslab.pojoactor.core.distributed.ActorMessage
Message protocol for distributed actor invocation.
This class represents a serializable message that can be sent over HTTP to invoke actions on remote actors. It uses JSON serialization for network transmission.
Message Format
{
"actorName": "math",
"actionName": "add",
"args": "5,3",
"messageId": "550e8400-e29b-41d4-a716-446655440000",
"replyTo": "node2:8082"
}
Usage Example
// Create message
ActorMessage msg = new ActorMessage("math", "add", "5,3");
// Serialize to JSON
String json = msg.toJson();
// Deserialize from JSON
ActorMessage received = ActorMessage.fromJson(json);
- Since:
- 3.0.0, 3.0.0
- Author:
- devteam@scivics-lab.com
-
Constructor Summary
ConstructorsConstructorDescriptionActorMessage(String actorName, String actionName, String args) Constructs a new ActorMessage without reply address.Constructs a new ActorMessage with specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic ActorMessageDeserializes an ActorMessage from JSON string.Returns the action name to invoke.Returns the target actor name.getArgs()Returns the action arguments.Returns the unique message identifier.Returns the reply address.toJson()Serializes this message to JSON string.toString()
-
Constructor Details
-
ActorMessage
public ActorMessage(String actorName, String actionName, String args, String messageId, String replyTo) Constructs a new ActorMessage with specified parameters.- Parameters:
actorName- the name of the target actoractionName- the name of the action to invokeargs- the arguments for the action (string format)messageId- unique identifier for this messagereplyTo- optional reply address (e.g., "node2:8082")
-
ActorMessage
Constructs a new ActorMessage without reply address.- Parameters:
actorName- the name of the target actoractionName- the name of the action to invokeargs- the arguments for the action (string format)
-
-
Method Details
-
getActorName
Returns the target actor name.- Returns:
- the actor name
-
getActionName
Returns the action name to invoke.- Returns:
- the action name
-
getArgs
Returns the action arguments.- Returns:
- the arguments as a string
-
getMessageId
Returns the unique message identifier.- Returns:
- the message ID
-
getReplyTo
Returns the reply address.- Returns:
- the reply address, or
nullif not specified
-
toJson
Serializes this message to JSON string.- Returns:
- JSON representation of this message
- Throws:
RuntimeException- if serialization fails
-
fromJson
Deserializes an ActorMessage from JSON string.- Parameters:
json- the JSON string- Returns:
- the deserialized ActorMessage
- Throws:
RuntimeException- if deserialization fails
-
toString
-