有一个类Datacenter,其构造函数是:
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());
}
我们使用这个类在程序中创建数据中心:
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;
}
程序运行结果如下:
问题是,如果我通过扩展Datacenter类来定义自己的数据中心,程序将无法工作。我将MyDatacenter类定义如下:
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 */
}
临摹微笑
慕容3067478
相关分类