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

net.lakis.cerebro.jobs.prosumer.poller.units.HybridQueuePoller Maven / Gradle / Ivy

Go to download

A framework to handle dependency injection and allowing users to communicate with the application using command line.

The newest version!
package net.lakis.cerebro.jobs.prosumer.poller.units;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

import lombok.Getter;
import net.lakis.cerebro.jobs.prosumer.poller.Poller;
 
public class HybridQueuePoller extends Poller {

	private @Getter LinkedBlockingQueue queue;

	public HybridQueuePoller(LinkedBlockingQueue queue) {
		this.queue = queue;
	}

	@Override
	public List poll(int count) throws InterruptedException {
		T item = poll();
		List itemList = new ArrayList();
		itemList.add(item);
		for (int i = 1; i < count; i++) {
			item = queue.poll();
			if (item == null)
				break;
			itemList.add(item);
		}
		return itemList;
	}

	@Override
	public T poll() throws InterruptedException {
		return queue.take();
	}

	public void clear() {
		queue.clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy