Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / examples / java / io / storage / Client.java
1 /* Copyright (c) 2012-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /********************* Files and Storage handling ****************************
7  * This example implements some storage related functions of the MSG API
8  *
9  * Scenario :
10  * - display information on the disks mounted by the current host
11  * - attach some properties to a disk
12  * - list all the storage elements in the platform
13  *
14 ******************************************************************************/
15
16 package io.storage;
17
18 import java.util.Arrays;
19 import java.util.Comparator;
20 import org.simgrid.msg.Msg;
21 import org.simgrid.msg.Host;
22 import org.simgrid.msg.Process;
23 import org.simgrid.msg.Storage;
24 import org.simgrid.msg.MsgException;
25
26 public class Client extends Process {
27   public Client(Host host, int number) {
28     super(host, Integer.toString(number), null);
29   }
30
31   public void main(String[] args) throws MsgException {
32    // Retrieve all mount points of current host
33     Storage[] storages = getHost().getMountedStorage();
34
35     Arrays.sort(storages, new Comparator<Storage>() {
36         public int compare(Storage a, Storage b) {
37           return a.getName().compareTo(b.getName());
38         }
39       });
40     for (int i = 0; i < storages.length; i++) {
41       // For each disk mounted on host
42       Msg.info("------------------------------------");
43       Msg.info("Disk name: "+storages[i].getName());
44       Msg.info("Size: "+storages[i].getSize()+" bytes.");
45       Msg.info("Free Size: "+storages[i].getFreeSize()+" bytes.");
46       Msg.info("Used Size: "+storages[i].getUsedSize()+" bytes.");
47     }
48
49     Storage st = Storage.getByName("Disk2");
50     Msg.info("Disk name: "+st.getName());
51     Msg.info("Attached to host:"+st.getHost());
52
53     st.setProperty("key","Pierre");
54     Msg.info("Property key: "+st.getProperty("key"));
55
56     Host h = Host.currentHost();
57     h.setProperty("key2","Pierre");
58     Msg.info("Property key2: "+h.getProperty("key2"));
59
60     String[] attach = h.getAttachedStorage();
61     for (int j = 0; j < attach.length; j++) {
62       Msg.info("Disk attached: "+attach[j]);
63     }
64
65     Msg.info("**************** ALL *************************");
66     Storage[] stos = Storage.all();
67     for (int i = 0; i < stos.length; i++) {
68       Msg.info("Disk: "+ stos[i].getName());
69     }
70   }
71 }