Class EventReceiverFirehoseFactory.EventReceiverFirehose
- java.lang.Object
-
- org.apache.druid.segment.realtime.firehose.EventReceiverFirehoseFactory.EventReceiverFirehose
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.druid.data.input.Firehose,ChatHandler,EventReceiverFirehoseMetric
- Enclosing class:
- EventReceiverFirehoseFactory
public class EventReceiverFirehoseFactory.EventReceiverFirehose extends Object implements ChatHandler, org.apache.druid.data.input.Firehose, EventReceiverFirehoseMetric
Apart from adhering toFirehosecontract 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)andshutdown(java.lang.String, javax.servlet.http.HttpServletRequest). Concurrent data flow: inaddAll(java.io.InputStream, javax.servlet.http.HttpServletRequest)(can be called concurrently with any other methods and other calls toaddAll(java.io.InputStream, javax.servlet.http.HttpServletRequest)) rows are pushed intobuffer. The single Firehose "consumer" thread callshasMore()andnextRow(), where rows are taken out from the other end of thebufferqueue. This class creates and manages one thread (delayedCloseExecutor) for callingclose()asynchronously in response to ashutdown(java.lang.String, javax.servlet.http.HttpServletRequest)request, or after this Firehose has been idle (no calls toaddAll(java.io.InputStream, javax.servlet.http.HttpServletRequest)) forEventReceiverFirehoseFactory.maxIdleTimeMillis.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.ws.rs.core.ResponseaddAll(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).voidclose()This method is synchronized because it might be called concurrently from multiple threads: fromdelayedCloseExecutor, and from the thread that creates and uses the Firehose object.longgetBytesReceived()Return the number of bytes received by the firehose.intgetCapacity()Return the capacity of the buffer.intgetCurrentBufferSize()Return the current number ofInputRowthat are stored in the buffer.booleanhasMore()org.apache.druid.data.input.InputRownextRow()javax.ws.rs.core.Responseshutdown(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.
-
-
-
Method Detail
-
addAll
public javax.ws.rs.core.Response addAll(InputStream in, @Context javax.servlet.http.HttpServletRequest req) throws com.fasterxml.jackson.core.JsonProcessingException
This method might be called concurrently from multiple threads, if multiple requests arrive to the server at the same time (possibly exact duplicates). Concurrency is controlled incheckProducerSequence(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 inbuffer(if twoaddRows(Iterable)are executed concurrently).- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
hasMore
public boolean hasMore()
- Specified by:
hasMorein interfaceorg.apache.druid.data.input.Firehose
-
nextRow
@Nullable public org.apache.druid.data.input.InputRow nextRow()
- Specified by:
nextRowin interfaceorg.apache.druid.data.input.Firehose
-
getCurrentBufferSize
public int getCurrentBufferSize()
Description copied from interface:EventReceiverFirehoseMetricReturn the current number ofInputRowthat are stored in the buffer.- Specified by:
getCurrentBufferSizein interfaceEventReceiverFirehoseMetric
-
getCapacity
public int getCapacity()
Description copied from interface:EventReceiverFirehoseMetricReturn the capacity of the buffer.- Specified by:
getCapacityin interfaceEventReceiverFirehoseMetric
-
getBytesReceived
public long getBytesReceived()
Description copied from interface:EventReceiverFirehoseMetricReturn the number of bytes received by the firehose.- Specified by:
getBytesReceivedin interfaceEventReceiverFirehoseMetric
-
close
public void close()
This method is synchronized because it might be called concurrently from multiple threads: fromdelayedCloseExecutor, and from the thread that creates and uses the Firehose object.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.apache.druid.data.input.Firehose
-
shutdown
public javax.ws.rs.core.Response shutdown(String shutoffTimeMillis, @Context javax.servlet.http.HttpServletRequest req)
This method might be called concurrently from multiple threads, if multiple shutdown requests arrive at the same time. No attempts are made to synchronize such requests, or prioritize them a-la "latest shutdown time wins" or "soonest shutdown time wins".delayedCloseExecutor's logic (seecreateDelayedCloseExecutor()) 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.
-
-