Class ACurve.PendingQueue<T>

java.lang.Object
edu.cnu.mdi.splot.pdata.ACurve.PendingQueue<T>
Type Parameters:
T - pending item payload type (e.g. a point, a sample value, etc.)
Enclosing class:
ACurve

protected static final class ACurve.PendingQueue<T> extends Object
A reusable pending-queue helper for streaming/DAQ scenarios.

Producer threads enqueue items lock-free. Application occurs later on the EDT via drainPendingOnEDT(int, Consumer).

  • Constructor Details

    • PendingQueue

      protected PendingQueue()
  • Method Details

    • enqueue

      public void enqueue(T item)
      Enqueue an item (thread-safe, lock-free).
    • enqueueAll

      public void enqueueAll(List<? extends T> items)
      Enqueue multiple items (thread-safe, lock-free).
      Parameters:
      items - items to enqueue (non-null, no null elements)
    • clear

      public void clear()
      Clear any queued (not-yet-applied) items.
    • getPendingCount

      public long getPendingCount()
      Returns:
      approximate number of pending items
    • getTotalEnqueued

      public long getTotalEnqueued()
      Returns:
      total number of items ever enqueued (monotonic)
    • drainPendingOnEDT

      public int drainPendingOnEDT(int max, Consumer<List<T>> applier)
      Drain up to max items on the EDT and apply them in one batch.
      Parameters:
      max - maximum number of items to drain
      applier - called on the EDT with a non-empty batch of items
      Returns:
      number of drained items
      Throws:
      IllegalStateException - if called off the Swing EDT
    • startDrainTimer

      public void startDrainTimer(int periodMs, int maxPerTick, IntSupplier drainAction, IntConsumer drainedCallback)
      Start a Swing Timer that periodically drains queued items on the EDT.
      Parameters:
      periodMs - timer period in milliseconds; if periodMs <= 0, no timer is started
      maxPerTick - maximum number of items to drain per tick (prevents EDT starvation)
      drainAction - action that performs the drain and returns drained count (EDT)
      drainedCallback - optional callback invoked on the EDT with the drained count
    • stopDrainTimer

      public void stopDrainTimer()
      Stop the drain timer if running.