From a1f531399fbf78620eb9304888c731f340258767 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 17 May 2016 06:39:25 +0200 Subject: [PATCH] improve I/O Java examples --- examples/java/io/file/Node.java | 21 ++++++++++++++++++--- examples/java/io/file/io_file.tesh | 28 ++++++++++++++++------------ examples/java/io/storage/Client.java | 10 +++------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/examples/java/io/file/Node.java b/examples/java/io/file/Node.java index 89e992b234..3044f17d10 100644 --- a/examples/java/io/file/Node.java +++ b/examples/java/io/file/Node.java @@ -4,6 +4,18 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +/********************* Files and Storage handling **************************** + * This example implements all main file functions of the MSG API + * + * Scenario: Each host + * - opens a file + * - tries to read 10,000 bytes in this file + * - writes 100,000 bytes in the file + * - seeks back to the beginning of the file + * - tries to read 150,000 bytes in this file + * +******************************************************************************/ + package io.file; import org.simgrid.msg.Msg; @@ -54,13 +66,16 @@ public class Node extends Process { Msg.info("Open file " + filename); File file = new File(filename); - long read = file.read(10000000,1); + long read = file.read(10000,1); Msg.info("Having read " + read + " on " + filename); - long write = file.read(100000,1); + long write = file.write(100000,1); Msg.info("Having write " + write + " on " + filename); - read = file.read(10000000,1); + Msg.info("Seek back to the beginning of " + filename); + file.seek(0,file.SEEK_SET); + + read = file.read(150000,1); Msg.info("Having read " + read + " on " + filename); } } diff --git a/examples/java/io/file/io_file.tesh b/examples/java/io/file/io_file.tesh index 7167d37dcf..a03eed5ea3 100644 --- a/examples/java/io/file/io_file.tesh +++ b/examples/java/io/file/io_file.tesh @@ -8,15 +8,19 @@ $ java -classpath ${classpath:=.} io/file/Main ${srcdir:=.}/../platforms/storage > [carl:2:(3) 0.000000] [jmsg/INFO] Open file /home/doc/simgrid/examples/platforms/g5k_cabinets.xml > [bob:3:(4) 0.000000] [jmsg/INFO] Open file /home/doc/simgrid/examples/platforms/nancy.xml > [bob:3:(4) 0.000040] [jmsg/INFO] Having read 4028 on /home/doc/simgrid/examples/platforms/nancy.xml -> [bob:3:(4) 0.000040] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/nancy.xml -> [bob:3:(4) 0.000040] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/nancy.xml -> [denise:0:(1) 0.000085] [jmsg/INFO] Having read 17028 on /home/doc/simgrid/examples/platforms/g5k.xml -> [denise:0:(1) 0.000085] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/g5k.xml -> [denise:0:(1) 0.000085] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/g5k.xml -> [carl:2:(3) 0.000226] [jmsg/INFO] Having read 22645 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml -> [carl:2:(3) 0.000226] [jmsg/INFO] Having write 0 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml -> [carl:2:(3) 0.000226] [jmsg/INFO] Having read 0 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml -> [alice:1:(2) 0.000508] [jmsg/INFO] Having read 101663 on c:\Windows\setupact.log -> [alice:1:(2) 0.000508] [jmsg/INFO] Having write 0 on c:\Windows\setupact.log -> [alice:1:(2) 0.000508] [jmsg/INFO] Having read 0 on c:\Windows\setupact.log -> [0.000508] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... +> [denise:0:(1) 0.000050] [jmsg/INFO] Having read 10000 on /home/doc/simgrid/examples/platforms/g5k.xml +> [alice:1:(2) 0.000050] [jmsg/INFO] Having read 10000 on c:\Windows\setupact.log +> [carl:2:(3) 0.000100] [jmsg/INFO] Having read 10000 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [denise:0:(1) 0.001717] [jmsg/INFO] Having write 100000 on /home/doc/simgrid/examples/platforms/g5k.xml +> [denise:0:(1) 0.001717] [jmsg/INFO] Seek back to the beginning of /home/doc/simgrid/examples/platforms/g5k.xml +> [alice:1:(2) 0.001717] [jmsg/INFO] Having write 100000 on c:\Windows\setupact.log +> [alice:1:(2) 0.001717] [jmsg/INFO] Seek back to the beginning of c:\Windows\setupact.log +> [denise:0:(1) 0.002267] [jmsg/INFO] Having read 110000 on /home/doc/simgrid/examples/platforms/g5k.xml +> [alice:1:(2) 0.002267] [jmsg/INFO] Having read 110000 on c:\Windows\setupact.log +> [bob:3:(4) 0.003374] [jmsg/INFO] Having write 100000 on /home/doc/simgrid/examples/platforms/nancy.xml +> [bob:3:(4) 0.003374] [jmsg/INFO] Seek back to the beginning of /home/doc/simgrid/examples/platforms/nancy.xml +> [carl:2:(3) 0.003433] [jmsg/INFO] Having write 100000 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [carl:2:(3) 0.003433] [jmsg/INFO] Seek back to the beginning of /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [bob:3:(4) 0.004414] [jmsg/INFO] Having read 104028 on /home/doc/simgrid/examples/platforms/nancy.xml +> [carl:2:(3) 0.004533] [jmsg/INFO] Having read 110000 on /home/doc/simgrid/examples/platforms/g5k_cabinets.xml +> [0.004533] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... diff --git a/examples/java/io/storage/Client.java b/examples/java/io/storage/Client.java index 509c32392b..e3e6fcd601 100644 --- a/examples/java/io/storage/Client.java +++ b/examples/java/io/storage/Client.java @@ -5,16 +5,12 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ /********************* Files and Storage handling **************************** - * This example implements all main storage and file functions of the MSG API + * This example implements some storage related functions of the MSG API * * Scenario : * - display information on the disks mounted by the current host - * - create a 200,000 bytes file - * - completely read the created file - * - write 100,000 bytes in the file - * - rename the created file - * - attach some user data to a disk - * - dump disk's contents + * - attach some properties to a disk + * - list all the storage elements in the platform * ******************************************************************************/ -- 2.20.1