There is a class named Datacenter
in which constructor is:
public Datacenter(
String name,
DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name);
setCharacteristics(characteristics);
setVmAllocationPolicy(vmAllocationPolicy);
setLastProcessTime(0.0);
setStorageList(storageList);
setVmList(new ArrayList<Vm>());
setSchedulingInterval(schedulingInterval);
for (Host host : getCharacteristics().getHostList()) {
host.setDatacenter(this);
}
// If this resource doesn't have any PEs then no useful at all
if (getCharacteristics().getNumberOfPes() == 0) {
throw new Exception(super.getName()
+ " : Error - this entity has no PEs. Therefore, can't process any Cloudlets.");
}
// stores id of this class
getCharacteristics().setId(super.getId());
}
We use this class to make Datacenters in program:
private static Datacenter createDatacenter(String name, LinkedList myHarddriveList, double timeZone) {
/* Additional codes like defining Hots */
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics,
new VmAllocationPolicySimple(hostList), myHarddriveList, 0);
} catch (Exception e) {
System.out.println("Error: " + e);
}
return datacenter;
}
The result of running program is like that:
The problem is that if I define my own Datacenter by extending Datacenter
class the program won't work. I define MyDatacenter
class as following:
public class MyDatacenter extends Datacenter{
/* My own variables */
public MyDatacenter(String name,
DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name,
characteristics,
vmAllocationPolicy,
storageList,
schedulingInterval);
}
/* My own mwthods */
}
So if I change the return type of createDatacenter()
method from Datacenter
to MyDatacenter
the program wont work.
private static MyDatacenter createDatacenter(String name, LinkedList myHarddriveList, double timeZone) {
/* No changes */
MyDatacenter datacenter = null;
try {
datacenter = new MyDatacenter(name, characteristics,
new VmAllocationPolicySimple(hostList), myHarddriveList, 0);
} catch (Exception e) {
System.out.println("Error: " + e);
}
return datacenter;
}
No cloudlet will be assigned to any datacenter:
I can not even cast the created Datacenter
instance to MyDatacenter
.