public class EventReceiverFirehoseFactory.EventReceiverFirehose extends Object implements ChatHandler, Firehose, EventReceiverFirehoseMetric
Firehose contract regarding concurrency, this class has two methods that might be
called concurrently with any other methods and each other, from arbitrary number of threads: addAll(java.io.InputStream, javax.servlet.http.HttpServletRequest) and
shutdown(java.lang.String, javax.servlet.http.HttpServletRequest).
Concurrent data flow: in addAll(java.io.InputStream, javax.servlet.http.HttpServletRequest) (can be called concurrently with any other methods and other calls to
addAll(java.io.InputStream, javax.servlet.http.HttpServletRequest)) rows are pushed into buffer. The single Firehose "consumer" thread calls hasMore()
and nextRow(), where rows are taken out from the other end of the buffer queue.
This class creates and manages one thread (delayedCloseExecutor) for calling close()
asynchronously in response to a shutdown(java.lang.String, javax.servlet.http.HttpServletRequest) request, or after this Firehose has been idle (no calls to addAll(java.io.InputStream, javax.servlet.http.HttpServletRequest)) for EventReceiverFirehoseFactory.maxIdleTimeMillis.| Modifier and Type | Method and Description |
|---|---|
javax.ws.rs.core.Response |
addAll(InputStream in,
javax.servlet.http.HttpServletRequest req)
This method might be called concurrently from multiple threads, if multiple requests arrive to the server at the
same time (possibly exact duplicates).
|
void |
close()
This method is synchronized because it might be called concurrently from multiple threads: from
delayedCloseExecutor, and from the thread that creates and uses the Firehose object. |
long |
getBytesReceived()
Return the number of bytes received by the firehose.
|
int |
getCapacity()
Return the capacity of the buffer.
|
int |
getCurrentBufferSize()
Return the current number of
InputRow that are stored in the buffer. |
boolean |
hasMore() |
InputRow |
nextRow() |
javax.ws.rs.core.Response |
shutdown(String shutoffTimeMillis,
javax.servlet.http.HttpServletRequest req)
This method might be called concurrently from multiple threads, if multiple shutdown requests arrive at the same
time.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnextRowWithRawpublic javax.ws.rs.core.Response addAll(InputStream in, @Context javax.servlet.http.HttpServletRequest req) throws com.fasterxml.jackson.core.JsonProcessingException
checkProducerSequence(javax.servlet.http.HttpServletRequest, java.lang.String, com.fasterxml.jackson.databind.ObjectMapper), where only
requests with "X-Firehose-Producer-Seq" number greater than the max "X-Firehose-Producer-Seq" in previously
arrived requests are allowed to proceed. After that check requests don't synchronize with each other and
therefore if two large batches are sent with little interval, the events from the batches might be mixed up in
buffer (if two addRows(Iterable) are executed concurrently).com.fasterxml.jackson.core.JsonProcessingExceptionpublic int getCurrentBufferSize()
EventReceiverFirehoseMetricInputRow that are stored in the buffer.getCurrentBufferSize in interface EventReceiverFirehoseMetricpublic int getCapacity()
EventReceiverFirehoseMetricgetCapacity in interface EventReceiverFirehoseMetricpublic long getBytesReceived()
EventReceiverFirehoseMetricgetBytesReceived in interface EventReceiverFirehoseMetricpublic void close()
delayedCloseExecutor, and from the thread that creates and uses the Firehose object.public javax.ws.rs.core.Response shutdown(String shutoffTimeMillis, @Context javax.servlet.http.HttpServletRequest req)
delayedCloseExecutor's logic (see createDelayedCloseExecutor())
is indifferent to shutdown times jumping in arbitrary directions. But once a shutdown request is made, it can't
be cancelled entirely, the shutdown time could only be rescheduled with a new request.Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.