Package net.sf.freecol.common.networking
Class NetworkReplyObject
- java.lang.Object
-
- net.sf.freecol.common.networking.NetworkReplyObject
-
public class NetworkReplyObject extends java.lang.Object
Class for storing a network response. If the response has not been set whengetResponse(long)
has been called, this method will block untilsetResponse(java.lang.Object)
is called.
-
-
Field Summary
Fields Modifier and Type Field Description private int
networkReplyId
A unique identifier for the message to wait for.private static int
ONE_SECOND
private java.lang.Object
response
The response from the network.private boolean
responseGiven
A gating flag that shows when the response is valid.
-
Constructor Summary
Constructors Constructor Description NetworkReplyObject(int networkReplyId)
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getNetworkReplyId()
Gets the unique identifier for the network message this object will store.java.lang.Object
getResponse(long timeout)
Gets the response.void
interrupt()
Interrupt the wait for response.void
setResponse(java.lang.Object response)
Sets the response and continuesgetResponse()
.
-
-
-
Field Detail
-
ONE_SECOND
private static int ONE_SECOND
-
networkReplyId
private final int networkReplyId
A unique identifier for the message to wait for.
-
response
private java.lang.Object response
The response from the network.
-
responseGiven
private volatile boolean responseGiven
A gating flag that shows when the response is valid. Starts false, becomes true insetResponse(java.lang.Object)
.
-
-
Method Detail
-
getNetworkReplyId
public int getNetworkReplyId()
Gets the unique identifier for the network message this object will store.- Returns:
- the unique identifier.
-
getResponse
public java.lang.Object getResponse(long timeout) throws java.util.concurrent.TimeoutException
Gets the response. If the response has not been set, this method will block untilsetResponse(java.lang.Object)
has been called.- Parameters:
timeout
- A timeout in milliseconds, after which aTimeoutException
gets thrown when waiting for a reply.- Returns:
- the response.
- Throws:
java.util.concurrent.TimeoutException
- when the timeout is reached.
-
setResponse
public void setResponse(java.lang.Object response)
Sets the response and continuesgetResponse()
.- Parameters:
response
- The response.- See Also:
getResponse(long)
-
interrupt
public void interrupt()
Interrupt the wait for response.
-
-