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

io.vertx.core.eventbus.impl.Handlers Maven / Gradle / Ivy

There is a newer version: 4.5.10
Show newest version
package io.vertx.core.eventbus.impl;

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

/**
 * @author Tim Fox
 */
public class Handlers {

  private final AtomicInteger pos = new AtomicInteger(0);
  public final List list = new CopyOnWriteArrayList<>();

  public HandlerHolder choose() {
    while (true) {
      int size = list.size();
      if (size == 0) {
        return null;
      }
      int p = pos.getAndIncrement();
      if (p >= size - 1) {
        pos.set(0);
      }
      try {
        return list.get(p);
      } catch (IndexOutOfBoundsException e) {
        // Can happen
        pos.set(0);
      }
    }
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy