All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.avarabyeu.jashing.demo.RandomGraphEventSource Maven / Gradle / Ivy

There is a newer version: 0.0.16
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy