*** empty log message ***
[IRC.git] / Robust / Transactions / dstm2src / benchmark / PureIO.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package dstm2.benchmark;
7
8 import TransactionalIO.benchmarks.benchmark;
9 import TransactionalIO.core.TransactionalFile;
10 import java.io.IOException;
11 import java.io.RandomAccessFile;
12 import java.util.Vector;
13 import java.util.logging.Level;
14 import java.util.logging.Logger;
15
16 /**
17  *
18  * @author navid
19  */
20 public class PureIO extends CustomBenchmark{
21
22     @Override
23     protected void init() {
24         
25     }
26
27
28     protected void execute() {
29         try {
30             TransactionalFile f1 = (TransactionalFile)benchmark.m.get("0");
31            // RandomAccessFile f1 = ((TransactionalFile) benchmark.m.get("0")).file;
32             byte[] data = new byte[1];
33             char[] holder = new char[10000];
34             char[] word = new char[20];
35             boolean flag = false;
36             long toseek = Integer.valueOf(Thread.currentThread().getName().substring(7)) * 20448;
37
38           //  benchmark.filelock.lock();
39             f1.seek(toseek);
40
41             data[0] = 'a';
42             if (toseek != 0) {
43                 //////////////// skipt the first word since its been read already
44                 while (data[0] != '\n') {
45                     int res;
46                     res = f1.read(data);
47                     if (res == -1) {
48                         flag = true;
49                         break;
50                     }
51                 }
52             }
53             while (f1.getFilePointer() < toseek + 20448) {
54                 if (flag == true) {
55                     break;
56                 }
57                 data[0] = 'a';
58                 int i = 0;
59                 int res;
60                 while (data[0] != '\n') {
61                     res = f1.read(data);
62                     if (res == -1) {
63                         flag = true;
64                         break;
65                     }
66
67                     holder[i] = (char) data[0];
68                     i++;
69                 }
70
71
72                 byte[] towrite = new byte[String.valueOf(holder, 0, i).length()];
73                 towrite = String.valueOf(holder, 0, i).getBytes();
74
75
76
77                   //     System.out.println(String.valueOf(holder,0,i).toLowerCase().substring(0, 1));
78                     //((TransactionalFile) (benchmark.m.get(String.valueOf(holder,0,i).toLowerCase().substring(0, 1)))).file.write(towrite);
79                     ((TransactionalFile) (benchmark.m.get(String.valueOf(holder,0,i).toLowerCase().substring(0, 1)))).write(towrite);
80                     //update the memory         //}
81             }
82            // benchmark.filelock.unlock();
83         } catch (IOException ex) {
84             Logger.getLogger(PureIO.class.getName()).log(Level.SEVERE, null, ex);
85         } catch (NullPointerException e) {
86             e.printStackTrace();
87         }
88     }
89
90     @Override
91     protected void printResults() {
92         throw new UnsupportedOperationException("Not supported yet.");
93     }
94
95     @Override
96     protected void execute(Vector arguments) {
97         throw new UnsupportedOperationException("Not supported yet.");
98     }
99
100 }