- All Known Implementing Classes:
ActionQueue
public interface AbstractActionQueue
This class provides the ability to pop items into
a queue thread-safely and know they'll happen later.
For example, this is helpful for minum.logging, or passing functions to a minum.database. It lets us run a bit faster, since the I/O actions are happening on a separate thread and the only time required is passing the function of what we want to run later.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
enqueue
(String description, ThrowingRunnable action) Adds something to the queue to be processed.getQueue()
Get theQueue
of data that is supposed to get processed.Start the queue's processingboolean
Indicate whether this has had itsstop()
method completed.void
stop()
This will prevent any new actions being queued (by setting the stop flag to true and thus causing an exception to be thrown when a call is made to [enqueue]) and will block until the queue is empty.void
stop
(int count, int sleepTime) Stops the action queue
-
Method Details
-
initialize
AbstractActionQueue initialize()Start the queue's processing -
enqueue
Adds something to the queue to be processed.An example:
actionQueue.enqueue("Write person file to disk at " + filePath, () -> { Files.writeString(filePath, pf.serialize()); });
-
stop
void stop(int count, int sleepTime) Stops the action queue- Parameters:
count
- how many loops to wait before we crash it closedsleepTime
- how long to wait in milliseconds between loops
-
stop
void stop()This will prevent any new actions being queued (by setting the stop flag to true and thus causing an exception to be thrown when a call is made to [enqueue]) and will block until the queue is empty. -
getQueue
LinkedBlockingQueue<RunnableWithDescription> getQueue()Get theQueue
of data that is supposed to get processed. -
isStopped
boolean isStopped()Indicate whether this has had itsstop()
method completed.
-