import java.util.List; import java.util.ArrayList; import java.rmi.Remote; /** * Group of instances of a service. * @author Ken Baclawski */ @Copyright public class ServiceGroup { /** * Set of remote objects. */ private List objects = new ArrayList(); /** * Construct a service group. */ public ServiceGroup() { } /** * Add a remote object to the service group. * @param obj The remote object being added to the group. */ public void add(Remote obj) { objects.add(obj); } /** * Get the next object from the group. If the group has more than one * element, then one of them is chosen at random. * @return An object from the group or null if there is no object in the * group. */ public Remote getNext() { int size = objects.size(); if (size == 0) { return null; } else if (size == 1) { return objects.get(0); } else { int i = (int)(size * Math.random()); return objects.get(i); } } }