Skip to content

Instantly share code, notes, and snippets.

@geneqew
Created July 28, 2016 10:41
Show Gist options
  • Save geneqew/9c023d41f330a9e742ccef10c1b58eb5 to your computer and use it in GitHub Desktop.
Save geneqew/9c023d41f330a9e742ccef10c1b58eb5 to your computer and use it in GitHub Desktop.
@Component
public class BulkProcessorFactoryBean extends AbstractFactoryBean<BulkProcessor> {
@Autowired
private Client client;
@Autowired
private Listener bulkProcessorListener;
@Value("${bulk.actionsSize:1000}")
private Integer actionSize;
@Value("${bulk.flushIntervalInSeconds:3}")
private Integer flushInterval;
@Value("${bulk.flushSizeInMB:10}")
private Long flushSize;
@Value("${bulk.concurrentRequestCount:1}")
private Integer concurrentRequest;
@Override
public Class<?> getObjectType() {
return BulkProcessor.class;
}
private BulkProcessor bulkProcessor;
@Override
protected BulkProcessor createInstance() throws Exception {
bulkProcessor = BulkProcessor
.builder(client, bulkProcessorListener).setBulkActions(actionSize).setBulkSize(new ByteSizeValue(flushSize, ByteSizeUnit.MB))
.setFlushInterval(TimeValue.timeValueSeconds(flushInterval)).setConcurrentRequests(concurrentRequest).build();
return bulkProcessor;
}
@Override
public void destroy() throws Exception {
if (bulkProcessor != null) {
bulkProcessor.close();
}
super.destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment