Class NetworkReplyObject


  • public class NetworkReplyObject
    extends java.lang.Object
    Class for storing a network response. If the response has not been set when getResponse(long) has been called, this method will block until setResponse(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 continues getResponse().
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in setResponse(java.lang.Object).
    • Constructor Detail

      • NetworkReplyObject

        public NetworkReplyObject​(int networkReplyId)
        The constructor.
        Parameters:
        networkReplyId - The unique identifier for the network message this object will store.
    • 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 until setResponse(java.lang.Object) has been called.
        Parameters:
        timeout - A timeout in milliseconds, after which a TimeoutException 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 continues getResponse().
        Parameters:
        response - The response.
        See Also:
        getResponse(long)
      • interrupt

        public void interrupt()
        Interrupt the wait for response.