Package net.sf.freecol.common.networking
Class TrivialMessage
- java.lang.Object
-
- net.sf.freecol.common.networking.Message
-
- net.sf.freecol.common.networking.TrivialMessage
-
- Direct Known Subclasses:
AttributeMessage,ContinueMessage,DisconnectMessage,EndTurnMessage,EnterRevengeModeMessage,ReconnectMessage,RequestLaunchMessage,RetireMessage,StartGameMessage
public abstract class TrivialMessage extends Message
The basic trivial message, with just a name.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.networking.Message
Message.MessagePriority
-
-
Field Summary
Fields Modifier and Type Field Description static ContinueMessagecontinueMessagestatic DisconnectMessagedisconnectMessagestatic EndTurnMessageendTurnMessagestatic EnterRevengeModeMessageenterRevengeModeMessagestatic ReconnectMessagereconnectMessagestatic RequestLaunchMessagerequestLaunchMessagestatic RetireMessageretireMessagestatic StartGameMessagestartGameMessageprivate java.lang.StringtypeThe actual message type.-
Fields inherited from class net.sf.freecol.common.networking.Message
logger, messagePriorityComparator
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTrivialMessage(java.lang.String type)Create a newTrivialMessageof a given type.protectedTrivialMessage(java.lang.String tag, Game game, FreeColXMLReader xr)Create a newTrivialMessagefrom a stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaiHandler(FreeColServer freeColServer, AIPlayer aiPlayer)AI-side handler for this message.protected <T extends FreeColObject>
voidappendChild(T fco)Append a new child.protected <T extends FreeColObject>
voidappendChildren(java.util.Collection<T> fcos)Append a multiple new children.voidclientHandler(FreeColClient freeColClient)Client-side handler for this message.booleancurrentPlayerMessage()Should this message only be sent to a server by the current player?protected intgetChildCount()Get the number of child objects.protected java.util.List<FreeColObject>getChildren()Get the child objects of this message.Message.MessagePrioritygetPriority()Get the priority of this type of message.protected java.lang.StringgetStringAttribute(java.lang.String key)Get a string attribute value.protected java.util.Map<java.lang.String,java.lang.String>getStringAttributeMap()Get a map of all the attributes in this message.java.lang.StringgetType()Get the message tag.protected booleanhasAttribute(java.lang.String key)Checks if an attribute is present in this message.ChangeSetserverHandler(FreeColServer freeColServer, ServerPlayer serverPlayer)Server-side handler for this message.protected voidsetChildren(java.util.List<? extends FreeColObject> fcos)Set the list of objects attached to this message.protected voidsetStringAttribute(java.lang.String key, java.lang.String value)Sets an attribute in this message.protected voidsetType(java.lang.String type)Set the message tag.-
Methods inherited from class net.sf.freecol.common.networking.Message
canMerge, clientGeneric, expected, getArrayAttributes, getBooleanAttribute, getChild, getChildren, getEnumAttribute, getIntegerAttribute, getPriorityLevel, igc, igc, invokeAndWait, invokeLater, isEmpty, isType, merge, pgc, pgc, pretty, read, setArrayAttributes, setArrayAttributes, setBooleanAttribute, setEnumAttribute, setIntegerAttribute, setStringAttributeMap, setStringAttributes, setStringAttributes, toString, toXML, writeAttributes, writeChildren
-
-
-
-
Field Detail
-
continueMessage
public static final ContinueMessage continueMessage
-
disconnectMessage
public static final DisconnectMessage disconnectMessage
-
endTurnMessage
public static final EndTurnMessage endTurnMessage
-
enterRevengeModeMessage
public static final EnterRevengeModeMessage enterRevengeModeMessage
-
reconnectMessage
public static final ReconnectMessage reconnectMessage
-
requestLaunchMessage
public static final RequestLaunchMessage requestLaunchMessage
-
retireMessage
public static final RetireMessage retireMessage
-
startGameMessage
public static final StartGameMessage startGameMessage
-
type
private java.lang.String type
The actual message type.
-
-
Constructor Detail
-
TrivialMessage
protected TrivialMessage(java.lang.String type)
Create a newTrivialMessageof a given type.- Parameters:
type- The message type.
-
TrivialMessage
protected TrivialMessage(java.lang.String tag, Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamExceptionCreate a newTrivialMessagefrom a stream. Note: only call this from direct subclasses of TrivialMessage as it consumes the whole message.- Parameters:
tag- The message tag.game- TheGamethis message belongs to.xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if the stream is corrupt.
-
-
Method Detail
-
getType
public java.lang.String getType()
Get the message tag.
-
setType
protected void setType(java.lang.String type)
Set the message tag.
-
hasAttribute
protected boolean hasAttribute(java.lang.String key)
Checks if an attribute is present in this message.- Specified by:
hasAttributein classMessage- Parameters:
key- The attribute to look for.- Returns:
- True if the attribute is present.
-
getStringAttribute
protected java.lang.String getStringAttribute(java.lang.String key)
Get a string attribute value.- Specified by:
getStringAttributein classMessage- Parameters:
key- The attribute to look for.- Returns:
- The string value found, or null if the attribute was absent.
-
setStringAttribute
protected void setStringAttribute(java.lang.String key, java.lang.String value)Sets an attribute in this message.- Specified by:
setStringAttributein classMessage- Parameters:
key- The attribute to set.value- The new value of the attribute.
-
getStringAttributeMap
protected java.util.Map<java.lang.String,java.lang.String> getStringAttributeMap()
Get a map of all the attributes in this message.- Specified by:
getStringAttributeMapin classMessage- Returns:
- A
Mapof the attributes.
-
getChildCount
protected int getChildCount()
Get the number of child objects.- Specified by:
getChildCountin classMessage- Returns:
- The child count.
-
getChildren
protected java.util.List<FreeColObject> getChildren()
Get the child objects of this message.- Specified by:
getChildrenin classMessage- Returns:
- A list of child
FreeColObjects.
-
setChildren
protected void setChildren(java.util.List<? extends FreeColObject> fcos)
Set the list of objects attached to this message.- Specified by:
setChildrenin classMessage- Parameters:
fcos- The new list of attachedFreeColObjects.
-
appendChild
protected <T extends FreeColObject> void appendChild(T fco)
Append a new child.- Specified by:
appendChildin classMessage- Type Parameters:
T- The child type.- Parameters:
fco- The new child object.
-
appendChildren
protected <T extends FreeColObject> void appendChildren(java.util.Collection<T> fcos)
Append a multiple new children.- Specified by:
appendChildrenin classMessage- Type Parameters:
T- The child type.- Parameters:
fcos- The new child objects.
-
currentPlayerMessage
public boolean currentPlayerMessage()
Should this message only be sent to a server by the current player?- Specified by:
currentPlayerMessagein classMessage- Returns:
- True if this is a current-player-only message.
-
getPriority
public Message.MessagePriority getPriority()
Get the priority of this type of message.- Specified by:
getPriorityin classMessage- Returns:
- The message priority.
-
aiHandler
public void aiHandler(FreeColServer freeColServer, AIPlayer aiPlayer) throws FreeColException
AI-side handler for this message. AI handlers always return null. FIXME: One day the FreeColServer should devolve to AIMain.- Specified by:
aiHandlerin classMessage- Parameters:
freeColServer- TheFreeColServerhandling the request.aiPlayer- TheAIPlayerthe message was sent to.- Throws:
FreeColException- if there is a problem handling the message.
-
clientHandler
public void clientHandler(FreeColClient freeColClient) throws FreeColException
Client-side handler for this message. Client handlers always return null.- Specified by:
clientHandlerin classMessage- Parameters:
freeColClient- TheFreeColClientto handle this message.- Throws:
FreeColException- if there is a problem building the message.
-
serverHandler
public ChangeSet serverHandler(FreeColServer freeColServer, ServerPlayer serverPlayer)
Server-side handler for this message.- Specified by:
serverHandlerin classMessage- Parameters:
freeColServer- TheFreeColServerhandling the request.serverPlayer- TheServerPlayerthat sent the request.- Returns:
- A
ChangeSetdefining the response.
-
-