Package org.nuxeo.ecm.core.work
Class NuxeoBlockingQueue
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<Runnable>
-
- org.nuxeo.ecm.core.work.NuxeoBlockingQueue
-
- All Implemented Interfaces:
Iterable<Runnable>,Collection<Runnable>,BlockingQueue<Runnable>,Queue<Runnable>
- Direct Known Subclasses:
MemoryBlockingQueue,RedisBlockingQueue
public abstract class NuxeoBlockingQueue extends AbstractQueue<Runnable> implements BlockingQueue<Runnable>
An abstractBlockingQueuesuitable for a fixed-sizedThreadPoolExecutor, that can be implemented in terms of a few methods.offer(java.lang.Runnable)always succeeds.- Since:
- 5.8
-
-
Field Summary
Fields Modifier and Type Field Description protected Conditionactivationprotected ReentrantLockactivationLockprotected booleanactiveprotected StringqueueIdprotected WorkQueuingqueuing
-
Constructor Summary
Constructors Modifier Constructor Description protectedNuxeoBlockingQueue(String queueId, WorkQueuing queuing)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected longawaitActivation(long nanos)booleancontains(Object o)intdrainTo(Collection<? super Runnable> c)intdrainTo(Collection<? super Runnable> c, int maxElements)abstract intgetQueueSize()Gets the size of the queue.Iterator<Runnable>iterator()protected abstract WorkQueueMetricsmetrics()booleanoffer(Runnable r)booleanoffer(Runnable r, long timeout, TimeUnit unit)Runnablepeek()Runnablepoll()abstract RunnablepollElement()Retrieves and removes an element from the queue, or returns null if the queue is empty.voidput(Runnable r)abstract voidputElement(Runnable r)Adds an element into this queue, waiting if necessary for space to become available.intremainingCapacity()WorkQueueMetricssetActive(boolean active)Sets the queue active or inactive.intsize()protected longtimeUntil(long end)-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.BlockingQueue
add, poll, remove, take
-
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Field Detail
-
activationLock
protected final ReentrantLock activationLock
-
activation
protected final Condition activation
-
active
protected volatile boolean active
-
queueId
protected final String queueId
-
queuing
protected final WorkQueuing queuing
-
-
Constructor Detail
-
NuxeoBlockingQueue
protected NuxeoBlockingQueue(String queueId, WorkQueuing queuing)
-
-
Method Detail
-
metrics
protected abstract WorkQueueMetrics metrics()
-
setActive
public WorkQueueMetrics setActive(boolean active)
Sets the queue active or inactive. When deactivated, taking an element from the queue (take, poll, peek) behaves as if the queue was empty. Elements can still be added when the queue is deactivated. When reactivated, all elements are again available.- Parameters:
active-trueto make the queue active, orfalseto deactivate it
-
offer
public boolean offer(Runnable r)
-
offer
public boolean offer(Runnable r, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerin interfaceBlockingQueue<Runnable>- Throws:
InterruptedException
-
put
public void put(Runnable r) throws InterruptedException
- Specified by:
putin interfaceBlockingQueue<Runnable>- Throws:
InterruptedException
-
timeUntil
protected long timeUntil(long end)
-
awaitActivation
protected long awaitActivation(long nanos) throws InterruptedException- Throws:
InterruptedException
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceBlockingQueue<Runnable>- Specified by:
containsin interfaceCollection<Runnable>- Overrides:
containsin classAbstractCollection<Runnable>
-
size
public int size()
- Specified by:
sizein interfaceCollection<Runnable>- Specified by:
sizein classAbstractCollection<Runnable>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfaceBlockingQueue<Runnable>
-
iterator
public Iterator<Runnable> iterator()
- Specified by:
iteratorin interfaceCollection<Runnable>- Specified by:
iteratorin interfaceIterable<Runnable>- Specified by:
iteratorin classAbstractCollection<Runnable>
-
drainTo
public int drainTo(Collection<? super Runnable> c)
- Specified by:
drainToin interfaceBlockingQueue<Runnable>
-
drainTo
public int drainTo(Collection<? super Runnable> c, int maxElements)
- Specified by:
drainToin interfaceBlockingQueue<Runnable>
-
getQueueSize
public abstract int getQueueSize()
Gets the size of the queue.
-
putElement
public abstract void putElement(Runnable r) throws InterruptedException
Adds an element into this queue, waiting if necessary for space to become available.- Throws:
InterruptedException
-
pollElement
public abstract Runnable pollElement()
Retrieves and removes an element from the queue, or returns null if the queue is empty.
-
-