Interface Sequenced

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int getBufferSize()
      The capacity of the data structure to hold entries.
      boolean hasAvailableCapacity​(int requiredCapacity)
      Has the buffer got capacity to allocate another sequence.
      long next()
      Claim the next event in sequence for publishing.
      long next​(int n)
      Claim the next n events in sequence for publishing.
      void publish​(long sequence)
      Publishes a sequence.
      void publish​(long lo, long hi)
      Batch publish sequences.
      long remainingCapacity()
      Get the remaining capacity for this sequencer.
      long tryNext()
      Attempt to claim the next event in sequence for publishing.
      long tryNext​(int n)
      Attempt to claim the next n events in sequence for publishing.
    • Method Detail

      • getBufferSize

        int getBufferSize()
        The capacity of the data structure to hold entries.
        Returns:
        the size of the RingBuffer.
      • hasAvailableCapacity

        boolean hasAvailableCapacity​(int requiredCapacity)
        Has the buffer got capacity to allocate another sequence. This is a concurrent method so the response should only be taken as an indication of available capacity.
        Parameters:
        requiredCapacity - in the buffer
        Returns:
        true if the buffer has the capacity to allocate the next sequence otherwise false.
      • remainingCapacity

        long remainingCapacity()
        Get the remaining capacity for this sequencer.
        Returns:
        The number of slots remaining.
      • next

        long next()
        Claim the next event in sequence for publishing.
        Returns:
        the claimed sequence value
      • next

        long next​(int n)
        Claim the next n events in sequence for publishing. This is for batch event producing. Using batch producing requires a little care and some math.
         int n = 10;
         long hi = sequencer.next(n);
         long lo = hi - (n - 1);
         for (long sequence = lo; sequence <= hi; sequence++) {
             // Do work.
         }
         sequencer.publish(lo, hi);
         
        Parameters:
        n - the number of sequences to claim
        Returns:
        the highest claimed sequence value
      • tryNext

        long tryNext​(int n)
              throws InsufficientCapacityException
        Attempt to claim the next n events in sequence for publishing. Will return the highest numbered slot if there is at least requiredCapacity slots available. Have a look at next() for a description on how to use this method.
        Parameters:
        n - the number of sequences to claim
        Returns:
        the claimed sequence value
        Throws:
        InsufficientCapacityException
      • publish

        void publish​(long sequence)
        Publishes a sequence. Call when the event has been filled.
        Parameters:
        sequence -
      • publish

        void publish​(long lo,
                     long hi)
        Batch publish sequences. Called when all of the events have been filled.
        Parameters:
        lo - first sequence number to publish
        hi - last sequence number to publish