• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Java
  • License
    Artistic License 2.0
  • Created over 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

buffer-trigger

Build Status Coverage Status Total alerts Language grade: Java Maven Central

A local data buffer with customizable data trigger

  • customize trigger strategy
  • buffer container can be customized
  • jdk1.8 only

Usage

// declare
BufferTrigger<String> buffer = SimpleBufferTrigger.<String, Set<String>> newBuilder()
        .triggerStrategy(new MultiIntervalTriggerStrategy()
            .on(10, SECONDS, 1)
            .on(5, SECONDS, 10)
            .on(1, SECONDS, 100)
        )
        .consumer(this::out)
        .setContainer(ConcurrentSkipListSet::new, Set::add) // default is Collections.newSetFromMap(new ConcurrentHashMap<>())
        .build();
        
// enqueue
buffer.enqueue("i'm ok");

// consumer declare
private void out(Collection<String> set) {
	set.forEach(System.out::println);
}

// batch consumer blocking queue
BufferTrigger<String> buffer = BatchConsumeBlockingQueueTrigger.<String> newBuilder()
                .batchSize(3)
                .setConsumerEx(this::out)
                .bufferSize(5)
                .linger(ofSeconds(2))
                .build();
    

Special Thanks

perlmonk with his great team gives me a huge help. (https://github.com/aloha-app)