Interface StreamConsumer

All Known Implementing Classes:
AbstractStreamConsumer

public interface StreamConsumer
A StreamConsumer must be thread safe. It may be accessed concurrently by a thread providing data to process and another thread that is processing that data.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Will be called by the thread that produces byte buffers with available data to be processed.
    Uniquely identifies the consumer
    boolean
    If true signals the consumer is done consuming data and will not process any more buffers.
    void
    Will be called by the thread that executes the consumption of data.
    void
    Will be called once just after construction.
    void
    Called once the end of the input stream is detected
  • Method Details

    • setReturnBufferQueue

      void setReturnBufferQueue(BufferPool returnQueue)
      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!!!
      Parameters:
      returnQueue - pool of buffers to use
    • addFilledBuffer

      void addFilledBuffer(ByteBuffer buffer)
      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)
      Parameters:
      buffer - filled buffer
    • process

      void process() throws IOException
      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.
      Throws:
      IOException - if there is an issue processing
    • signalEndOfStream

      void signalEndOfStream()
      Called once the end of the input stream is detected
    • isConsumerFinished

      boolean isConsumerFinished()
      If true signals the consumer is done consuming data and will not process any more buffers.
      Returns:
      true if finished
    • getId

      String getId()
      Uniquely identifies the consumer
      Returns:
      identifier of consumer