Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadExtension.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadExtension.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadExtension.java	(revision 1285)
@@ -0,0 +1,101 @@
+package schedframe.resources.computing.profiles.load;
+
+import java.util.Properties;
+
+import schedframe.events.Event;
+import schedframe.resources.computing.extensions.Extension;
+import schedframe.resources.computing.extensions.ExtensionException;
+import schedframe.resources.computing.extensions.ExtensionType;
+import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.EnergyEventType;
+import schedframe.resources.computing.profiles.load.ui.LoadInterface;
+import schedframe.resources.devices.PhysicalResource;
+import schedframe.scheduling.manager.tasks.JobRegistryImpl;
+
+public class LoadExtension implements Extension {
+
+	protected LoadInterface loadInterface;
+	protected LoadProfile loadProfile;
+  	protected PhysicalResource resource;
+
+	public LoadExtension(LoadProfile loadProfile,  PhysicalResource resource) {
+		this.loadProfile = loadProfile;
+		this.loadInterface =  LoadInterfaceFactory.createLoadInterface(resource, loadProfile);
+		this.resource = resource;
+	}
+
+	public boolean supportsEvent(Event event) {
+
+		if(loadProfile == null || loadProfile.getLoadEstimationPlugin() == null)
+			return false;
+		if(event.getType().getName().equals(EnergyEventType.POWER_STATE_CHANGED.getName()))
+			return true;
+		else if(event.getType().getName().equals(EnergyEventType.FREQUENCY_CHANGED.getName()))
+			return true;
+		else if(event.getType().getName().equals(EnergyEventType.TASK_STARTED.getName()))
+			return true;
+		else if(event.getType().getName().equals(EnergyEventType.TASK_FINISHED.getName()))
+			return true;
+		else if(event.getType().getName().equals(EnergyEventType.RESOURCE_UTILIZATION_CHANGED.getName()))
+			return true;		
+		else return false;
+	}
+
+	public void handleEvent(Event event) {
+		
+		EnergyEvent enEvent = (EnergyEvent)event;
+		double load = 0;
+		try{
+			switch (enEvent.getType()) {
+			
+			case POWER_STATE_CHANGED:
+				load = loadProfile.getLoadEstimationPlugin().estimateUtlization(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
+				loadProfile.addToLoadHistory(load);
+				break;
+				
+			case FREQUENCY_CHANGED:
+				load = loadProfile.getLoadEstimationPlugin().estimateUtlization(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
+				loadProfile.addToLoadHistory(load);
+				break;
+				
+			case TASK_STARTED:
+				load = loadProfile.getLoadEstimationPlugin().estimateUtlization(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
+				loadProfile.addToLoadHistory(load);
+				break;
+	
+			case TASK_FINISHED:
+				load = loadProfile.getLoadEstimationPlugin().estimateUtlization(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
+				loadProfile.addToLoadHistory(load);
+				break;
+				
+			case RESOURCE_UTILIZATION_CHANGED:
+				load = loadProfile.getLoadEstimationPlugin().estimateUtlization(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
+				loadProfile.addToLoadHistory(load);
+				break;
+
+			}
+		}catch(Exception e){
+			
+		}
+	}
+
+	@Override
+	public void init(Properties properties) throws ExtensionException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public ExtensionType getType() {
+		return ExtensionType.LOAD_EXTENSION;
+	}
+
+	public LoadProfile getLoadProfile() {
+		return loadProfile;
+	}
+
+	public LoadInterface getLoadInterface() {
+		return loadInterface;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/ComputingResourceLoadInterface.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/ComputingResourceLoadInterface.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/ComputingResourceLoadInterface.java	(revision 1285)
@@ -0,0 +1,43 @@
+package schedframe.resources.computing.profiles.load.ui;
+
+import java.util.List;
+
+import org.joda.time.DateTimeUtils;
+
+import schedframe.resources.computing.profiles.energy.MeasurementHistory;
+import schedframe.resources.computing.profiles.load.LoadProfile;
+import schedframe.resources.computing.profiles.load.ResourceLoadCalendar;
+import schedframe.resources.devices.PhysicalResource;
+
+public class ComputingResourceLoadInterface implements LoadInterface{
+
+	protected PhysicalResource resource;
+	protected LoadProfile loadProfile;
+	
+	public ComputingResourceLoadInterface(PhysicalResource resource, LoadProfile loadProfile){
+		this.resource = resource;
+		this.loadProfile = loadProfile;
+	}
+
+	public MeasurementHistory getRecentUtilization() {
+		MeasurementHistory load = null;
+		int lastIdx = getUtilizationHistory().size() - 1;
+		if(lastIdx >= 0)
+			load = getUtilizationHistory().get(lastIdx);
+		else {	
+			load = new MeasurementHistory(DateTimeUtils.currentTimeMillis(), 0);
+		}
+		return load;
+	}
+	
+	public List<MeasurementHistory> getUtilizationHistory(){
+		return loadProfile.getUtilizationHistory();
+	}
+
+	public ResourceLoadCalendar getLoadCalendar() {
+		if(loadProfile == null) {
+			return new ResourceLoadCalendar();
+		}
+		return loadProfile.getLoadCalendar();
+	}
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/LoadInterface.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/LoadInterface.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ui/LoadInterface.java	(revision 1285)
@@ -0,0 +1,16 @@
+package schedframe.resources.computing.profiles.load.ui;
+
+import java.util.List;
+
+import schedframe.resources.computing.profiles.energy.MeasurementHistory;
+import schedframe.resources.computing.profiles.load.ResourceLoadCalendar;
+
+public interface LoadInterface {
+	
+	public MeasurementHistory getRecentUtilization();
+	
+	public List<MeasurementHistory> getUtilizationHistory();
+	
+	public ResourceLoadCalendar getLoadCalendar();
+	
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/plugin/LoadEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/plugin/LoadEstimationPlugin.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/plugin/LoadEstimationPlugin.java	(revision 1285)
@@ -0,0 +1,13 @@
+package schedframe.resources.computing.profiles.load.plugin;
+
+import schedframe.Plugin;
+import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.devices.PhysicalResource;
+import schedframe.scheduling.manager.tasks.JobRegistry;
+
+public interface LoadEstimationPlugin extends Plugin {
+	
+	public double estimateUtlization(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource);
+
+
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/TimestampUtilization.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/TimestampUtilization.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/TimestampUtilization.java	(revision 1285)
@@ -0,0 +1,44 @@
+package schedframe.resources.computing.profiles.load;
+
+public class TimestampUtilization implements Comparable<TimestampUtilization>{
+
+	long startTime;
+	long endTime;
+	double utlization;
+
+	TimestampUtilization(long startTime, long endTime, double utlization) {
+		super();
+		this.startTime = startTime;
+		this.endTime = endTime;
+		this.utlization = utlization;
+	}
+
+	public double getUtlization() {
+		return utlization;
+	}
+	public void setUtlization(double utlization) {
+		this.utlization = utlization;
+	}
+
+	@Override
+	public int compareTo(TimestampUtilization arg0) {
+		if(this.getStartTime() < arg0.getStartTime())
+			return 1;
+		else if (this.getStartTime() > arg0.getStartTime())
+			return -1;
+		else 
+			return 0;
+	}
+	public long getStartTime() {
+		return startTime;
+	}
+	public void setStartTime(long startTime) {
+		this.startTime = startTime;
+	}
+	public long getEndTime() {
+		return endTime;
+	}
+	public void setEndTime(long endTime) {
+		this.endTime = endTime;
+	}
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadProfile.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadProfile.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadProfile.java	(revision 1285)
@@ -0,0 +1,90 @@
+package schedframe.resources.computing.profiles.load;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.joda.time.DateTimeUtils;
+
+import schedframe.Parameters;
+import schedframe.resources.computing.profiles.energy.MeasurementHistory;
+import schedframe.resources.computing.profiles.load.plugin.LoadEstimationPlugin;
+import schemas.LoadCalendar;
+import schemas.WeekDay;
+import schemas.WeekDayTypeChoice;
+import schemas.types.DayType;
+
+public class LoadProfile {
+
+	protected List<MeasurementHistory> utlizationHistory;
+	protected LoadEstimationPlugin loadEstimationPlugin;
+
+	protected ResourceLoadCalendar loadCalendar;
+	
+	protected Parameters parameters;
+	
+
+	public LoadProfile(LoadEstimationPlugin loadEstimationPlugin, ResourceLoadCalendar loadCal) {
+		this.loadEstimationPlugin = loadEstimationPlugin;
+		this.loadCalendar = loadCal;
+		this.utlizationHistory = new ArrayList<MeasurementHistory>();
+	}
+
+
+	public LoadEstimationPlugin getLoadEstimationPlugin() {
+		return loadEstimationPlugin;
+	}
+	
+	public ResourceLoadCalendar getLoadCalendar() {
+		if(loadCalendar == null){
+			LoadCalendar lc = new LoadCalendar();
+			WeekDay weekDay = new WeekDay();
+			weekDay.setType(DayType.VALUE_0);
+			WeekDayTypeChoice wdc = new WeekDayTypeChoice();
+			wdc.setLoadLevel(0);
+			weekDay.setWeekDayTypeChoice(wdc);
+			lc.addWeekDay(weekDay);	
+			return new ResourceLoadCalendar(lc);
+		}
+		return loadCalendar;
+	}
+
+	public boolean addToLoadHistory(double load) {
+
+		if (utlizationHistory.size() == 0) {
+			MeasurementHistory usage = new MeasurementHistory(DateTimeUtils.currentTimeMillis(), load);
+			utlizationHistory.add(usage);
+			return true;
+		}
+
+		boolean status = false;
+		int lastIdx = utlizationHistory.size() - 1;
+		double lastLoad = utlizationHistory.get(lastIdx).getValue();
+		if (lastLoad != load) {
+			status = true;
+			MeasurementHistory util = utlizationHistory.get(lastIdx);
+			long currentTime = DateTimeUtils.currentTimeMillis();
+			if (util.getTimestamp() == currentTime) {
+				util.setValue(load);
+				if(lastIdx > 0 && utlizationHistory.get(lastIdx - 1).getValue() == load)
+					utlizationHistory.remove(util);
+			} else {
+				util = new MeasurementHistory(DateTimeUtils.currentTimeMillis(), load);
+				utlizationHistory.add(util);
+			}
+		}
+		return status;
+	}
+
+	public List<MeasurementHistory> getUtilizationHistory() {
+		return utlizationHistory;
+	}
+
+	public void init(Parameters params){
+		this.parameters = params;
+	}
+	
+	public Parameters getParameters() {
+		return parameters;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ResourceLoadCalendar.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ResourceLoadCalendar.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ResourceLoadCalendar.java	(revision 1285)
@@ -0,0 +1,150 @@
+package schedframe.resources.computing.profiles.load;
+
+import java.util.LinkedList;
+
+import org.joda.time.DateTimeUtilsExt;
+
+import schemas.LoadCalendar;
+import schemas.LoadDistribution;
+import schemas.LoadSchedule;
+
+
+public class ResourceLoadCalendar {
+	
+	//private Day[] week;
+	private LinkedList<TimestampUtilization> loadDistribution;
+	
+	public ResourceLoadCalendar(LoadCalendar loadCalendar){
+		/*week = new Day[7];
+		for(int i = 0; i < 7; i++){
+			week[i] = new Day();
+		}*/
+		
+		loadDistribution = new LinkedList<TimestampUtilization>();
+		
+		for(int i = 0; i < loadCalendar.getLoadScheduleCount(); i++){
+			LoadSchedule loadSched = loadCalendar.getLoadSchedule(i);
+			for(int j = 0; j < loadSched.getLoadDistributionCount(); j++){
+				LoadDistribution ld = loadSched.getLoadDistribution(j);
+				TimestampUtilization tu = new TimestampUtilization(ld.getFromTime(), ld.getToTime(), ld.getLoadLevel());
+				loadDistribution.add(tu);
+			}
+		}
+		
+		/*for(int i = 0; i < loadCalendar.getWeekDayCount(); i++){
+			WeekDay weekDay = loadCalendar.getWeekDay(i);
+			if(weekDay.getType().equals(DayType.VALUE_0)){
+				WeekDayTypeChoice wdc = weekDay.getWeekDayTypeChoice();
+				for(int j = 0; j < 7; j++){
+					if(wdc.hasLoadLevel()){
+						TimeUtilization tu = new TimeUtilization (new LocalTime(0, 0), new LocalTime(23, 59), wdc.getLoadLevel());
+						week[j].add(tu);
+					} else {
+						for(int k = 0; k < wdc.getTimePeriodCount(); k++){
+							TimePeriod tp = wdc.getTimePeriod(k);
+							TimeUtilization tu = new TimeUtilization (new LocalTime(tp.getFromTime().getHour(), tp.getFromTime().getMinute()), new LocalTime(tp.getToTime().getHour(), tp.getToTime().getMinute()), tp.getLoadLevel());
+							week[j].add(tu);
+						}
+					}
+				}
+			} else {
+				WeekDayTypeChoice wdc = weekDay.getWeekDayTypeChoice();
+				if(wdc.hasLoadLevel()){
+					TimeUtilization tu = new TimeUtilization (new LocalTime(0, 0), new LocalTime(23, 59), wdc.getLoadLevel());
+					week[weekDay.getType().ordinal() - 1].add(tu);
+				} else {
+					for(int k = 0; k < wdc.getTimePeriodCount(); k++){
+						TimePeriod tp = wdc.getTimePeriod(k);
+						TimeUtilization tu = new TimeUtilization (new LocalTime(tp.getFromTime().getHour(), tp.getFromTime().getMinute()), new LocalTime(tp.getToTime().getHour(), tp.getToTime().getMinute()), tp.getLoadLevel());
+						week[weekDay.getType().ordinal() - 1].add(tu);
+					}
+				}
+			}	
+		}*/
+	}
+	
+	public ResourceLoadCalendar(){
+		loadDistribution = new LinkedList<TimestampUtilization>();
+	}
+	
+	/*public double getLoad(DateTime dateTime){
+		int dayType = dateTime.getDayOfWeek();
+		int timeOfDay = dateTime.getMillisOfDay();
+		Day day = week[dayType];
+		for(TimeUtilization tu: day){
+			if(tu.getStartTime().getMillisOfDay() <= timeOfDay && tu.getEndTime().getMillisOfDay() > timeOfDay)
+				return tu.getUtlization();
+		}
+		return 0;
+	}*/
+	
+	public double getCurrentLoad(){
+		long simStartTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis();
+		long currentTime = DateTimeUtilsExt.currentTimeMillis();
+		long runTime = (currentTime-simStartTime) / 1000;
+
+		for(int i = 0; i < loadDistribution.size(); i++){
+			TimestampUtilization tu = loadDistribution.get(i);
+			if(tu.getStartTime() == runTime) {
+				return loadDistribution.get(i).getUtlization();
+			} else if(tu.getStartTime() > runTime && i != 0) {
+				return loadDistribution.get(i-1).getUtlization();
+			}
+		}
+		return 0;
+	}
+
+	public LinkedList<TimestampUtilization> getLoadDistribution() {
+		return loadDistribution;
+	}
+}
+
+/*class Day extends ArrayList<TimeUtilization> {
+
+	private static final long serialVersionUID = -1788266677275361001L;
+}
+
+class TimeUtilization implements Comparable<TimeUtilization>{
+
+	LocalTime startTime;
+	LocalTime endTime;
+	double utlization;
+
+	TimeUtilization(LocalTime startTime, LocalTime endTime, double utlization) {
+		super();
+		this.startTime = startTime;
+		this.endTime = endTime;
+		this.utlization = utlization;
+	}
+
+	public double getUtlization() {
+		return utlization;
+	}
+	public void setUtlization(double utlization) {
+		this.utlization = utlization;
+	}
+
+	@Override
+	public int compareTo(TimeUtilization arg0) {
+		if(this.getStartTime().getMillisOfDay() < arg0.getStartTime().getMillisOfDay() )
+			return 1;
+		else if (this.getStartTime().getMillisOfDay() > arg0.getStartTime().getMillisOfDay() )
+			return -1;
+		else 
+			return 0;
+	}
+	public LocalTime getStartTime() {
+		return startTime;
+	}
+	public void setStartTime(LocalTime startTime) {
+		this.startTime = startTime;
+	}
+	public LocalTime getEndTime() {
+		return endTime;
+	}
+	public void setEndTime(LocalTime endTime) {
+		this.endTime = endTime;
+	}
+}
+*/
+
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadEstimationPluginFactory.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadEstimationPluginFactory.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadEstimationPluginFactory.java	(revision 1285)
@@ -0,0 +1,22 @@
+package schedframe.resources.computing.profiles.load;
+
+import example.energy.coolemall.DefaultLoadEstimationPlugin;
+import example.load.ProcessorLoadEstimationPlugin;
+import schedframe.resources.ResourceType;
+import schedframe.resources.StandardResourceType;
+import schedframe.resources.computing.profiles.load.plugin.LoadEstimationPlugin;
+
+public class LoadEstimationPluginFactory {
+
+	
+	public static LoadEstimationPlugin createLoadEstimationPlugi(ResourceType resType){
+		LoadEstimationPlugin loadEstimationPlugin = null;
+		
+		if(resType.getName().equals(StandardResourceType.Processor.getName()))
+			loadEstimationPlugin = new ProcessorLoadEstimationPlugin();
+		else
+			loadEstimationPlugin = new DefaultLoadEstimationPlugin();
+		
+		return loadEstimationPlugin;
+	}
+}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadInterfaceFactory.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadInterfaceFactory.java	(revision 1285)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadInterfaceFactory.java	(revision 1285)
@@ -0,0 +1,19 @@
+package schedframe.resources.computing.profiles.load;
+
+import schedframe.resources.computing.profiles.load.ui.ComputingResourceLoadInterface;
+import schedframe.resources.computing.profiles.load.ui.LoadInterface;
+import schedframe.resources.devices.PhysicalResource;
+
+public class LoadInterfaceFactory {
+
+	
+	public static LoadInterface createLoadInterface(PhysicalResource resource, LoadProfile lp){
+		//if(lp == null)
+		//	return null;
+		LoadInterface loadInterface ;
+		
+		loadInterface = new ComputingResourceLoadInterface(resource, lp);
+		
+		return loadInterface;
+	}
+}
