Class QueueChannel

All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, ExecutorChannelInterceptorAware, QueueChannelOperations, ExpressionCapable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, org.springframework.messaging.MessageChannel, org.springframework.messaging.PollableChannel, org.springframework.messaging.support.InterceptableChannel
Direct Known Subclasses:
PriorityChannel, RendezvousChannel

public class QueueChannel
extends AbstractPollableChannel
implements QueueChannelOperations
Simple implementation of a message channel. Each Message is placed in a BlockingQueue whose capacity may be specified upon construction. The capacity must be a positive integer value. For a zero-capacity version based upon a SynchronousQueue, consider the RendezvousChannel.
  • Field Details

    • queueSemaphore

      protected final java.util.concurrent.Semaphore queueSemaphore
  • Constructor Details

    • QueueChannel

      public QueueChannel​(java.util.Queue<org.springframework.messaging.Message<?>> queue)
      Create a channel with the specified queue.
      Parameters:
      queue - The queue.
    • QueueChannel

      public QueueChannel​(int capacity)
      Create a channel with the specified queue capacity.
      Parameters:
      capacity - The capacity.
    • QueueChannel

      public QueueChannel()
      Create a channel with "unbounded" queue capacity. The actual capacity value is Integer.MAX_VALUE. Note that a bounded queue is recommended, since an unbounded queue may lead to OutOfMemoryErrors.
  • Method Details

    • registerMetricsCaptor

      public void registerMetricsCaptor​(MetricsCaptor metricsCaptor)
      Description copied from interface: IntegrationManagement
      Inject a MetricsCaptor.
      Specified by:
      registerMetricsCaptor in interface IntegrationManagement
      Overrides:
      registerMetricsCaptor in class AbstractMessageChannel
      Parameters:
      metricsCaptor - the captor.
    • doSend

      protected boolean doSend​(org.springframework.messaging.Message<?> message, long timeout)
      Description copied from class: AbstractMessageChannel
      Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.
      Specified by:
      doSend in class AbstractMessageChannel
      Parameters:
      message - The message.
      timeout - The timeout.
      Returns:
      true if the send was successful.
    • doReceive

      @Nullable protected org.springframework.messaging.Message<?> doReceive​(long timeout)
      Description copied from class: AbstractPollableChannel
      Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is empty (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either a message is available or the blocking thread is interrupted.
      Specified by:
      doReceive in class AbstractPollableChannel
      Parameters:
      timeout - The timeout.
      Returns:
      The message, or null.
    • clear

      public java.util.List<org.springframework.messaging.Message<?>> clear()
      Description copied from interface: QueueChannelOperations
      Remove all Messages from this channel.
      Specified by:
      clear in interface QueueChannelOperations
      Returns:
      The messages that were removed.
    • purge

      public java.util.List<org.springframework.messaging.Message<?>> purge​(@Nullable MessageSelector selector)
      Description copied from interface: QueueChannelOperations
      Remove any Messages that are not accepted by the provided selector.
      Specified by:
      purge in interface QueueChannelOperations
      Parameters:
      selector - The message selector.
      Returns:
      The list of messages that were purged.
    • getQueueSize

      public int getQueueSize()
      Description copied from interface: QueueChannelOperations
      Obtain the current number of queued Messages in this channel.
      Specified by:
      getQueueSize in interface QueueChannelOperations
      Returns:
      The current number of queued Messages in this channel.
    • getRemainingCapacity

      public int getRemainingCapacity()
      Description copied from interface: QueueChannelOperations
      Obtain the remaining capacity of this channel.
      Specified by:
      getRemainingCapacity in interface QueueChannelOperations
      Returns:
      The remaining capacity of this channel.
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Specified by:
      destroy in interface IntegrationManagement
      Overrides:
      destroy in class AbstractMessageChannel