Class Message

java.lang.Object
it.polimi.ingsw.network.messages.Message

public class Message
extends java.lang.Object
Represents a message between client and server in network
  • Constructor Summary

    Constructors
    Constructor Description
    Message​(MessageType messageType)
    construct a message with the specified MessageType
    Message​(MessageType messageType, java.lang.Object object)
    construct a message with a payload as an Object, a messageType and an empty username
    Message​(MessageType messageType, java.lang.String payload)
    construct a message with a payload, a messageType and an empty username
    Message​(java.lang.String username, MessageType messageType)
    construct a message with an username, a messageType and an empty payload
    Message​(java.lang.String username, MessageType messageType, java.lang.Object object)
    construct a message with an username, a payload as an Object and a messageType
    Message​(java.lang.String username, MessageType messageType, java.lang.String payload)
    construct a message with an username, a payload as a String and a messageType
  • Method Summary

    Modifier and Type Method Description
    Action getAction()
    if the messageType is ACTION this method returns the action object contained as payload in the message if the payload doesn't contain an action returns null
    MessageType getMessageType()  
    java.lang.String getPayload()
    returns message payload as a String
    <T> T getPayloadByType​(java.lang.Class<T> myType)
    returns message payload as a java object of the specified type
    java.lang.String getUsername()  
    void setUsername​(java.lang.String usr)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Message

      public Message​(MessageType messageType)
      construct a message with the specified MessageType
      Parameters:
      messageType - the new message messageType
    • Message

      public Message​(java.lang.String username, MessageType messageType)
      construct a message with an username, a messageType and an empty payload
      Parameters:
      username - the sender/receiver username
      messageType - the new message messageType
    • Message

      public Message​(MessageType messageType, java.lang.String payload)
      construct a message with a payload, a messageType and an empty username
      Parameters:
      messageType - the new message messageType
      payload - the new message payload as a String
    • Message

      public Message​(MessageType messageType, java.lang.Object object)
      construct a message with a payload as an Object, a messageType and an empty username
      Parameters:
      messageType - the new message messageType
      object - the payload Object
    • Message

      public Message​(java.lang.String username, MessageType messageType, java.lang.String payload)
      construct a message with an username, a payload as a String and a messageType
      Parameters:
      username - the sender/receiver username
      messageType - the new message messageType
      payload - the new message payload as a String
    • Message

      public Message​(java.lang.String username, MessageType messageType, java.lang.Object object)
      construct a message with an username, a payload as an Object and a messageType
      Parameters:
      username - the sender/receiver username
      messageType - the new message messageType
      object - the new message payload as an Object
  • Method Details

    • getMessageType

      public MessageType getMessageType()
    • getPayload

      public java.lang.String getPayload()
      returns message payload as a String
      Returns:
      the message payload String
    • getPayloadByType

      public <T> T getPayloadByType​(java.lang.Class<T> myType)
      returns message payload as a java object of the specified type
      Type Parameters:
      T - the generic return type (same as parameter myType)
      Parameters:
      myType - the type of the returned object
      Returns:
      the message payload as a java object
    • getAction

      public Action getAction()
      if the messageType is ACTION this method returns the action object contained as payload in the message if the payload doesn't contain an action returns null
      Returns:
      the ACTION contained as payload
    • setUsername

      public void setUsername​(java.lang.String usr)
    • getUsername

      public java.lang.String getUsername()