1 package at.ac.tuwien.lsdc.types;
3 import java.util.ArrayList;
4 import java.util.HashMap;
6 public class VirtualMachine {
8 private static int count = 0;
10 private PhysicalMachine runningOn;
12 private HashMap<Integer, Application> applications = new HashMap<Integer, Application>();
16 public static final int initialSize = 100;
17 public static final int initialRAM = 50;
18 public static final int initialCPU = 150;
24 public VirtualMachine(int size, int RAM, int CPU, PhysicalMachine pm) {
27 this.size = size + initialSize;
28 this.RAM = RAM + initialRAM;
29 this.CPU = CPU + initialCPU;
33 public boolean startApplication(Application app) {
35 applications.put(app.getID(), app);
36 size = size + app.getSize();
37 RAM = RAM + app.getRam();
38 CPU = CPU + app.getCpu();
44 public boolean stopApplication(Application app) {
45 if (applications.containsKey(app.getID())) {
46 size = size - app.getSize();
47 RAM = RAM - app.getRam();
48 CPU = CPU - app.getCpu();
49 applications.remove(app.getID());
55 private boolean checkApp(Application app) {
56 return (app.getSize() <= availableSize())
57 && (app.getRam() <= availableRAM())
58 && (app.getCpu() <= availableCPU());
61 private int availableSize() {
62 return size - initialSize;
65 private int availableRAM() {
66 return RAM - initialRAM;
69 private int availableCPU() {
70 return CPU - initialCPU;
77 public PhysicalMachine getRunningOn() {
81 public ArrayList<Application> getApplications() {
82 return new ArrayList<Application>(applications.values());
85 public int getSize() {