Package net.sf.freecol.common.networking
Class NetworkReplyObject
- java.lang.Object
-
- net.sf.freecol.common.networking.NetworkReplyObject
-
public class NetworkReplyObject extends java.lang.ObjectClass 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 intnetworkReplyIdA unique identifier for the message to wait for.private static intONE_SECONDprivate java.lang.ObjectresponseThe response from the network.private booleanresponseGivenA 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 intgetNetworkReplyId()Gets the unique identifier for the network message this object will store.java.lang.ObjectgetResponse(long timeout)Gets the response.voidinterrupt()Interrupt the wait for response.voidsetResponse(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.TimeoutExceptionGets 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 aTimeoutExceptiongets 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.
-
-