9d5ca4dc60be0ac5d89988cb91f23f6ed603e3ba
[IRC.git] / Robust / Transactions / TransactionalIO / src / TransactionalIO / benchmarks / lockthread1.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package TransactionalIO.benchmarks;
7
8 import TransactionalIO.core.TransactionalFile;
9 import java.io.IOException;
10 import java.io.RandomAccessFile;
11 import java.util.logging.Level;
12 import java.util.logging.Logger;
13
14 /**
15  *
16  * @author navid
17  */
18 public class lockthread1 extends Thread{
19
20     RandomAccessFile f1;
21     char sample;
22     public lockthread1(RandomAccessFile file, char sample) {
23         f1 = file;
24         this.sample = sample;
25         this.start();
26     }
27
28     
29     
30     public void run(){
31         try {
32
33
34             //  f1.read(b);
35             byte[] b = new byte[20];
36             for (int j = 0; j < 19; j++) {
37                 b[j] = (byte) sample;
38             }
39             b[19] = (byte) '\n';
40
41             
42
43             //  f1 = (TransactionalFile)benchmark.m.get("0");
44             //  f1 = (TransactionalFile)benchmark.m.get("0");
45             byte[] data = new byte[1];
46             char[] holder = new char[40];
47             benchmark.filelock.lock();
48
49             long toseek = Integer.valueOf(Thread.currentThread().getName().substring(7)) * 20448;
50             f1.seek(toseek);
51
52             data[0] = 'a';
53             if (toseek != 0) {
54                 //////////////// skipt the first word since its been read already
55                 while (data[0] != '\n') {
56                     f1.read(data);
57                 }
58             }
59             while (f1.getFilePointer() < toseek + 20448) {
60                 data[0] = 'a';
61                 int i = 0;
62                 int result = 0;
63                 while (data[0] != '\n') {
64                     result = f1.read(data);
65                     holder[i] = (char) data[0];
66                     i++;
67                 }
68
69                 byte[] towrite = new byte[String.valueOf(holder, 0, i).length()];
70                 towrite = String.valueOf(holder, 0, i).getBytes();
71                 try {
72                     ((TransactionalFile) (benchmark.m.get(String.valueOf(holder,0,i).toLowerCase().substring(0, 1)))).file.write(towrite);
73                 } catch (IOException ex) {
74                     Logger.getLogger(thread1.class.getName()).log(Level.SEVERE, null, ex);
75                 }
76             }
77
78             benchmark.filelock.unlock();
79         } catch (IOException ex) {
80             Logger.getLogger(lockthread1.class.getName()).log(Level.SEVERE, null, ex);
81         }
82            
83
84
85     }
86 }