-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathBatchRequestSubmitterFactory.java
50 lines (43 loc) · 1.96 KB
/
BatchRequestSubmitterFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.getindata.connectors.http.internal.sink.httpclient;
import java.util.Properties;
import org.apache.flink.util.StringUtils;
import com.getindata.connectors.http.internal.config.ConfigException;
import com.getindata.connectors.http.internal.config.HttpConnectorConfigConstants;
public class BatchRequestSubmitterFactory implements RequestSubmitterFactory {
private final String maxBatchSize;
public BatchRequestSubmitterFactory(int maxBatchSize) {
this.maxBatchSize = String.valueOf(maxBatchSize);
}
@Override
public RequestSubmitter createSubmitter(Properties properties, String[] headersAndValues) {
String batchRequestSize =
properties.getProperty(HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE);
if (StringUtils.isNullOrWhitespaceOnly(batchRequestSize)) {
properties.setProperty(
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE,
maxBatchSize
);
} else {
try {
// TODO Create property validator someday.
int batchSize = Integer.parseInt(batchRequestSize);
if (batchSize < 1) {
throw new ConfigException(
String.format("Property %s must be greater than 0 but was: %s",
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE,
batchRequestSize)
);
}
} catch (NumberFormatException e) {
// TODO Create property validator someday.
throw new ConfigException(
String.format("Property %s must be an integer but was: %s",
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE,
batchRequestSize),
e
);
}
}
return new BatchRequestSubmitter(properties, headersAndValues);
}
}