Class FancyBlockingQueue<E>
- java.lang.Object
-
- org.deeplearning4j.optimize.solvers.accumulation.FancyBlockingQueue<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,BlockingQueue<E>
,Queue<E>
,Registerable
public class FancyBlockingQueue<E> extends Object implements BlockingQueue<E>, Registerable
-
-
Field Summary
Fields Modifier and Type Field Description protected BlockingQueue<E>
backingQueue
protected AtomicInteger
barrier
protected AtomicBoolean
bypassMode
protected int
consumers
protected AtomicInteger
currentConsumers
protected ThreadLocal<AtomicLong>
currentStep
protected boolean
isDebug
protected AtomicBoolean
isDone
protected AtomicBoolean
isFirst
protected ReentrantReadWriteLock
lock
protected AtomicInteger
numElementsDrained
protected AtomicInteger
numElementsReady
protected AtomicInteger
secondary
protected AtomicInteger
state
protected AtomicLong
step
-
Constructor Summary
Constructors Constructor Description FancyBlockingQueue(@NonNull BlockingQueue<E> queue)
FancyBlockingQueue(@NonNull BlockingQueue<E> queue, int consumers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
int
drainTo(Collection<? super E> c)
int
drainTo(Collection<? super E> c, int maxElements)
E
element()
void
fallbackToSingleConsumerMode(boolean reallyFallback)
This method enables/disables bypass modeboolean
isEmpty()
Iterator<E>
iterator()
boolean
offer(E e)
boolean
offer(E e, long timeout, TimeUnit unit)
E
peek()
E
poll()
E
poll(long timeout, TimeUnit unit)
void
put(E e)
void
registerConsumers(int consumers)
This method notifies producer about number of consumers for the current consumption cycleint
remainingCapacity()
E
remove()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
protected void
synchronize(int consumers)
E
take()
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
backingQueue
protected BlockingQueue<E> backingQueue
-
consumers
protected volatile int consumers
-
currentStep
protected ThreadLocal<AtomicLong> currentStep
-
step
protected final AtomicLong step
-
state
protected final AtomicInteger state
-
currentConsumers
protected final AtomicInteger currentConsumers
-
isFirst
protected AtomicBoolean isFirst
-
isDone
protected AtomicBoolean isDone
-
barrier
protected AtomicInteger barrier
-
secondary
protected AtomicInteger secondary
-
numElementsReady
protected AtomicInteger numElementsReady
-
numElementsDrained
protected AtomicInteger numElementsDrained
-
bypassMode
protected AtomicBoolean bypassMode
-
isDebug
protected boolean isDebug
-
lock
protected ReentrantReadWriteLock lock
-
-
Constructor Detail
-
FancyBlockingQueue
public FancyBlockingQueue(@NonNull @NonNull BlockingQueue<E> queue)
-
FancyBlockingQueue
public FancyBlockingQueue(@NonNull @NonNull BlockingQueue<E> queue, int consumers)
-
-
Method Detail
-
add
public boolean add(E e)
- Specified by:
add
in interfaceBlockingQueue<E>
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceQueue<E>
-
offer
public boolean offer(E e)
-
fallbackToSingleConsumerMode
public void fallbackToSingleConsumerMode(boolean reallyFallback)
Description copied from interface:Registerable
This method enables/disables bypass mode- Specified by:
fallbackToSingleConsumerMode
in interfaceRegisterable
-
registerConsumers
public void registerConsumers(int consumers)
Description copied from interface:Registerable
This method notifies producer about number of consumers for the current consumption cycle- Specified by:
registerConsumers
in interfaceRegisterable
-
put
public void put(E e) throws InterruptedException
- Specified by:
put
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
-
synchronize
protected void synchronize(int consumers)
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
-
offer
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
take
public E take() throws InterruptedException
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
poll
public E poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceBlockingQueue<E>
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceBlockingQueue<E>
- Specified by:
contains
in interfaceCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<E>
-
drainTo
public int drainTo(Collection<? super E> c)
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
public int drainTo(Collection<? super E> c, int maxElements)
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
-