Package cz.o2.proxima.beam.direct.io
Class BlockingQueueLogObserver
- java.lang.Object
-
- cz.o2.proxima.beam.direct.io.BlockingQueueLogObserver
-
- All Implemented Interfaces:
BatchLogObserver,LogObserver,java.io.Serializable
final class BlockingQueueLogObserver extends java.lang.Object implements LogObserver, BatchLogObserver
ALogObserverthat caches data inBlockingQueue.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBlockingQueueLogObserver.BatchLogObserverUnifiedContext(package private) static classBlockingQueueLogObserver.LogObserverUnifiedContext(package private) static interfaceBlockingQueueLogObserver.UnifiedContext-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.batch.BatchLogObserver
BatchLogObserver.OnNextContext
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.commitlog.LogObserver
LogObserver.OffsetCommitter, LogObserver.OnIdleContext, LogObserver.OnNextContext, LogObserver.OnRepartitionContext
-
-
Field Summary
Fields Modifier and Type Field Description private booleancancelledprivate java.util.concurrent.CountDownLatchcancelledLatchprivate java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>errorprivate BlockingQueueLogObserver.UnifiedContextlastReadContextprivate BlockingQueueLogObserver.UnifiedContextlastWrittenContextprivate longlimitprivate booleannackAllIncomingprivate java.lang.Stringnameprivate Pair<StreamElement,BlockingQueueLogObserver.UnifiedContext>peekElementprivate java.util.concurrent.BlockingQueue<Pair<StreamElement,BlockingQueueLogObserver.UnifiedContext>>queueprivate static longserialVersionUIDprivate booleanstoppedprivate java.util.concurrent.atomic.AtomicLongwatermark
-
Constructor Summary
Constructors Modifier Constructor Description privateBlockingQueueLogObserver(java.lang.String name, long limit, long startingWatermark)privateBlockingQueueLogObserver(java.lang.String name, long limit, long startingWatermark, int capacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidclearIncomingQueue()private StreamElementconsumePeek()(package private) static BlockingQueueLogObservercreate(java.lang.String name, long startingWatermark)(package private) static BlockingQueueLogObservercreate(java.lang.String name, long limit, long startingWatermark)(package private) static BlockingQueueLogObservercreate(java.lang.String name, long limit, long startingWatermark, int queueCapacity)private booleanenqueue(StreamElement element, BlockingQueueLogObserver.UnifiedContext context)(package private) java.lang.ThrowablegetError()BlockingQueueLogObserver.UnifiedContextgetPeekContext()(package private) longgetWatermark()voidonCancelled()voidonCompleted()booleanonError(java.lang.Throwable error)voidonIdle(LogObserver.OnIdleContext context)booleanonNext(StreamElement element, BatchLogObserver.OnNextContext context)booleanonNext(StreamElement ingest, LogObserver.OnNextContext context)booleanpeekElement()Peek element or returnnullif queue is empty.booleanpeekElement(long timeout, java.util.concurrent.TimeUnit unit)Peek element or returnnullif queue is empty within given timeoutprivate booleanputToQueue(StreamElement element, BlockingQueueLogObserver.UnifiedContext context)private java.lang.ObjectreadResolve()(package private) voidstop()(package private) voidstop(boolean nack)(package private) StreamElementtake()Take next element without blocking.(package private) StreamElementtakeBlocking()Take next element waiting for input if necessary.(package private) StreamElementtakeBlocking(long timeout, java.util.concurrent.TimeUnit unit)Take next element waiting for input if necessary.java.lang.StringtoString()private voidupdateAndLogWatermark(long newWatermark)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.batch.BatchLogObserver
onNext
-
Methods inherited from interface cz.o2.proxima.direct.commitlog.LogObserver
onException, onFatalError, onRepartition
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
name
private final java.lang.String name
-
error
private final java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> error
-
watermark
private final java.util.concurrent.atomic.AtomicLong watermark
-
queue
private final java.util.concurrent.BlockingQueue<Pair<StreamElement,BlockingQueueLogObserver.UnifiedContext>> queue
-
stopped
private volatile boolean stopped
-
nackAllIncoming
private volatile boolean nackAllIncoming
-
lastWrittenContext
@Nullable private BlockingQueueLogObserver.UnifiedContext lastWrittenContext
-
lastReadContext
@Nullable private BlockingQueueLogObserver.UnifiedContext lastReadContext
-
peekElement
@Nullable private Pair<StreamElement,BlockingQueueLogObserver.UnifiedContext> peekElement
-
limit
private long limit
-
cancelled
private boolean cancelled
-
cancelledLatch
private transient java.util.concurrent.CountDownLatch cancelledLatch
-
-
Method Detail
-
create
static BlockingQueueLogObserver create(java.lang.String name, long startingWatermark)
-
create
static BlockingQueueLogObserver create(java.lang.String name, long limit, long startingWatermark)
-
create
static BlockingQueueLogObserver create(java.lang.String name, long limit, long startingWatermark, int queueCapacity)
-
onError
public boolean onError(java.lang.Throwable error)
- Specified by:
onErrorin interfaceBatchLogObserver- Specified by:
onErrorin interfaceLogObserver
-
onNext
public boolean onNext(StreamElement ingest, LogObserver.OnNextContext context)
- Specified by:
onNextin interfaceLogObserver
-
onNext
public boolean onNext(StreamElement element, BatchLogObserver.OnNextContext context)
- Specified by:
onNextin interfaceBatchLogObserver
-
enqueue
private boolean enqueue(StreamElement element, BlockingQueueLogObserver.UnifiedContext context)
-
onCancelled
public void onCancelled()
- Specified by:
onCancelledin interfaceBatchLogObserver- Specified by:
onCancelledin interfaceLogObserver
-
onCompleted
public void onCompleted()
- Specified by:
onCompletedin interfaceBatchLogObserver- Specified by:
onCompletedin interfaceLogObserver
-
putToQueue
private boolean putToQueue(@Nullable StreamElement element, @Nullable BlockingQueueLogObserver.UnifiedContext context) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
onIdle
public void onIdle(LogObserver.OnIdleContext context)
- Specified by:
onIdlein interfaceLogObserver
-
take
@Nullable StreamElement take()
Take next element without blocking.- Returns:
- element that was taken without blocking or
nullotherwise
-
getPeekContext
@Nullable public BlockingQueueLogObserver.UnifiedContext getPeekContext()
-
takeBlocking
@Nullable StreamElement takeBlocking(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Take next element waiting for input if necessary.- Returns:
- element that was taken or
nullon end of input - Throws:
java.lang.InterruptedException
-
takeBlocking
@Nullable StreamElement takeBlocking() throws java.lang.InterruptedException
Take next element waiting for input if necessary.- Returns:
- element that was taken or
nullon end of input - Throws:
java.lang.InterruptedException
-
peekElement
public boolean peekElement()
Peek element or returnnullif queue is empty.- Returns:
trueif queue is not empty after the call
-
peekElement
public boolean peekElement(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionPeek element or returnnullif queue is empty within given timeout- Parameters:
timeout- the timeoutunit- time unit of timeout- Throws:
java.lang.InterruptedException- when interrupted
-
consumePeek
@Nullable private StreamElement consumePeek()
-
getError
@Nullable java.lang.Throwable getError()
-
getWatermark
long getWatermark()
-
stop
void stop()
-
stop
void stop(boolean nack)
-
clearIncomingQueue
void clearIncomingQueue()
-
updateAndLogWatermark
private void updateAndLogWatermark(long newWatermark)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
readResolve
private java.lang.Object readResolve()
-
-