Created
July 28, 2016 10:41
-
-
Save geneqew/9c023d41f330a9e742ccef10c1b58eb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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