Created
December 18, 2015 15:16
-
-
Save fteychene/4a130e725c0368cd5a87 to your computer and use it in GitHub Desktop.
Sample of structure for Batcher
This file contains hidden or 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
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