com.github.avarabyeu.jashing.demo.RandomGraphEventSource Maven / Gradle / Ivy
package com.github.avarabyeu.jashing.demo;
import com.github.avarabyeu.jashing.core.EventSource;
import com.github.avarabyeu.jashing.core.eventsource.ScheduledEventSource;
import com.github.avarabyeu.jashing.events.GraphEvent;
import com.google.common.collect.EvictingQueue;
import java.util.Queue;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Andrei Varabyeu
*/
@EventSource("random-graph-event-source")
public class RandomGraphEventSource extends ScheduledEventSource {
private Random random = new Random();
private AtomicInteger counter = new AtomicInteger();
private Queue points = EvictingQueue.create(10);
@Override
protected GraphEvent produceEvent() {
points.add(new GraphEvent.Point(counter.incrementAndGet(), random.nextInt(100)));
return new GraphEvent(points);
}
}