Class QueueChannel<Message>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static co.paralleluniverse.common.monitoring.FlightRecorder RECORDER  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int capacity()
      The channel's internal buffer capacity.
      void close()
      Closes the channel so that no more messages could be sent to it.
      void close​(java.lang.Throwable t)
      Closes the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer.
      boolean equals​(java.lang.Object other)  
      protected java.lang.Throwable getCloseException()  
      Channels.OverflowPolicy getOverflowPolicy()  
      int getQueueLength()  
      boolean isClosed()
      This method must only be called by the channel's owner (the receiver)
      boolean isSingleConsumer()
      Whether or not the channel supports a single consumer only.
      boolean isSingleProducer()
      Whether or not the channel supports a single producer only.
      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.
      Message receive​(Timeout timeout)
      Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.
      Message receiveFromThread()  
      Message receiveFromThread​(long timeout, java.util.concurrent.TimeUnit unit)  
      java.lang.Object register()  
      java.lang.Object register​(SelectAction<Message> action)  
      void send​(Message message)
      Sends a message to the channel, possibly blocking until there's room available in the channel.
      boolean send​(Message message, long timeout, java.util.concurrent.TimeUnit unit)
      Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.
      boolean send​(Message message, Timeout timeout)
      Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.
      boolean send0​(Message message, boolean sync, boolean timed, long nanos)  
      void sendNonSuspendable​(Message message)  
      protected void sendSync​(Message message)  
      protected void signalAndWait()  
      protected void signalReceivers()  
      protected Condition sync()  
      java.lang.String toString()  
      boolean tryNow​(java.lang.Object token)  
      Message tryReceive()
      Retrieves a message from the channel if one is available.
      boolean trySend​(Message message)
      Sends a message to the channel if the channel has room available.
      void unregister​(java.lang.Object token)  
      protected java.lang.Object writeReplace()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • RECORDER

        public static final co.paralleluniverse.common.monitoring.FlightRecorder RECORDER
    • Constructor Detail

      • QueueChannel

        protected QueueChannel​(co.paralleluniverse.strands.queues.BasicQueue<Message> queue,
                               Channels.OverflowPolicy overflowPolicy,
                               boolean singleConsumer)
      • QueueChannel

        protected QueueChannel​(co.paralleluniverse.strands.queues.BasicQueue<Message> queue,
                               Channels.OverflowPolicy overflowPolicy,
                               boolean singleProducer,
                               boolean singleConsumer)
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • capacity

        public int capacity()
        Description copied from interface: StandardChannel
        The channel's internal buffer capacity.
        Specified by:
        capacity in interface StandardChannel<Message>
        Returns:
        the channel's internal buffer capacity, -1 for an unbounded buffer, and 0 for a transfer channel.
      • isSingleProducer

        public boolean isSingleProducer()
        Description copied from interface: StandardChannel
        Whether or not the channel supports a single producer only.
        Specified by:
        isSingleProducer in interface StandardChannel<Message>
        Returns:
        true if the channel supports no more than one producer; false otherwise.
      • isSingleConsumer

        public boolean isSingleConsumer()
        Description copied from interface: StandardChannel
        Whether or not the channel supports a single consumer only.
        Specified by:
        isSingleConsumer in interface StandardChannel<Message>
        Returns:
        true if the channel supports no more than one consumer; false otherwise.
      • signalReceivers

        protected void signalReceivers()
      • signalAndWait

        protected void signalAndWait()
                              throws SuspendExecution,
                                     java.lang.InterruptedException
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • tryNow

        public boolean tryNow​(java.lang.Object token)
        Specified by:
        tryNow in interface Selectable<Message>
      • send

        public void send​(Message message)
                  throws SuspendExecution,
                         java.lang.InterruptedException
        Description copied from interface: SendPort
        Sends a message to the channel, possibly blocking until there's room available in the channel. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel's OverflowPolicy, set at construction time.
        Specified by:
        send in interface SendPort<Message>
        Parameters:
        message - the message
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • send

        public boolean send​(Message message,
                            long timeout,
                            java.util.concurrent.TimeUnit unit)
                     throws SuspendExecution,
                            java.lang.InterruptedException
        Description copied from interface: SendPort
        Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel's OverflowPolicy, set at construction time.
        Specified by:
        send in interface SendPort<Message>
        Parameters:
        message - the message
        timeout - the maximum duration this method is allowed to wait.
        unit - the timeout's time unit
        Returns:
        true if the message has been sent successfully; false if the timeout has expired.
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • send

        public boolean send​(Message message,
                            Timeout timeout)
                     throws SuspendExecution,
                            java.lang.InterruptedException
        Description copied from interface: SendPort
        Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel's OverflowPolicy, set at construction time.
        Specified by:
        send in interface SendPort<Message>
        Parameters:
        message - the message
        timeout - the method will not block for longer than the amount remaining in the Timeout
        Returns:
        true if the message has been sent successfully; false if the timeout has expired.
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • trySend

        public boolean trySend​(Message message)
        Description copied from interface: SendPort
        Sends a message to the channel if the channel has room available. This method never blocks.
        Specified by:
        trySend in interface SendPort<Message>
        Parameters:
        message - the message
        Returns:
        true if the message has been sent; false otherwise.
      • send0

        public boolean send0​(Message message,
                             boolean sync,
                             boolean timed,
                             long nanos)
                      throws SuspendExecution,
                             java.lang.InterruptedException
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • close

        public void close()
        Description copied from interface: PortAutoCloseable
        Closes the channel so that no more messages could be sent to it. Messages already sent to the channel will still be received.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface PortAutoCloseable
      • close

        public void close​(java.lang.Throwable t)
        Description copied from interface: SendPort
        Closes the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer. The exception will be thrown when the consumer calls ReceivePort's receive or tryReceive, wrapped by a ProducerException. Messages already sent to the channel prior to calling this method will still be received.
        Specified by:
        close in interface SendPort<Message>
        Parameters:
        t - the exception causing the close
      • sendNonSuspendable

        public void sendNonSuspendable​(Message message)
                                throws co.paralleluniverse.strands.queues.QueueCapacityExceededException
        Throws:
        co.paralleluniverse.strands.queues.QueueCapacityExceededException
      • isClosed

        public boolean isClosed()
        This method must only be called by the channel's owner (the receiver)
        Specified by:
        isClosed in interface PortAutoCloseable
        Returns:
        true if the channels has been closed and no more messages will be received; false otherwise.
      • getCloseException

        protected java.lang.Throwable getCloseException()
      • tryReceive

        public Message tryReceive()
        Description copied from interface: ReceivePort
        Retrieves a message from the channel if one is available. This method never blocks.
        Specified by:
        tryReceive in interface ReceivePort<Message>
        Returns:
        a message, or null if one is not immediately available.
      • receive

        public Message receive​(long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws SuspendExecution,
                               java.lang.InterruptedException
        Description copied from interface: ReceivePort
        Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.
        Specified by:
        receive in interface ReceivePort<Message>
        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 PortAutoCloseable.isClosed()), or if the timeout has expired.
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • receive

        public Message receive​(Timeout timeout)
                        throws SuspendExecution,
                               java.lang.InterruptedException
        Description copied from interface: ReceivePort
        Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.
        Specified by:
        receive in interface ReceivePort<Message>
        Parameters:
        timeout - the method will not block for longer than the amount remaining in the Timeout
        Returns:
        a message, or null if the channel has been closed and no more messages await (see PortAutoCloseable.isClosed()), or if the timeout has expired.
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • receiveFromThread

        public Message receiveFromThread()
                                  throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • receiveFromThread

        public Message receiveFromThread​(long timeout,
                                         java.util.concurrent.TimeUnit unit)
                                  throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • getQueueLength

        public int getQueueLength()
      • toString

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

        protected java.lang.Object writeReplace()
                                         throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException