How to Store and Retrieve files in Cloudsim

  • HarddriveStorage class is used to virtually create the specified storage space. Cloudsim class also has “File” class which is used to add the files in the created Harddrive storage space.
  • int num_user = 1;
    Calendar calendar = Calendar.getInstance();
    boolean trace_flag = false;
    CloudSim.init(num_user, calendar, trace_flag);
    //******************************************************
    //Creating Storages
    HarddriveStorage hd1 = new HarddriveStorage(1024);
    HarddriveStorage hd2 = new HarddriveStorage(1024);
    HarddriveStorage hd3 = new HarddriveStorage(1024);
    System.out.println("* * *");
    System.out.println("Used disk space on hd1=" + hd1.getCurrentSize());
    System.out.println("Used disk space on hd2=" + hd2.getCurrentSize());
    System.out.println("Used disk space on hd3=" + hd3.getCurrentSize());
    System.out.println("* * *");
    //Creating 3 Files
    //Attention: This is the "org.cloudbus.cloudsim.File" class!!
    File file1 = new File("file1.dat", 300);
    File file2 = new File("file2.dat", 300);
    File file3 = new File("file3.dat", 300);
    hd1.addFile(file1);
    hd2.addFile(file2);
    hd3.addFile(file3);
    //************************************************************
    LinkedList hdList = new LinkedList();
    hdList.add(hd1);
    hdList.add(hd2);
    hdList.add(hd3);
    //You can add files into datacenter by Datacenter.addFile method too.
    //Look inside createDatacenter() method!!
    Datacenter mydc = createDatacenter("MyDC", hdList);
    DatacenterBroker broker = createBroker();
    int brokerId = broker.getId();
    CloudSim.startSimulation();
    System.out.println("* * *");
    System.out.println("Used disk space on hd1=" + hd1.getCurrentSize());
    System.out.println("Used disk space on hd2=" + hd2.getCurrentSize());
    System.out.println("Used disk space on hd3=" + hd3.getCurrentSize());
    System.out.println("* * *");
    double capacity1=hd1.getAvailableSpace();
    double capacity2=hd2.getAvailableSpace();
    double capacity3=hd3.getAvailableSpace();