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 ContinueMessage
continueMessage
static DisconnectMessage
disconnectMessage
static EndTurnMessage
endTurnMessage
static EnterRevengeModeMessage
enterRevengeModeMessage
static ReconnectMessage
reconnectMessage
static RequestLaunchMessage
requestLaunchMessage
static RetireMessage
retireMessage
static StartGameMessage
startGameMessage
private java.lang.String
type
The actual message type.-
Fields inherited from class net.sf.freecol.common.networking.Message
logger, messagePriorityComparator
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TrivialMessage(java.lang.String type)
Create a newTrivialMessage
of a given type.protected
TrivialMessage(java.lang.String tag, Game game, FreeColXMLReader xr)
Create a newTrivialMessage
from a stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
aiHandler(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.void
clientHandler(FreeColClient freeColClient)
Client-side handler for this message.boolean
currentPlayerMessage()
Should this message only be sent to a server by the current player?protected int
getChildCount()
Get the number of child objects.protected java.util.List<FreeColObject>
getChildren()
Get the child objects of this message.Message.MessagePriority
getPriority()
Get the priority of this type of message.protected java.lang.String
getStringAttribute(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.String
getType()
Get the message tag.protected boolean
hasAttribute(java.lang.String key)
Checks if an attribute is present in this message.ChangeSet
serverHandler(FreeColServer freeColServer, ServerPlayer serverPlayer)
Server-side handler for this message.protected void
setChildren(java.util.List<? extends FreeColObject> fcos)
Set the list of objects attached to this message.protected void
setStringAttribute(java.lang.String key, java.lang.String value)
Sets an attribute in this message.protected void
setType(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 newTrivialMessage
of a given type.- Parameters:
type
- The message type.
-
TrivialMessage
protected TrivialMessage(java.lang.String tag, Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a newTrivialMessage
from a stream. Note: only call this from direct subclasses of TrivialMessage as it consumes the whole message.- Parameters:
tag
- The message tag.game
- TheGame
this message belongs to.xr
- TheFreeColXMLReader
to 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:
hasAttribute
in 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:
getStringAttribute
in 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:
setStringAttribute
in 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:
getStringAttributeMap
in classMessage
- Returns:
- A
Map
of the attributes.
-
getChildCount
protected int getChildCount()
Get the number of child objects.- Specified by:
getChildCount
in classMessage
- Returns:
- The child count.
-
getChildren
protected java.util.List<FreeColObject> getChildren()
Get the child objects of this message.- Specified by:
getChildren
in classMessage
- Returns:
- A list of child
FreeColObject
s.
-
setChildren
protected void setChildren(java.util.List<? extends FreeColObject> fcos)
Set the list of objects attached to this message.- Specified by:
setChildren
in classMessage
- Parameters:
fcos
- The new list of attachedFreeColObject
s.
-
appendChild
protected <T extends FreeColObject> void appendChild(T fco)
Append a new child.- Specified by:
appendChild
in 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:
appendChildren
in 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:
currentPlayerMessage
in 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:
getPriority
in 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:
aiHandler
in classMessage
- Parameters:
freeColServer
- TheFreeColServer
handling the request.aiPlayer
- TheAIPlayer
the 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:
clientHandler
in classMessage
- Parameters:
freeColClient
- TheFreeColClient
to 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:
serverHandler
in classMessage
- Parameters:
freeColServer
- TheFreeColServer
handling the request.serverPlayer
- TheServerPlayer
that sent the request.- Returns:
- A
ChangeSet
defining the response.
-
-