Skip to content

Commit

Permalink
New enableBatch method
Browse files Browse the repository at this point in the history
  • Loading branch information
csokol committed May 9, 2017
1 parent 87487a0 commit d567e7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/influxdb/InfluxDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.influxdb.dto.Pong;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.BatchProcessor;

/**
* Interface with all available methods to access a InfluxDB database.
Expand Down Expand Up @@ -93,6 +94,14 @@ public String value() {
*/
public boolean isGzipEnabled();

/**
* Enable batching of single Point writes as {@link #enableBatch(int, int, TimeUnit, ThreadFactory)}}
* and {@link #enableBatch(int, int, TimeUnit, ThreadFactory)} with a given {@link org.influxdb.impl.BatchProcessor}
*
* @see org.influxdb.impl.BatchProcessor
*/
public InfluxDB enableBatch(final BatchProcessor batchProcessor);

/**
* Enable batching of single Point writes as {@link #enableBatch(int, int, TimeUnit, ThreadFactory)}}
* using {@linkplain java.util.concurrent.Executors#defaultThreadFactory() default thread factory}.
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/influxdb/impl/InfluxDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ public boolean isGzipEnabled() {
return this.gzipRequestInterceptor.isEnabled();
}

@Override
public InfluxDB enableBatch(BatchProcessor batchProcessor) {
this.batchProcessor = batchProcessor;
this.batchEnabled.set(true);
return this;
}

@Override
public InfluxDB enableBatch(final int actions, final int flushDuration,
final TimeUnit flushDurationTimeUnit) {
Expand All @@ -163,13 +170,13 @@ public InfluxDB enableBatch(final int actions, final int flushDuration,
if (this.batchEnabled.get()) {
throw new IllegalStateException("BatchProcessing is already enabled.");
}
this.batchProcessor = BatchProcessor
BatchProcessor batchProcessor = BatchProcessor
.builder(this)
.actions(actions)
.interval(flushDuration, flushDurationTimeUnit)
.threadFactory(threadFactory)
.build();
this.batchEnabled.set(true);
enableBatch(batchProcessor);
return this;
}

Expand Down

0 comments on commit d567e7c

Please sign in to comment.