Logo AND Algorithmique Numérique Distribuée

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