Package edu.cnu.mdi.splot.pdata
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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear any queued (not-yet-applied) items.intdrainPendingOnEDT(int max, Consumer<List<T>> applier) Drain up tomaxitems on the EDT and apply them in one batch.voidEnqueue an item (thread-safe, lock-free).voidenqueueAll(List<? extends T> items) Enqueue multiple items (thread-safe, lock-free).longlongvoidstartDrainTimer(int periodMs, int maxPerTick, IntSupplier drainAction, IntConsumer drainedCallback) Start a SwingTimerthat periodically drains queued items on the EDT.voidStop the drain timer if running.
-
Constructor Details
-
PendingQueue
protected PendingQueue()
-
-
Method Details
-
enqueue
Enqueue an item (thread-safe, lock-free). -
enqueueAll
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
Drain up tomaxitems on the EDT and apply them in one batch.- Parameters:
max- maximum number of items to drainapplier- 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 SwingTimerthat periodically drains queued items on the EDT.- Parameters:
periodMs- timer period in milliseconds; ifperiodMs <= 0, no timer is startedmaxPerTick- 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.
-