Package it.polimi.ingsw.network.messages
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 MessageTypeMessage(MessageType messageType, java.lang.Object object)construct a message with a payload as an Object, a messageType and an empty usernameMessage(MessageType messageType, java.lang.String payload)construct a message with a payload, a messageType and an empty usernameMessage(java.lang.String username, MessageType messageType)construct a message with an username, a messageType and an empty payloadMessage(java.lang.String username, MessageType messageType, java.lang.Object object)construct a message with an username, a payload as an Object and a messageTypeMessage(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 ActiongetAction()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 nullMessageTypegetMessageType()java.lang.StringgetPayload()returns message payload as a String<T> TgetPayloadByType(java.lang.Class<T> myType)returns message payload as a java object of the specified typejava.lang.StringgetUsername()voidsetUsername(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
construct a message with the specified MessageType- Parameters:
messageType- the new message messageType
-
Message
construct a message with an username, a messageType and an empty payload- Parameters:
username- the sender/receiver usernamemessageType- the new message messageType
-
Message
construct a message with a payload, a messageType and an empty username- Parameters:
messageType- the new message messageTypepayload- the new message payload as a String
-
Message
construct a message with a payload as an Object, a messageType and an empty username- Parameters:
messageType- the new message messageTypeobject- the payload Object
-
Message
construct a message with an username, a payload as a String and a messageType- Parameters:
username- the sender/receiver usernamemessageType- the new message messageTypepayload- the new message payload as a String
-
Message
construct a message with an username, a payload as an Object and a messageType- Parameters:
username- the sender/receiver usernamemessageType- the new message messageTypeobject- the new message payload as an Object
-
-
Method Details
-
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
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()
-