Skip to content

Commit cb12f31

Browse files
committed
New enableBatch method
1 parent 87487a0 commit cb12f31

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/main/java/org/influxdb/InfluxDB.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public String value() {
101101
*/
102102
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit);
103103

104+
/**
105+
* Enable batching of single Point writes as {@link #enableBatch(int, int, TimeUnit, ThreadFactory, Consumer<Throwable>)}
106+
* using with a exceptionHandler that does nothing.
107+
*
108+
* @see #enableBatch(int, int, TimeUnit, ThreadFactory, Consumer<Throwable>)
109+
*/
110+
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit,
111+
final ThreadFactory threadFactory);
112+
104113
/**
105114
* Enable batching of single Point writes to speed up writes significant. If either actions or
106115
* flushDurations is reached first, a batch write is issued.
@@ -113,10 +122,12 @@ public String value() {
113122
* the time to wait at most.
114123
* @param flushDurationTimeUnit
115124
* @param threadFactory
125+
* @param exceptionHandler
126+
* a consumer function to handle asynchronous errors
116127
* @return the InfluxDB instance to be able to use it in a fluent manner.
117128
*/
118129
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit,
119-
final ThreadFactory threadFactory);
130+
final ThreadFactory threadFactory, final Consumer<Throwable> exceptionHandler);
120131

121132
/**
122133
* Disable Batching.

src/main/java/org/influxdb/impl/InfluxDBImpl.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,21 @@ public InfluxDB enableBatch(final int actions, final int flushDuration,
160160
@Override
161161
public InfluxDB enableBatch(final int actions, final int flushDuration,
162162
final TimeUnit flushDurationTimeUnit, final ThreadFactory threadFactory) {
163+
enableBatch(actions, flushDuration, flushDurationTimeUnit, threadFactory, (throwable) -> { });
164+
return this;
165+
}
166+
167+
@Override
168+
public InfluxDB enableBatch(int actions, int flushDuration, TimeUnit flushDurationTimeUnit, ThreadFactory threadFactory, Consumer<Throwable> exceptionHandler) {
163169
if (this.batchEnabled.get()) {
164170
throw new IllegalStateException("BatchProcessing is already enabled.");
165171
}
166172
this.batchProcessor = BatchProcessor
167-
.builder(this)
168-
.actions(actions)
169-
.interval(flushDuration, flushDurationTimeUnit)
170-
.threadFactory(threadFactory)
171-
.build();
173+
.builder(this)
174+
.actions(actions)
175+
.interval(flushDuration, flushDurationTimeUnit)
176+
.threadFactory(threadFactory)
177+
.build();
172178
this.batchEnabled.set(true);
173179
return this;
174180
}

0 commit comments

Comments
 (0)