net.lakis.cerebro.jobs.prosumer.poller.units.HybridQueuePoller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cerebro Show documentation
Show all versions of cerebro Show documentation
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();
}
}