java.lang.Object
com.renomad.minum.queue.ActionQueue
- All Implemented Interfaces:
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.
-
Constructor Summary
ConstructorDescriptionActionQueue
(String name, Context context) See theActionQueue
description for more detail. -
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 itsAbstractActionQueue.stop()
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 queuetoString()
-
Constructor Details
-
ActionQueue
See theActionQueue
description for more detail. This constructor will build your new action queue and handle registering it with a list of other action queues in theContext
object.- Parameters:
name
- give this object a unique, explanatory name.
-
-
Method Details
-
initialize
Description copied from interface:AbstractActionQueue
Start the queue's processing- Specified by:
initialize
in interfaceAbstractActionQueue
-
enqueue
Adds something to the queue to be processed.Here is an example use of .enqueue:
actionQueue.enqueue("Write person file to disk at " + filePath, () -> { Files.writeString(filePath, pf.serialize()); });
- Specified by:
enqueue
in interfaceAbstractActionQueue
-
stop
public void stop(int count, int sleepTime) Stops the action queue- Specified by:
stop
in interfaceAbstractActionQueue
- Parameters:
count
- how many loops to wait before we crash it closedsleepTime
- how long to wait in milliseconds between loops
-
stop
public 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.- Specified by:
stop
in interfaceAbstractActionQueue
-
toString
-
getQueue
Description copied from interface:AbstractActionQueue
Get theQueue
of data that is supposed to get processed.- Specified by:
getQueue
in interfaceAbstractActionQueue
-
isStopped
public boolean isStopped()Description copied from interface:AbstractActionQueue
Indicate whether this has had itsAbstractActionQueue.stop()
method completed.- Specified by:
isStopped
in interfaceAbstractActionQueue
-