package schedframe.scheduling; import java.util.Collection; import java.util.Iterator; import org.joda.time.DateTime; import org.joda.time.MutableInterval; import schedframe.resources.ResourceDescription; import schedframe.resources.units.ResourceUnit; /** * This class defines a resource allocation over time * It contains information about time frame and specific resources allocated * It may be initialized by a description of allocated resources or * by a list of allocated resource units (e.g. number of CPUs, memory etc.) * * @author Ariel * @author Marcin Krystek */ public class TimeResourceAllocation extends MutableInterval { /** * */ private static final long serialVersionUID = -8327181428985141349L; /** * Id of this allocation */ protected String id; /** * Contains detail information about resource. */ protected ResourceDescription allocatedResource; protected static int uniqueID_ = -1; protected synchronized int getUniqueID(){ uniqueID_++; return uniqueID_; } public TimeResourceAllocation(DateTime startTime, DateTime endTime) { super(startTime, endTime); allocatedResource = null; id = String.valueOf(getUniqueID()); } public TimeResourceAllocation(ResourceDescription allocatedResource, DateTime startTime, DateTime endTime) { this(startTime, endTime); this.allocatedResource = allocatedResource; } /** * Copy constructor * @param alloc */ public TimeResourceAllocation(TimeResourceAllocation alloc) { super(alloc.getStart(), alloc.getEnd()); this.id = alloc.getId(); this.allocatedResource = (ResourceDescription)alloc.getAllocatedResource().clone(); } public String getId() { return id; } public ResourceDescription getAllocatedResource(){ return this.allocatedResource; } public void setAllocatedResource(ResourceDescription resDesc){ this.allocatedResource = resDesc; } public String toString() { String start = getStart().toString("YYYY-MM-dd HH:mm:ss"); String end = getEnd().toString("YYYY-MM-dd HH:mm:ss"); String resources = ""; String desc = id + " resources: " + resources + " <" + start + " - " + end + ">"; Collection res = this.allocatedResource.getResourceUnit(); if (res != null) { Iterator itr = res.iterator(); while(itr.hasNext()){ ResourceUnit unit = itr.next(); desc += unit; } } return desc; } public boolean equals(Object obj) { if (obj instanceof TimeResourceAllocation == false) return false; TimeResourceAllocation other = (TimeResourceAllocation) obj; if (! id.equals(other.id)) return false; return super.equals(other); } }