/** * Maximum amount of seconds that nakadi will be waiting for commit after sending a batch to a client. * If the commit does not come within this timeout, nakadi will initialize stream termination, no * new data will be sent. Partitions from this stream will be assigned to other streams. * * @param commitTimeout */ public StreamParameters withCommitTimeout(int commitTimeout) { return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
/** * * Maximum number of empty keep alive batches to get in a row before closing the connection. * * @param streamKeepAliveLimit * If 0 or undefined will send keep alive messages indefinitely. */ public StreamParameters withStreamKeepAliveLimit(int streamKeepAliveLimit) { return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
public StreamParameters withMaxUncommittedEvents(int maxUncommittedEvents) { return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
/** * Maximum time in seconds a stream will live before connection is closed by the server. If 0 or unspecified will stream indefinitely. * If this timeout is reached, any pending messages (in the sense of stream_limit) will be flushed to the client. * * @param streamTimeout * Stream initialization will fail if stream_timeout is lower than batch_flush_timeout * @throws IllegalArgumentException */ public StreamParameters withStreamTimeout(int streamTimeout) throws IllegalArgumentException { if(batchFlushTimeout != null && batchFlushTimeout > streamTimeout){ throw new IllegalArgumentException("stream_timeout is lower than batch_flush_timeout."); } return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
/** * * Maximum number of Events in this stream (over all partitions being streamed in this connection). * * @param streamLimit * If 0 or undefined, will stream batches indefinitely. * Stream initialization will fail if stream_limit is lower than batch_limit. * * @throws IllegalArgumentException */ public StreamParameters withStreamLimit(int streamLimit) throws IllegalArgumentException { if(batchLimit != null && batchLimit > streamLimit){ throw new IllegalArgumentException("streamLimit is lower than batch_limit."); } return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
/** * Maximum time in seconds to wait for the flushing of each chunk (per partition). * * @param batchFlushTimeout * If the amount of buffered Events reaches batch_limit before this batch_flush_timeout is reached, * the messages are immediately flushed to the client and batch flush timer is reset. * If 0 or undefined, will assume 30 seconds. * * @throws IllegalArgumentException */ public StreamParameters withBatchFlushTimeout(int batchFlushTimeout) throws IllegalArgumentException { if (streamTimeout != null && streamTimeout < batchFlushTimeout){ throw new IllegalArgumentException("stream_timeout is lower than batch_flush_timeout."); } return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
/** * * Maximum number of Events in each chunk (and therefore per partition) of the stream. * * * <p> * Note 2017/05/19: the API definition says if the value is 0 or unspecified the server will * buffer events indefinitely and flush on reaching of {@link StreamParameters#batchFlushTimeout}. * This is incorrect - if the server receives a value of '0' it will not send events at * all (effectively it's a silent bug). Because of this if value is set to 0 (or less than 1) * client raise an exception. * </p> * * @param batchLimit * batch_limit must be lower or equal to stream_limit * @throws IllegalArgumentException */ public StreamParameters withBatchLimit(int batchLimit) throws IllegalArgumentException { if(streamLimit != null && streamLimit < batchLimit){ throw new IllegalArgumentException("streamLimit is lower than batch_limit."); } if(batchLimit < DEFAULT_BATCH_LIMIT){ throw new IllegalArgumentException("batch_limit can't be lower than 1."); } return new StreamParameters(batchLimit, streamLimit, batchFlushTimeout, streamTimeout, streamKeepAliveLimit, maxUncommittedEvents, commitTimeout); }
@Override public final <T> IORunnable runnable(EventReader<T> eventReader, Listener<T> listener) { final StreamParameters streamParameters = this.streamParameters != null ? this.streamParameters : new StreamParameters(); final String queryString = streamParameters.toQueryString(); final URI uri = getURI(queryString); final Set<String> eventNames = getEventNames(); final Optional<Subscription> subscription = getSubscription(); final Optional<Lock> lock = getLock(); final BackoffStrategy backoffStrategy = this.backoffStrategy != null ? this.backoffStrategy : new EqualJitterBackoffStrategy(); final MetricsCollector metricsCollector = this.metricsCollector != null ? this.metricsCollector : NoMetricsCollector.NO_METRICS_COLLECTOR; final BatchHandler batchHandler = this.batchHandler != null ? this.batchHandler : DefaultBatchHandler.INSTANCE; return new NakadiReader<>(uri, requestFactory, backoffStrategy, cursorManager, eventNames, subscription, lock, eventReader, listener, batchHandler, metricsCollector); }