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.Logger
logger
private DummyConnection
otherConnection
The 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 Message
askMessage(Message message, long timeout)
Send a message, and return the response.void
close()
Close this connection.DummyConnection
getOtherConnection()
Gets theDummyConnection
this object is connected to.boolean
isAlive()
Is this connection alive?void
sendMessage(Message message)
Send a message, do not consider a response.void
setOtherConnection(DummyConnection dc)
Sets the other connection for this dummy connection.java.lang.String
toString()
-
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 theDummyConnection
this object is connected to.- Returns:
- The
DummyConnection
.
-
setOtherConnection
public void setOtherConnection(DummyConnection dc)
Sets the other connection for this dummy connection.- Parameters:
dc
- TheDummyConnection
to connect to.
-
isAlive
public boolean isAlive()
Is this connection alive?- Overrides:
isAlive
in classConnection
- Returns:
- True if the connection is alive.
-
close
public void close()
Close this connection.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in 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:
sendMessage
in classConnection
- Parameters:
message
- TheMessage
to 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:
askMessage
in classConnection
- Parameters:
message
- TheMessage
to send.timeout
- A timeout in milliseconds, after which aTimeoutException
gets 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:
toString
in classConnection
-
-