Class ThreadReceivePort<Message>


  • public class ThreadReceivePort<Message>
    extends java.lang.Object
    This class is a simple convenience wrapper around ReceivePort that can be used by threads (as opposed to fibers). Its methods do not declare they throw SuspendExecution.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the channel so that no more messages could be sent to it.
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      boolean isClosed()
      Tests whether the channel has been closed and no more messages await in the channel.
      Message receive()
      Retrieves a message from the channels, possibly blocking until one becomes available.
      Message receive​(long timeout, java.util.concurrent.TimeUnit unit)
      Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.
      java.lang.String toString()  
      Message tryReceive()
      Retrieves a message from the channel if one is available.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • receive

        public Message receive()
                        throws java.lang.InterruptedException
        Retrieves a message from the channels, possibly blocking until one becomes available.
        Returns:
        a message, or null if the channel has been closed and no more messages await (see isClosed()).
        Throws:
        java.lang.InterruptedException
      • receive

        public Message receive​(long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.InterruptedException
        Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.
        Parameters:
        timeout - the maximum duration to block waiting for a message.
        unit - the time unit of the timeout.
        Returns:
        a message, or null if the channel has been closed and no more messages await (see isClosed()), or if the timeout has expired.
        Throws:
        java.lang.InterruptedException
      • tryReceive

        public Message tryReceive()
        Retrieves a message from the channel if one is available. This method never blocks.
        Returns:
        a message, or null if one is not immediately available.
      • close

        public void close()
        Closes the channel so that no more messages could be sent to it. Messages already sent to the channel will still be received.
      • isClosed

        public boolean isClosed()
        Tests whether the channel has been closed and no more messages await in the channel. If this method returns true all future calls to receive() are guaranteed to return null, and calls to receive on a primitive channel will throw an EOFException.
        Returns:
        true if the channels has been closed and no more messages will be received; false otherwise.
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object