Class ActorMessage

java.lang.Object
com.scivicslab.pojoactor.core.distributed.ActorMessage

public class ActorMessage extends Object
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 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 actor
      actionName - the name of the action to invoke
      args - the arguments for the action (string format)
      messageId - unique identifier for this message
      replyTo - optional reply address (e.g., "node2:8082")
    • ActorMessage

      public ActorMessage(String actorName, String actionName, String args)
      Constructs a new ActorMessage without reply address.
      Parameters:
      actorName - the name of the target actor
      actionName - the name of the action to invoke
      args - the arguments for the action (string format)
  • Method Details

    • getActorName

      public String getActorName()
      Returns the target actor name.
      Returns:
      the actor name
    • getActionName

      public String getActionName()
      Returns the action name to invoke.
      Returns:
      the action name
    • getArgs

      public String getArgs()
      Returns the action arguments.
      Returns:
      the arguments as a string
    • getMessageId

      public String getMessageId()
      Returns the unique message identifier.
      Returns:
      the message ID
    • getReplyTo

      public String getReplyTo()
      Returns the reply address.
      Returns:
      the reply address, or null if not specified
    • toJson

      public String toJson()
      Serializes this message to JSON string.
      Returns:
      JSON representation of this message
      Throws:
      RuntimeException - if serialization fails
    • fromJson

      public static ActorMessage fromJson(String json)
      Deserializes an ActorMessage from JSON string.
      Parameters:
      json - the JSON string
      Returns:
      the deserialized ActorMessage
      Throws:
      RuntimeException - if deserialization fails
    • toString

      public String toString()
      Overrides:
      toString in class Object