Class AbstractStreamConsumer

java.lang.Object
org.apache.nifi.io.nio.consumer.AbstractStreamConsumer
All Implemented Interfaces:
StreamConsumer

public abstract class AbstractStreamConsumer extends Object implements StreamConsumer
  • Field Details

  • Constructor Details

    • AbstractStreamConsumer

      public AbstractStreamConsumer(String id)
  • Method Details

    • setReturnBufferQueue

      public final void setReturnBufferQueue(BufferPool returnQueue)
      Description copied from interface: StreamConsumer
      Will be called once just after construction. It provides the queue to which processed and emptied and cleared buffers must be returned. For each time addFilledBuffer is called there should be an associated add to this given queue. If not, buffers will run out and all stream processing will halt. READ THIS!!!
      Specified by:
      setReturnBufferQueue in interface StreamConsumer
      Parameters:
      returnQueue - pool of buffers to use
    • addFilledBuffer

      public final void addFilledBuffer(ByteBuffer buffer)
      Description copied from interface: StreamConsumer
      Will be called by the thread that produces byte buffers with available data to be processed. If the consumer is finished this should simply return the given buffer to the return buffer queue (after it is cleared)
      Specified by:
      addFilledBuffer in interface StreamConsumer
      Parameters:
      buffer - filled buffer
    • process

      public final void process() throws IOException
      Description copied from interface: StreamConsumer
      Will be called by the thread that executes the consumption of data. May be called many times though once isConsumerFinished returns true this method will likely do nothing.
      Specified by:
      process in interface StreamConsumer
      Throws:
      IOException - if there is an issue processing
    • processBuffer

      protected abstract void processBuffer(ByteBuffer buffer) throws IOException
      Throws:
      IOException
    • signalEndOfStream

      public final void signalEndOfStream()
      Description copied from interface: StreamConsumer
      Called once the end of the input stream is detected
      Specified by:
      signalEndOfStream in interface StreamConsumer
    • onConsumerDone

      protected void onConsumerDone()
      Convenience method that is called when the consumer is done processing based on being told the signal is end of stream and has processed all given buffers.
    • isConsumerFinished

      public final boolean isConsumerFinished()
      Description copied from interface: StreamConsumer
      If true signals the consumer is done consuming data and will not process any more buffers.
      Specified by:
      isConsumerFinished in interface StreamConsumer
      Returns:
      true if finished
    • getId

      public final String getId()
      Description copied from interface: StreamConsumer
      Uniquely identifies the consumer
      Specified by:
      getId in interface StreamConsumer
      Returns:
      identifier of consumer
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object