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 abstractBlockingQueue
suitable 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 Condition
activation
protected ReentrantLock
activationLock
protected boolean
active
protected String
queueId
protected WorkQueuing
queuing
-
Constructor Summary
Constructors Modifier Constructor Description protected
NuxeoBlockingQueue(String queueId, WorkQueuing queuing)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected long
awaitActivation(long nanos)
boolean
contains(Object o)
int
drainTo(Collection<? super Runnable> c)
int
drainTo(Collection<? super Runnable> c, int maxElements)
abstract int
getQueueSize()
Gets the size of the queue.Iterator<Runnable>
iterator()
protected abstract WorkQueueMetrics
metrics()
boolean
offer(Runnable r)
boolean
offer(Runnable r, long timeout, TimeUnit unit)
Runnable
peek()
Runnable
poll()
abstract Runnable
pollElement()
Retrieves and removes an element from the queue, or returns null if the queue is empty.void
put(Runnable r)
abstract void
putElement(Runnable r)
Adds an element into this queue, waiting if necessary for space to become available.int
remainingCapacity()
WorkQueueMetrics
setActive(boolean active)
Sets the queue active or inactive.int
size()
protected long
timeUntil(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
-true
to make the queue active, orfalse
to deactivate it
-
offer
public boolean offer(Runnable r)
-
offer
public boolean offer(Runnable r, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offer
in interfaceBlockingQueue<Runnable>
- Throws:
InterruptedException
-
put
public void put(Runnable r) throws InterruptedException
- Specified by:
put
in 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:
contains
in interfaceBlockingQueue<Runnable>
- Specified by:
contains
in interfaceCollection<Runnable>
- Overrides:
contains
in classAbstractCollection<Runnable>
-
size
public int size()
- Specified by:
size
in interfaceCollection<Runnable>
- Specified by:
size
in classAbstractCollection<Runnable>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfaceBlockingQueue<Runnable>
-
iterator
public Iterator<Runnable> iterator()
- Specified by:
iterator
in interfaceCollection<Runnable>
- Specified by:
iterator
in interfaceIterable<Runnable>
- Specified by:
iterator
in classAbstractCollection<Runnable>
-
drainTo
public int drainTo(Collection<? super Runnable> c)
- Specified by:
drainTo
in interfaceBlockingQueue<Runnable>
-
drainTo
public int drainTo(Collection<? super Runnable> c, int maxElements)
- Specified by:
drainTo
in 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.
-
-