Class XThreadStringBuffer


  • public class XThreadStringBuffer
    extends java.lang.Object
    Thread-safe class that functions as a limited-size buffer of strings
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean abandoned  
      protected java.util.List<java.lang.String> buffer  
      protected boolean complete  
      protected static int MAX_SIZE  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void abandon()
      Signal that the buffer should be abandoned.
      void add​(java.lang.String string)
      Add a string to the buffer, and block if the buffer is full
      java.lang.String fetch()
      Pull an id off the buffer, and wait if there's more to come.
      void signalDone()
      Signal that the operation is complete, and that no more strings will be added.
      • Methods inherited from class java.lang.Object

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

      • MAX_SIZE

        protected static int MAX_SIZE
      • buffer

        protected java.util.List<java.lang.String> buffer
      • complete

        protected boolean complete
      • abandoned

        protected boolean abandoned
    • Constructor Detail

      • XThreadStringBuffer

        public XThreadStringBuffer()
        Constructor
    • Method Detail

      • add

        public void add​(java.lang.String string)
                 throws java.lang.InterruptedException
        Add a string to the buffer, and block if the buffer is full
        Throws:
        java.lang.InterruptedException
      • abandon

        public void abandon()
        Signal that the buffer should be abandoned. Called by the receiving thread!
      • signalDone

        public void signalDone()
        Signal that the operation is complete, and that no more strings will be added. Called by the sending thread!
      • fetch

        public java.lang.String fetch()
                               throws java.lang.InterruptedException
        Pull an id off the buffer, and wait if there's more to come. Called by the receiving thread! Returns null if the operation is complete.
        Throws:
        java.lang.InterruptedException