*** empty log message ***
[IRC.git] / Robust / Transactions / dstm2 / src / dstm2 / SpecialTransactionalFile.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package dstm2;
7
8 import TransactionalIO.core.Wrapper;
9 import TransactionalIO.exceptions.AbortedException;
10 import java.io.File;
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.io.RandomAccessFile;
14
15 /**
16  *
17  * @author navid
18  */
19 public class SpecialTransactionalFile{
20     
21     RandomAccessFile raFile;
22     
23     public SpecialTransactionalFile(File arg0, String arg1) throws FileNotFoundException {
24         raFile = new RandomAccessFile(arg0, arg1);
25     }
26
27     public SpecialTransactionalFile(String arg0, String arg1) throws FileNotFoundException {
28         raFile = new RandomAccessFile(arg0, arg1);
29     }
30
31     
32     private void checkConsisteny(){
33       //    System.out.println(Thread.currentThread());
34         Transaction me = Thread.getTransaction();
35         if (!me.isActive()) {
36                 SpecialLock.getSpecialLock().unlock(me);
37                 throw new AbortedException();
38         }
39         if (me != SpecialLock.getSpecialLock().getOwnerTransaction()){
40           //  System.out.println("trying to lock " + Thread.currentThread());
41             SpecialLock.getSpecialLock().lock(me);
42            // System.out.println("locked " + Thread.currentThread());
43         }
44         
45         if (!me.isActive()) {
46                 SpecialLock.getSpecialLock().unlock(me);
47                 throw new AbortedException();
48         }
49         
50     }
51     
52     
53     public void close() throws IOException {
54         checkConsisteny();
55         raFile.close();
56     }
57
58     
59     public long getFilePointer() throws IOException {
60         checkConsisteny();
61         return raFile.getFilePointer();
62     }
63
64     
65     public long length() throws IOException {
66         checkConsisteny();
67         return raFile.length();
68     }
69
70     
71     public int read() throws IOException {
72         checkConsisteny();
73         return raFile.read();
74     }
75
76     
77     public int read(byte[] arg0, int arg1, int arg2) throws IOException {
78         checkConsisteny();
79         return raFile.read(arg0, arg1, arg2);
80     }
81
82     
83     public int read(byte[] arg0) throws IOException {
84         checkConsisteny();
85         return raFile.read(arg0);
86     }
87
88     
89     public void seek(long arg0) throws IOException {
90         checkConsisteny();
91         raFile.seek(arg0);
92     }
93
94     
95     public void setLength(long arg0) throws IOException {
96         checkConsisteny();
97         raFile.setLength(arg0);
98     }
99
100     
101     public int skipBytes(int arg0) throws IOException {
102         checkConsisteny();
103         return raFile.skipBytes(arg0);
104     }
105
106     
107     public void write(int arg0) throws IOException {
108         checkConsisteny();
109         raFile.write(arg0);
110     }
111
112     
113     public void write(byte[] arg0) throws IOException {
114         checkConsisteny();
115         raFile.write(arg0);
116     }
117
118     
119     public void write(byte[] arg0, int arg1, int arg2) throws IOException {
120         checkConsisteny();
121         raFile.write(arg0, arg1, arg2);
122     }
123     
124     public final void writeInt(int integer) throws IOException{
125         checkConsisteny();
126         raFile.writeInt(integer);
127     }
128     
129     public final int readInt() throws IOException{
130         checkConsisteny();
131         return raFile.readInt();
132     }
133     
134     public final void writeBoolean(boolean bool) throws IOException{
135         checkConsisteny();
136         raFile.writeBoolean(bool);
137     }
138     
139     public final boolean readBoolean() throws IOException{
140         checkConsisteny();
141         return raFile.readBoolean();
142     }
143     
144     public final void writeUTF(String val) throws IOException{
145         checkConsisteny();
146         raFile.writeUTF(val);
147     }
148     
149     public final String readUTF() throws IOException{
150         checkConsisteny();
151         return raFile.readUTF();
152     }
153     
154     public final void writeShort(short val) throws IOException{
155         checkConsisteny();
156         raFile.writeShort(val);
157     }
158     
159     public final short readShort() throws IOException{
160         checkConsisteny();
161         return raFile.readShort();
162     }
163     
164       public final void writeByte(byte arg0) throws IOException{
165         checkConsisteny();
166         raFile.writeByte(arg0);
167     }
168     
169     public final byte readByte() throws IOException{
170         checkConsisteny();
171         return raFile.readByte();
172     }
173     
174     public final void writeChar(int val) throws IOException{
175         checkConsisteny();
176         raFile.writeChar(val);
177     }
178     
179     public final char readChar() throws IOException{
180         checkConsisteny();
181         return raFile.readChar();
182     }
183     
184     public final void writeBytes(String val) throws IOException{
185         checkConsisteny();
186         raFile.writeBytes(val);
187     }
188     
189       public final void writeLong(long val) throws IOException{
190         checkConsisteny();
191         raFile.writeLong(val);
192     }
193     
194     public final long readLong() throws IOException{
195         checkConsisteny();
196         return raFile.readLong();
197     }
198     
199       public final void writeDouble(double arg0) throws IOException{
200         checkConsisteny();
201         raFile.writeDouble(arg0);
202     }
203     
204     public final double readDouble() throws IOException{
205         checkConsisteny();
206         return raFile.readDouble();
207     }
208     
209     public final void writeFloat(float val) throws IOException{
210         checkConsisteny();
211         raFile.writeFloat(val);
212     }
213     
214     public final float readFloat() throws IOException{
215         checkConsisteny();
216         return raFile.readFloat();
217     }
218     
219   
220     
221     
222     
223
224    
225     
226 }