Module stormpot

Class RefillPile<T extends Poolable>

Type Parameters:
T - The concrete Poolable object type.
All Implemented Interfaces:
Serializable

public final class RefillPile<T extends Poolable> extends AtomicReference<RefillSlot<T>>
A RefillPile can collect objects, in a concurrent and wait-free manner, before releasing them all to a queue.
See Also:
  • Constructor Details

    • RefillPile

      public RefillPile(BlockingQueue<BSlot<T>> refillQueue)
      Create a refill pile that will refill into the given queue.
      Parameters:
      refillQueue - The queue to refill into.
  • Method Details

    • push

      public void push(BSlot<T> slot)
      Push the given slot onto the stack. This method is wait-free.
      Parameters:
      slot - The slot instance to be pushed onto the stack.
    • pop

      public BSlot<T> pop()
      Remove a slot from the pile, if there is any.
      Returns:
      A slot that was removed from the pile, or null if there were no slots to remove.
    • refill

      public boolean refill()
      Refill the target queue with all the slots that have been pushed onto this stack. This method atomically pops all elements from the stack at once, and then pushed onto the queue one by one.
      Returns:
      true if any slots has been offered to the queue, or false if there were no slots in the pile.
    • toString

      public String toString()
      Overrides:
      toString in class AtomicReference<RefillSlot<T extends Poolable>>