Skip to content

Instantly share code, notes, and snippets.

@fteychene
Created December 18, 2015 15:16
Show Gist options
  • Save fteychene/4a130e725c0368cd5a87 to your computer and use it in GitHub Desktop.
Save fteychene/4a130e725c0368cd5a87 to your computer and use it in GitHub Desktop.
Sample of structure for Batcher
public class Batcher {
static class Flusher implements Runnable {
private ConcurrentLinkedQueue<Events.Event> queu = new ConcurrentLinkedQueue<>();
@Override
public void run() {
// Flush with defined interval or with special rules
}
public void addEvent(Events.Event event) {
queu.add(event);
}
}
public static Events.Event enrichAndConvert(Map<String, Object> events) {
// Convert event and do what you want
return null;
}
public static void main(String[] args) {
List<Map<String, Object>> events = ImmutableList.of();
Flusher flusher = new Flusher();
ForkJoinPool.commonPool().execute(flusher);
for (Map<String, Object> event : events) {
ForkJoinPool.commonPool().execute(() -> {
flusher.addEvent(enrichAndConvert(event));
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment