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);
+ }
}
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;
public boolean appendmode = false;
public ReentrantLock offsetlock;
private GlobalOffset committedoffset;
+ AtomicBoolean open = new AtomicBoolean(true);
private GlobalINodeState inodestate;
if (inodestate != null) {
synchronized (inodestate) {
committedoffset = new GlobalOffset(0);
+ open .set(true);
}
}
}
+ public boolean isOpen(){
+ return open.get();
+ }
+
public TransactionalFile(String filename, String mode) {
if (inodestate != null) {
synchronized (inodestate) {
committedoffset = new GlobalOffset(0);
+ open.set(true);
}
}
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) {
return tmp.getLocalsize();
}
- public long getFilePointer() {
-
+ public long getFilePointer() throws IOException {
+ if (!(open.get()))
+ throw new IOException();
ExtendedTransaction me = Wrapper.getTransaction();
if (me == null) {
}
- 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) {
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 )
//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]);
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;
}
- public final float readFloat(){
+ public final float readFloat() throws IOException{
// byte[] data = new byte[4];
// int k = read(data);
return Float.intBitsToFloat(readInt());
// 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);
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);
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;
}
public void write(byte[] data) throws IOException {
-
+ if (!(open.get()))
+ throw new IOException();
if (!(writemode)) {
throw new IOException();