*** empty log message ***
authornavid <navid>
Wed, 28 Jan 2009 19:05:06 +0000 (19:05 +0000)
committernavid <navid>
Wed, 28 Jan 2009 19:05:06 +0000 (19:05 +0000)
Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/Main.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/thread1.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionLocalFileAttributes.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java

index 7797e9087f812f1ac161a042aae8fbafc5ef2ba9..28f3b68809a429bf01b4cf453cf9619bbb5a6c9f 100644 (file)
@@ -9,6 +9,7 @@ import TransactionalIO.core.CustomThread;
 import TransactionalIO.core.ExtendedTransaction;
 import TransactionalIO.core.TransactionalFile;
 import java.io.File;
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.TreeMap;
 import java.util.logging.Level;
@@ -137,7 +138,11 @@ public class Main {
             }*/
             int index =97;
             for (int j = 0; j < 26; j++) {
-                ((TransactionalFile)(benchmark.m.get(String.valueOf((char) (index+j))))).close();
+                try {
+                    ((TransactionalFile) (benchmark.m.get(String.valueOf((char) (index+j))))).close();
+                } catch (IOException ex) {
+                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+                }
             }
       //  }
               
index 2d410d9b99210e8dc5f1fa6f3d9da2894844ab6b..e2174af3fcd9b4f9117a471468b1608ac7e0c99b 100644 (file)
@@ -54,47 +54,50 @@ public class thread1 implements TransactionalProgram{
     
    
     public void execute() {
-        //TransactionalFile f1 = (TransactionalFile)benchmark.TransactionalFiles.get("0");
+        try {
+            //TransactionalFile f1 = (TransactionalFile)benchmark.TransactionalFiles.get("0");
             TransactionalFile f1;
-            if (tf != null)
+            if (tf != null) {
                 f1 = tf;
-            else 
-                f1 = (TransactionalFile)benchmark.m.get("0");
+            } else {
+                f1 = (TransactionalFile) benchmark.m.get("0");
+            }
             byte[] b = new byte[20];
             byte[] data = new byte[1];
             char[] holder = new char[30];
-   
-            
-           long toseek = (Integer.valueOf(Thread.currentThread().getName().substring(7)))%20 * 20448; 
-           f1.seek(toseek);
-           
-           data[0] ='a';
-           if (toseek != 0) //////////////// skipt the first word since its been read already
-                while (data[0] != '\n'){
+
+
+            long toseek = (Integer.valueOf(Thread.currentThread().getName().substring(7))) % 20 * 20448;
+            f1.seek(toseek);
+
+            data[0] = 'a';
+            if (toseek != 0) {
+                //////////////// skipt the first word since its been read already
+                while (data[0] != '\n') {
                     f1.read(data);
                 }
-               
-               
-           while (f1.getFilePointer() < toseek +20448)
-           {
+            }
+            while (f1.getFilePointer() < toseek + 20448) {
                 data[0] = 'a';
                 int i = 0;
                 int result = 0;
-                while (data[0] != '\n'){
+                while (data[0] != '\n') {
                     result = f1.read(data);
-                    holder[i] = (char)data[0];
+                    holder[i] = (char) data[0];
                     i++;
                 }
-                
-                byte[] towrite = new byte[String.valueOf(holder,0,i).length()];
-                towrite = String.valueOf(holder,0,i).getBytes();
-               try {
-                      ((TransactionalFile) (benchmark.m.get(String.valueOf(holder,0,i).toLowerCase().substring(0, 1)))).write(towrite);         
-                      
+
+                byte[] towrite = new byte[String.valueOf(holder, 0, i).length()];
+                towrite = String.valueOf(holder, 0, i).getBytes();
+                try {
+                    ((TransactionalFile) (benchmark.m.get(String.valueOf(holder,0,i).toLowerCase().substring(0, 1)))).write(towrite);
                 } catch (IOException ex) {
                     Logger.getLogger(thread1.class.getName()).log(Level.SEVERE, null, ex);
                 }
-           }
+            }
+        } catch (IOException ex) {
+            Logger.getLogger(thread1.class.getName()).log(Level.SEVERE, null, ex);
+        }
     }
     
 
index d836c22dfa783689aecd346a3a2a05d3dcf597e2..21d2e89c3d0c153818712b8ed5d84389aaa15ec7 100644 (file)
@@ -25,8 +25,10 @@ public class TransactionLocalFileAttributes {
     private boolean unknown_inital_offset_for_write = true;
     private long localoffset;
     private long localsize;
+    private boolean open;
     
     public TransactionLocalFileAttributes(long initialoffset, long initialsize){
+        open = true;
         localoffset = initialoffset;
         copylocaloffset = initialoffset;
         localsize = initialsize;
@@ -38,6 +40,10 @@ public class TransactionLocalFileAttributes {
         //localsize = initialsize;
     }
 
+    public void setOpen(boolean flag){
+        open = flag;
+    }
+    
     public long getCopylocaloffset() {
         return copylocaloffset;
     }
index 694246a95148be1a06a62bf13e306cf115b15472..a6e9e4633a467e1c3c889695c09c315324923499 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.TreeMap;
 import java.util.Vector;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.Lock;
 
 import java.util.concurrent.locks.ReentrantLock;
@@ -58,6 +59,7 @@ public class TransactionalFile implements Comparable {
     public boolean appendmode = false;
     public ReentrantLock offsetlock;
     private GlobalOffset committedoffset;
+    AtomicBoolean open = new AtomicBoolean(true);
     
    
     private GlobalINodeState inodestate;
@@ -97,11 +99,16 @@ public class TransactionalFile implements Comparable {
         if (inodestate != null) {
             synchronized (inodestate) {
                 committedoffset = new GlobalOffset(0);
+                open .set(true);
                 
             }
         }
     }
     
+    public boolean isOpen(){
+        return open.get();
+    }
+    
     public TransactionalFile(String filename, String mode) {
 
 
@@ -153,6 +160,7 @@ public class TransactionalFile implements Comparable {
         if (inodestate != null) {
             synchronized (inodestate) {
                 committedoffset = new GlobalOffset(0);
+                open.set(true);
             }
         }
 
@@ -202,16 +210,31 @@ public class TransactionalFile implements Comparable {
         return inode;
     }
 
-    public void close() {
-        try {
+    public void close() throws IOException {
+        ExtendedTransaction me = Wrapper.getTransaction();
+        if (!(open.get()))
+            throw new IOException();
+            
+        if (me == null) {
+            open.set(false);
             file.close();
-        } catch (IOException ex) {
-            Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex);
+            return;
+        }
+
+        if (!(me.getGlobaltoLocalMappings().containsKey(this))) {
+            me.addFile(this, 0);
         }
+        
+        TransactionLocalFileAttributes tmp = (TransactionLocalFileAttributes) me.getGlobaltoLocalMappings().get(this);
+        tmp.setOpen(false);
     }
     
     
-    public long length(){
+    
+    
+    public long length() throws IOException{
+        if (!(open.get()))
+            throw new IOException();
         ExtendedTransaction me = Wrapper.getTransaction();
 
         if (me == null) {
@@ -242,8 +265,9 @@ public class TransactionalFile implements Comparable {
 
         return tmp.getLocalsize();
     }
-    public long getFilePointer() {
-
+    public long getFilePointer() throws IOException {
+        if (!(open.get()))
+            throw new IOException();
         ExtendedTransaction me = Wrapper.getTransaction();
 
         if (me == null) {
@@ -296,8 +320,10 @@ public class TransactionalFile implements Comparable {
         
     }
     
-    public void seek(long offset) {
-
+    public void seek(long offset) throws IOException {
+        
+        if (!(open.get()))
+            throw new IOException();
         ExtendedTransaction me = Wrapper.getTransaction();
 
         if (me == null) {
@@ -342,14 +368,14 @@ public class TransactionalFile implements Comparable {
         return (int) (newpos - pos);
     }
 
-    public final byte readByte(){
+    public final byte readByte() throws IOException{
         byte[] data = new byte[1];
         read(data);
         byte result = (byte)(data[0]);
         return result;
     }
     
-    public final boolean readBoolean(){
+    public final boolean readBoolean() throws IOException{
         byte[] data = new byte[1];
         read(data);
         if (data[0] == 0 )
@@ -358,14 +384,14 @@ public class TransactionalFile implements Comparable {
         //return ((boolean)data[0]);// != 0);
     }
     
-    public final char readChar(){
+    public final char readChar() throws IOException{
         byte[] data = new byte[2];
         read(data);
         char result = (char)((data[0] << 8) | data[0]);
         return result;
     }
     
-    public final short readShort(){
+    public final short readShort() throws IOException{
         byte[] data = new byte[2];
         read(data);
         short result = (short)((data[0] << 8) | data[1]);
@@ -379,7 +405,7 @@ public class TransactionalFile implements Comparable {
         return (data[0] << 8) + (data[1] << 0);    
     }
     
-    public final String readUTF() throws UTFDataFormatException{
+    public final String readUTF() throws UTFDataFormatException, IOException{
             int utflen = -1;
             byte[] bytearr = null;
             char[] chararr = null;
@@ -461,7 +487,7 @@ public class TransactionalFile implements Comparable {
         
     }
     
-    public final float readFloat(){
+    public final float readFloat() throws IOException{
        // byte[] data = new byte[4];
        // int k = read(data);
         return Float.intBitsToFloat(readInt());
@@ -471,12 +497,12 @@ public class TransactionalFile implements Comparable {
       //  return result;
     }
     
-    public final double readDouble(){
+    public final double readDouble() throws IOException{
         return Double.longBitsToDouble(readLong());
     }
     
     
-    public final int readInt(){
+    public final int readInt() throws IOException{
         byte[] data = new byte[4];
         int k = read(data);
         
@@ -486,7 +512,7 @@ public class TransactionalFile implements Comparable {
         return result;
     }
     
-    public final long readLong(){
+    public final long readLong() throws IOException{
         //long result = ((long)(readInt()) << 32) + (readInt() & 0xFFFFFFFFL);
         byte[] data = new byte[8];
         read(data);
@@ -649,9 +675,11 @@ public class TransactionalFile implements Comparable {
                return utflen + 2;
     }
     
-    public int read(byte[] b) {
-
+    public int read(byte[] b) throws IOException {
 
+          if (!(open.get()))
+            throw new IOException();
+          
         ExtendedTransaction me = Wrapper.getTransaction();
         int size = b.length;
         int result = 0;
@@ -826,7 +854,8 @@ public class TransactionalFile implements Comparable {
     }
 
     public void write(byte[] data) throws IOException {
-
+      if (!(open.get()))
+            throw new IOException();
         if (!(writemode)) {
             throw new IOException();