Logo AND Algorithmique Numérique Distribuée

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