Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tidy the exceptions that can be raised by our Java code
[simgrid.git] / examples / java / io / storage / Client.java
1 /* Copyright (c) 2012-2017. 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 org.simgrid.msg.Msg;
19 import org.simgrid.msg.Host;
20 import org.simgrid.msg.Process;
21 import org.simgrid.msg.Storage;
22 import org.simgrid.msg.HostNotFoundException;
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     for (int i = 0; i < storages.length; i++) {
35       // For each disk mounted on host
36       Msg.info("------------------------------------");
37       Msg.info("Disk name: "+storages[i].getName());
38       Msg.info("Size: "+storages[i].getSize()+" bytes.");
39       Msg.info("Free Size: "+storages[i].getFreeSize()+" bytes.");
40       Msg.info("Used Size: "+storages[i].getUsedSize()+" bytes.");
41     }
42
43     Storage st = Storage.getByName("Disk2");
44     Msg.info("Disk name: "+st.getName());
45     Msg.info("Attached to host:"+st.getHost());
46
47     st.setProperty("key","Pierre");
48     Msg.info("Property key: "+st.getProperty("key"));
49
50     Host h = Host.currentHost();
51     h.setProperty("key2","Pierre");
52     Msg.info("Property key2: "+h.getProperty("key2"));
53
54     String[] attach = h.getAttachedStorage();
55     for (int j = 0; j < attach.length; j++) {
56       Msg.info("Disk attached: "+attach[j]);
57     }
58
59     Msg.info("**************** ALL *************************");
60     Storage[] stos = Storage.all();
61     for (int i = 0; i < stos.length; i++) {
62       Msg.info("Disk: "+ stos[i].getName());
63     }
64   }
65 }