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

com.alibaba.middleware.ushura.poller.PowerOfTwoPoller Maven / Gradle / Ivy

package com.alibaba.middleware.ushura.poller;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class PowerOfTwoPoller implements Poller{
    private AtomicInteger index = new AtomicInteger(0);
    private List items = new ArrayList();

    public PowerOfTwoPoller(List items){
        this.items = items;
    }

    public T next() {
        return items.get(index.getAndIncrement() & items.size() - 1);
    }

    public Poller refresh(List items) {
        return new PowerOfTwoPoller(items);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy