Package net.sf.freecol.server.networking
Class DummyConnection
- java.lang.Object
-
- net.sf.freecol.common.networking.Connection
-
- net.sf.freecol.server.networking.DummyConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class DummyConnection extends Connection
A dummy connection, used for AI players.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Loggerloggerprivate DummyConnectionotherConnectionThe other connection, to which outgoing requests are forwarded .-
Fields inherited from class net.sf.freecol.common.networking.Connection
BUFFER_SIZE, DEFAULT_REPLY_TIMEOUT, END_OF_STREAM, NETWORK_REPLY_ID_TAG, QUESTION_TAG, REPLY_SUFFIX, REPLY_TAG, SEND_SUFFIX
-
-
Constructor Summary
Constructors Constructor Description DummyConnection(java.lang.String name)Sets up a dummy connection using the specified message handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageaskMessage(Message message, long timeout)Send a message, and return the response.voidclose()Close this connection.DummyConnectiongetOtherConnection()Gets theDummyConnectionthis object is connected to.booleanisAlive()Is this connection alive?voidsendMessage(Message message)Send a message, do not consider a response.voidsetOtherConnection(DummyConnection dc)Sets the other connection for this dummy connection.java.lang.StringtoString()-
Methods inherited from class net.sf.freecol.common.networking.Connection
disconnect, endListen, getFreeColXMLReader, getHostAddress, getMessageHandler, getName, getPort, getReplyId, getSocket, getSocketName, handle, logMessage, reader, request, send, sendDisconnect, sendReconnect, setCommsLogging, setMessageHandler, setWriteScope, startListen, startReceiving
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
otherConnection
private DummyConnection otherConnection
The other connection, to which outgoing requests are forwarded .
-
-
Method Detail
-
getOtherConnection
public DummyConnection getOtherConnection()
Gets theDummyConnectionthis object is connected to.- Returns:
- The
DummyConnection.
-
setOtherConnection
public void setOtherConnection(DummyConnection dc)
Sets the other connection for this dummy connection.- Parameters:
dc- TheDummyConnectionto connect to.
-
isAlive
public boolean isAlive()
Is this connection alive?- Overrides:
isAlivein classConnection- Returns:
- True if the connection is alive.
-
close
public void close()
Close this connection.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classConnection
-
sendMessage
public void sendMessage(Message message) throws FreeColException, java.io.IOException
Send a message, do not consider a response. Public as this is called from ReceivingThread.- Overrides:
sendMessagein classConnection- Parameters:
message- TheMessageto send.- Throws:
FreeColException- on extreme confusion.java.io.IOException- on failure to send.
-
askMessage
public Message askMessage(Message message, long timeout) throws FreeColException, java.io.IOException
Send a message, and return the response. Log both.- Overrides:
askMessagein classConnection- Parameters:
message- TheMessageto send.timeout- A timeout in milliseconds, after which aTimeoutExceptiongets thrown when waiting for a reply.- Returns:
- The response.
- Throws:
FreeColException- on extreme confusion.java.io.IOException- on failure to send.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classConnection
-
-