Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package brooklyn.policy.followthesun;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brooklyn.entity.Entity;
import brooklyn.entity.Group;
import brooklyn.entity.basic.AbstractEntity;
import brooklyn.entity.basic.AbstractGroup;
import brooklyn.entity.trait.Resizable;
import brooklyn.entity.trait.Startable;
import brooklyn.event.Sensor;
import brooklyn.event.SensorEvent;
import brooklyn.event.SensorEventListener;
import brooklyn.event.basic.BasicNotificationSensor;
import brooklyn.policy.loadbalancing.Movable;
import brooklyn.util.MutableMap;
public class FollowTheSunPool extends AbstractEntity implements Resizable {
// FIXME Remove duplication from BalanceableWorkerPool?
// FIXME Asymmetry between loadbalancing and followTheSun: ITEM_ADDED and ITEM_REMOVED in loadbalancing
// are of type ContainerItemPair, but in followTheSun it is just the `Entity item`.
private static final Logger LOG = LoggerFactory.getLogger(FollowTheSunPool.class);
/** Encapsulates an item and a container; emitted by sensors.
*/
public static class ContainerItemPair implements Serializable {
private static final long serialVersionUID = 1L;
public final Entity container;
public final Entity item;
public ContainerItemPair(Entity container, Entity item) {
this.container = container;
this.item = checkNotNull(item);
}
@Override
public String toString() {
return ""+item+" @ "+container;
}
}
// Pool constituent notifications.
public static BasicNotificationSensor CONTAINER_ADDED = new BasicNotificationSensor(
Entity.class, "followthesun.container.added", "Container added");
public static BasicNotificationSensor CONTAINER_REMOVED = new BasicNotificationSensor(
Entity.class, "followthesun.container.removed", "Container removed");
public static BasicNotificationSensor ITEM_ADDED = new BasicNotificationSensor(
Entity.class, "followthesun.item.added", "Item added");
public static BasicNotificationSensor ITEM_REMOVED = new BasicNotificationSensor(
Entity.class, "followthesun.item.removed", "Item removed");
public static BasicNotificationSensor ITEM_MOVED = new BasicNotificationSensor(
ContainerItemPair.class, "followthesun.item.moved", "Item moved to the given container");
private Group containerGroup;
private Group itemGroup;
private final Set containers = Collections.synchronizedSet(new HashSet());
private final Set items = Collections.synchronizedSet(new HashSet());
private final SensorEventListener