Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
381e7b024a52d5dbd96fb8a44f8bc3991548d342
[simgrid.git] / examples / deprecated / java / io / storage / Client.java
1 /* Copyright (c) 2012-2020. 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 org.simgrid.msg.Msg;
20 import org.simgrid.msg.Host;
21 import org.simgrid.msg.Process;
22 import org.simgrid.msg.Storage;
23 import org.simgrid.msg.MsgException;
24
25 public class Client extends Process {
26   public Client(Host host, int number) {
27     super(host, Integer.toString(number), null);
28   }
29
30   public void main(String[] args) throws MsgException {
31    // Retrieve all mount points of current host
32     Storage[] storages = getHost().getMountedStorage();
33
34     Arrays.sort(storages, (Storage a, Storage b) -> a.getName().compareTo(b.getName()));
35     for (int i = 0; i < storages.length; i++) {
36       // For each disk mounted on host
37       Msg.info("------------------------------------");
38       Msg.info("Disk name: "+storages[i].getName());
39       Msg.info("Size: "+storages[i].getSize()+" bytes.");
40       Msg.info("Free Size: "+storages[i].getFreeSize()+" bytes.");
41       Msg.info("Used Size: "+storages[i].getUsedSize()+" bytes.");
42     }
43
44     Storage st = Storage.getByName("Disk2");
45     Msg.info("Disk name: "+st.getName());
46     Msg.info("Attached to host:"+st.getHost());
47
48     st.setProperty("key","Pierre");
49     Msg.info("Property key: "+st.getProperty("key"));
50
51     Host h = Host.currentHost();
52     h.setProperty("key2","Pierre");
53     Msg.info("Property key2: "+h.getProperty("key2"));
54
55     String[] attach = h.getAttachedStorage();
56     for (int j = 0; j < attach.length; j++) {
57       Msg.info("Disk attached: "+attach[j]);
58     }
59
60     Msg.info("**************** ALL *************************");
61     Storage[] stos = Storage.all();
62     for (int i = 0; i < stos.length; i++) {
63       Msg.info("Disk: "+ stos[i].getName());
64     }
65   }
66 }