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>backingQueueprotected AtomicIntegerbarrierprotected AtomicBooleanbypassModeprotected intconsumersprotected AtomicIntegercurrentConsumersprotected ThreadLocal<AtomicLong>currentStepprotected booleanisDebugprotected AtomicBooleanisDoneprotected AtomicBooleanisFirstprotected ReentrantReadWriteLocklockprotected AtomicIntegernumElementsDrainedprotected AtomicIntegernumElementsReadyprotected AtomicIntegersecondaryprotected AtomicIntegerstateprotected AtomicLongstep
-
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 booleanadd(E e)booleanaddAll(Collection<? extends E> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)intdrainTo(Collection<? super E> c)intdrainTo(Collection<? super E> c, int maxElements)Eelement()voidfallbackToSingleConsumerMode(boolean reallyFallback)This method enables/disables bypass modebooleanisEmpty()Iterator<E>iterator()booleanoffer(E e)booleanoffer(E e, long timeout, TimeUnit unit)Epeek()Epoll()Epoll(long timeout, TimeUnit unit)voidput(E e)voidregisterConsumers(int consumers)This method notifies producer about number of consumers for the current consumption cycleintremainingCapacity()Eremove()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()protected voidsynchronize(int consumers)Etake()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:
addin interfaceBlockingQueue<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceQueue<E>
-
offer
public boolean offer(E e)
-
fallbackToSingleConsumerMode
public void fallbackToSingleConsumerMode(boolean reallyFallback)
Description copied from interface:RegisterableThis method enables/disables bypass mode- Specified by:
fallbackToSingleConsumerModein interfaceRegisterable
-
registerConsumers
public void registerConsumers(int consumers)
Description copied from interface:RegisterableThis method notifies producer about number of consumers for the current consumption cycle- Specified by:
registerConsumersin interfaceRegisterable
-
put
public void put(E e) throws InterruptedException
- Specified by:
putin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>
-
synchronize
protected void synchronize(int consumers)
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>
-
offer
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
take
public E take() throws InterruptedException
- Specified by:
takein interfaceBlockingQueue<E>- Throws:
InterruptedException
-
poll
public E poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfaceBlockingQueue<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceBlockingQueue<E>- Specified by:
removein interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceBlockingQueue<E>- Specified by:
containsin interfaceCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>
-
drainTo
public int drainTo(Collection<? super E> c)
- Specified by:
drainToin interfaceBlockingQueue<E>
-
drainTo
public int drainTo(Collection<? super E> c, int maxElements)
- Specified by:
drainToin interfaceBlockingQueue<E>
-
-