Package org.apache.storm.utils

## Class JCQueue

- java.lang.Object
- - org.apache.storm.utils.JCQueue

- All Implemented Interfaces:
    `Closeable`, `AutoCloseable`

      public class JCQueue
      extends Object
      implements Closeable

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `JCQueue.Consumer` |
    `static interface` | `JCQueue.ExitCondition` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `JCQueue​(String queueName, String metricNamePrefix, int size, int overflowLimit, int producerBatchSz, IWaitStrategy backPressureWaitStrategy, String topologyId, String componentId, List<Integer> taskIds, int port, StormMetricRegistry metricRegistry)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` |
    `int` | `consume​(JCQueue.Consumer consumer)` | Non blocking.
    `int` | `consume​(JCQueue.Consumer consumer, JCQueue.ExitCondition exitCond)` | Non blocking.
    `void` | `flush()` | if(batchSz>1) : Blocking call.
    `int` | `getOverflowCount()` |
    `int` | `getQueuedCount()` |
    `double` | `getQueueLoad()` |
    `String` | `getQueueName()` |
    `boolean` | `isEmptyOverflow()` |
    `void` | `publish​(Object obj)` | Blocking call.
    `void` | `recordMsgDrop()` |
    `int` | `size()` |
    `boolean` | `tryFlush()` | if(batchSz>1) : Non-Blocking call.
    `boolean` | `tryPublish​(Object obj)` | Non-blocking call, returns false if full.
    `boolean` | `tryPublishDirect​(Object obj)` | Non-blocking call.
    `boolean` | `tryPublishToOverflow​(Object obj)` | Un-batched write to overflowQ.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JCQueue

          public JCQueue​(String queueName,
                         String metricNamePrefix,
                         int size,
                         int overflowLimit,
                         int producerBatchSz,
                         IWaitStrategy backPressureWaitStrategy,
                         String topologyId,
                         String componentId,
                         List<Integer> taskIds,
                         int port,
                         StormMetricRegistry metricRegistry)

  - ### Method Detail

    - #### getQueueName

          public String getQueueName()

    - #### close

          public void close()

      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Closeable`

    - #### consume

          public int consume​(JCQueue.Consumer consumer)

      Non blocking. Returns immediately if Q is empty. Returns number of elements consumed from Q.

    - #### consume

          public int consume​(JCQueue.Consumer consumer,
                             JCQueue.ExitCondition exitCond)

      Non blocking. Returns immediately if Q is empty. Runs till Q is empty OR exitCond.keepRunning() return false. Returns number of elements consumed from Q.

    - #### size

          public int size()

    - #### getQueueLoad

          public double getQueueLoad()

    - #### publish

          public void publish​(Object obj)
                       throws InterruptedException

      Blocking call. Retries till it can successfully publish the obj. Can be interrupted via Thread.interrupt().
      Throws:
        `InterruptedException`

    - #### tryPublish

          public boolean tryPublish​(Object obj)

      Non-blocking call, returns false if full.

    - #### tryPublishDirect

          public boolean tryPublishDirect​(Object obj)

      Non-blocking call. Bypasses any batching that may be enabled on the recvQueue. Intended for sending flush/metrics tuples

    - #### tryPublishToOverflow

          public boolean tryPublishToOverflow​(Object obj)

      Un-batched write to overflowQ. Should only be called by WorkerTransfer returns false if overflowLimit has reached

    - #### recordMsgDrop

          public void recordMsgDrop()

    - #### isEmptyOverflow

          public boolean isEmptyOverflow()

    - #### getOverflowCount

          public int getOverflowCount()

    - #### getQueuedCount

          public int getQueuedCount()

    - #### flush

          public void flush()
                     throws InterruptedException

      if(batchSz>1) : Blocking call. Does not return until at least 1 element is drained or Thread.interrupt() is received if(batchSz==1) : NO-OP. Returns immediately. doesnt throw.
      Throws:
        `InterruptedException`

    - #### tryFlush

          public boolean tryFlush()

      if(batchSz>1) : Non-Blocking call. Tries to flush as many as it can. Returns true if flushed at least 1. if(batchSz==1) : This is a NO-OP. Returns true immediately.