moved io classes

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6396 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent c0e0e1f422
commit bd876eb4b7

@ -1,62 +0,0 @@
// kelondroIOChunks.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// created: 11.12.2005
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.chunks;
import java.io.IOException;
import de.anomic.kelondro.io.random.Writer;
public interface IOChunksInterface {
// logging support
public String name();
// reference handling
public Writer getRA();
// pseudo-native methods:
public long length() throws IOException;
public void readFully(long pos, byte[] b, int off, int len) throws IOException;
public void write(long pos, byte[] b, int off, int len) throws IOException;
public void commit() throws IOException;
public void close() throws IOException;
// derived methods:
public byte readByte(long pos) throws IOException;
public void writeByte(long pos, int v) throws IOException;
public short readShort(long pos) throws IOException;
public void writeShort(long pos, int v) throws IOException;
public int readInt(long pos) throws IOException;
public void writeInt(long pos, int v) throws IOException;
public long readLong(long pos) throws IOException;
public void writeLong(long pos, long v) throws IOException;
public void write(long pos, byte[] b) throws IOException;
public void writeSpace(long pos, int spacecount) throws IOException;
public void deleteOnExit();
}

@ -1,77 +0,0 @@
// kelondroRAIOChunks.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// created: 11.12.2004
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.chunks;
import java.io.IOException;
import de.anomic.kelondro.io.random.Writer;
public final class RandomAccessIOChunks extends AbstractIOChunks implements IOChunksInterface {
protected Writer ra;
public RandomAccessIOChunks(final Writer ra, final String name) {
this.name = name;
this.ra = ra;
}
public Writer getRA() {
return this.ra;
}
public synchronized long length() throws IOException {
return ra.length();
}
public synchronized void readFully(long pos, final byte[] b, int off, int len) throws IOException {
if (len == 0) return;
this.ra.seek(pos);
this.ra.readFully(b, off, len);
}
public synchronized void write(final long pos, final byte[] b, final int off, final int len) throws IOException {
if (len == 0) return;
this.ra.seek(pos);
this.ra.write(b, off, len);
}
public void commit() throws IOException {
// do nothing here
// this method is used to flush write-buffers
}
public synchronized void close() throws IOException {
if (this.ra != null) this.ra.close();
this.ra = null;
}
protected void finalize() throws Throwable {
if (this.ra != null) this.close();
super.finalize();
}
public void deleteOnExit() {
this.ra.deleteOnExit();
}
}

@ -41,14 +41,13 @@ import java.util.logging.Logger;
import net.yacy.kelondro.index.Column; import net.yacy.kelondro.index.Column;
import net.yacy.kelondro.index.Row; import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.Row.EntryIndex; import net.yacy.kelondro.index.Row.EntryIndex;
import net.yacy.kelondro.io.CachedFileWriter;
import net.yacy.kelondro.io.RandomAccessIO;
import net.yacy.kelondro.io.Writer;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.ByteOrder; import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.NaturalOrder; import net.yacy.kelondro.order.NaturalOrder;
import de.anomic.kelondro.io.chunks.IOChunksInterface;
import de.anomic.kelondro.io.chunks.RandomAccessIOChunks;
import de.anomic.kelondro.io.random.CachedFileWriter;
import de.anomic.kelondro.io.random.Writer;
import de.anomic.kelondro.util.FileUtils; import de.anomic.kelondro.util.FileUtils;
import de.anomic.kelondro.util.kelondroException; import de.anomic.kelondro.util.kelondroException;
@ -80,7 +79,7 @@ public class Records {
// values that are only present at run-time // values that are only present at run-time
public String filename; // the database's file name public String filename; // the database's file name
protected IOChunksInterface entryFile; // the database file protected RandomAccessIO entryFile; // the database file
protected int overhead; // OHBYTEC + 4 * OHHANDLEC = size of additional control bytes protected int overhead; // OHBYTEC + 4 * OHHANDLEC = size of additional control bytes
protected int headchunksize;// overheadsize + key element column size protected int headchunksize;// overheadsize + key element column size
protected int tailchunksize;// sum(all: COLWIDTHS) minus the size of the key element colum protected int tailchunksize;// sum(all: COLWIDTHS) minus the size of the key element colum
@ -153,7 +152,6 @@ public class Records {
if (finalwrite) synchronized (entryFile) { if (finalwrite) synchronized (entryFile) {
assert this.USEDC >= 0 : "this.USEDC = " + this.USEDC; assert this.USEDC >= 0 : "this.USEDC = " + this.USEDC;
entryFile.writeInt(POS_USEDC, this.USEDC); entryFile.writeInt(POS_USEDC, this.USEDC);
entryFile.commit();
} }
} }
@ -161,7 +159,6 @@ public class Records {
synchronized (entryFile) { synchronized (entryFile) {
entryFile.writeInt(POS_FREEC, FREEC); entryFile.writeInt(POS_FREEC, FREEC);
entryFile.writeInt(POS_FREEH, FREEH.index); entryFile.writeInt(POS_FREEH, FREEH.index);
entryFile.commit();
checkConsistency(); checkConsistency();
} }
} }
@ -177,7 +174,6 @@ public class Records {
this.FREEC = 0; this.FREEC = 0;
entryFile.writeInt(POS_FREEC, FREEC); entryFile.writeInt(POS_FREEC, FREEC);
entryFile.writeInt(POS_FREEH, FREEH.index); entryFile.writeInt(POS_FREEH, FREEH.index);
entryFile.commit();
} else { } else {
this.FREEH = new Handle(freeh); this.FREEH = new Handle(freeh);
this.FREEC = entryFile.readInt(POS_FREEC); this.FREEC = entryFile.readInt(POS_FREEC);
@ -321,7 +317,6 @@ public class Records {
USAGE.FREEH = h; USAGE.FREEH = h;
assert ((USAGE.FREEH.index == Handle.NUL) && (USAGE.FREEC == 0)) || seekpos(USAGE.FREEH) < entryFile.length() : "allocateRecord: USAGE.FREEH.index = " + USAGE.FREEH.index; assert ((USAGE.FREEH.index == Handle.NUL) && (USAGE.FREEC == 0)) || seekpos(USAGE.FREEH) < entryFile.length() : "allocateRecord: USAGE.FREEH.index = " + USAGE.FREEH.index;
USAGE.writefree(); USAGE.writefree();
entryFile.commit();
} }
assert (index <= USAGE.allCount()); assert (index <= USAGE.allCount());
@ -330,7 +325,6 @@ public class Records {
entryFile.write(seekpos(index), bulkchunk, offset, recordsize); // write chunk and occupy space entryFile.write(seekpos(index), bulkchunk, offset, recordsize); // write chunk and occupy space
USAGE.USEDC++; USAGE.USEDC++;
USAGE.writeused(false); USAGE.writeused(false);
entryFile.commit();
} }
} }
} }
@ -353,7 +347,7 @@ public class Records {
if (!(file.exists())) return 0; if (!(file.exists())) return 0;
try { try {
final Writer ra = new CachedFileWriter(new File(file.getCanonicalPath())); final Writer ra = new CachedFileWriter(new File(file.getCanonicalPath()));
final IOChunksInterface entryFile = new RandomAccessIOChunks(ra, ra.name()); final RandomAccessIO entryFile = new RandomAccessIO(ra, ra.name());
final int used = entryFile.readInt(POS_USEDC); // works only if consistency with file size is given final int used = entryFile.readInt(POS_USEDC); // works only if consistency with file size is given
entryFile.close(); entryFile.close();
@ -425,7 +419,7 @@ public class Records {
private void initNewFile(final Writer ra, final int FHandles, final int txtProps) throws IOException { private void initNewFile(final Writer ra, final int FHandles, final int txtProps) throws IOException {
// create new Chunked IO // create new Chunked IO
this.entryFile = new RandomAccessIOChunks(ra, ra.name()); this.entryFile = new RandomAccessIO(ra, ra.name());
// store dynamic run-time data // store dynamic run-time data
this.overhead = this.OHBYTEC + 4 * this.OHHANDLEC; this.overhead = this.OHBYTEC + 4 * this.OHHANDLEC;
@ -477,8 +471,6 @@ public class Records {
for (int i = 0; i < this.TXTPROPS.length; i++) { for (int i = 0; i < this.TXTPROPS.length; i++) {
entryFile.write(POS_TXTPROPS + TXTPROPW * i, ea); entryFile.write(POS_TXTPROPS + TXTPROPW * i, ea);
} }
this.entryFile.commit();
} }
public void setDescription(final byte[] description) throws IOException { public void setDescription(final byte[] description) throws IOException {
@ -525,7 +517,7 @@ public class Records {
/*if (useBuffer) { /*if (useBuffer) {
this.entryFile = new BufferedIOChunks(ra, ra.name(), 1024*1024, 30000 + random.nextLong() % 30000); this.entryFile = new BufferedIOChunks(ra, ra.name(), 1024*1024, 30000 + random.nextLong() % 30000);
} else {*/ } else {*/
this.entryFile = new RandomAccessIOChunks(ra, ra.name()); this.entryFile = new RandomAccessIO(ra, ra.name());
//} //}
// read dynamic variables that are back-ups of stored values in file; // read dynamic variables that are back-ups of stored values in file;
@ -1206,10 +1198,6 @@ public class Records {
public synchronized void commit() throws IOException { public synchronized void commit() throws IOException {
// this must be called after all write operations to the node are finished // this must be called after all write operations to the node are finished
// place the data to the file
final boolean doCommit = this.ohChanged || this.bodyChanged;
// save head // save head
synchronized (entryFile) { synchronized (entryFile) {
if (this.ohChanged) { if (this.ohChanged) {
@ -1226,8 +1214,6 @@ public class Records {
entryFile.write(seekpos(this.handle) + overhead, (this.bodyChunk == null) ? new byte[ROW.objectsize] : this.bodyChunk); entryFile.write(seekpos(this.handle) + overhead, (this.bodyChunk == null) ? new byte[ROW.objectsize] : this.bodyChunk);
this.bodyChanged = false; this.bodyChanged = false;
} }
if (doCommit) entryFile.commit();
} }
} }

@ -45,12 +45,12 @@ import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowCollection; import net.yacy.kelondro.index.RowCollection;
import net.yacy.kelondro.index.RowSet; import net.yacy.kelondro.index.RowSet;
import net.yacy.kelondro.index.Row.Entry; import net.yacy.kelondro.index.Row.Entry;
import net.yacy.kelondro.io.BufferedRecords;
import net.yacy.kelondro.io.Records;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.CloneableIterator; import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.order.NaturalOrder; import net.yacy.kelondro.order.NaturalOrder;
import de.anomic.kelondro.io.records.BufferedRecords;
import de.anomic.kelondro.io.records.Records;
import de.anomic.kelondro.util.FileUtils; import de.anomic.kelondro.util.FileUtils;
import de.anomic.kelondro.util.MemoryControl; import de.anomic.kelondro.util.MemoryControl;
import de.anomic.kelondro.util.kelondroException; import de.anomic.kelondro.util.kelondroException;

@ -32,11 +32,11 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import net.yacy.kelondro.io.AbstractWriter;
import net.yacy.kelondro.order.ByteOrder; import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator; import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.order.NaturalOrder; import net.yacy.kelondro.order.NaturalOrder;
import de.anomic.kelondro.io.random.AbstractWriter;
public final class Heap extends HeapModifier implements BLOB { public final class Heap extends HeapModifier implements BLOB {

@ -28,10 +28,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.SortedMap; import java.util.SortedMap;
import net.yacy.kelondro.io.CachedFileWriter;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.ByteOrder; import net.yacy.kelondro.order.ByteOrder;
import de.anomic.kelondro.io.random.CachedFileWriter;
import de.anomic.kelondro.util.FileUtils; import de.anomic.kelondro.util.FileUtils;
import de.anomic.kelondro.util.MemoryControl; import de.anomic.kelondro.util.MemoryControl;

@ -35,13 +35,13 @@ import java.util.Map.Entry;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import net.yacy.kelondro.index.HandleMap; import net.yacy.kelondro.index.HandleMap;
import net.yacy.kelondro.io.CachedFileWriter;
import net.yacy.kelondro.io.Writer;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.ByteOrder; import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator; import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.order.RotateIterator; import net.yacy.kelondro.order.RotateIterator;
import de.anomic.kelondro.io.random.CachedFileWriter;
import de.anomic.kelondro.io.random.Writer;
import de.anomic.kelondro.util.FileUtils; import de.anomic.kelondro.util.FileUtils;
import de.anomic.kelondro.util.MemoryControl; import de.anomic.kelondro.util.MemoryControl;

@ -22,7 +22,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

@ -22,7 +22,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;

@ -22,7 +22,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.records; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

@ -20,7 +20,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

@ -1,10 +1,10 @@
// kelondroAbstractIOChunks.java // RandomAccessIO.java
// ----------------------- // -----------------------
// part of The Kelondro Database // part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net // (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de // first published on http://www.anomic.de
// Frankfurt, Germany, 2005 // Frankfurt, Germany, 2005
// created: 11.12.2005 // created: 11.12.2004
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,13 +20,40 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.chunks; package net.yacy.kelondro.io;
import java.io.IOException; import java.io.IOException;
public abstract class AbstractIOChunks implements IOChunksInterface { public final class RandomAccessIO {
protected Writer ra;
public RandomAccessIO(final Writer ra, final String name) {
this.name = name;
this.ra = ra;
}
public Writer getRA() {
return this.ra;
}
public synchronized long length() throws IOException {
return ra.length();
}
public synchronized void readFully(long pos, final byte[] b, int off, int len) throws IOException {
if (len == 0) return;
this.ra.seek(pos);
this.ra.readFully(b, off, len);
}
public synchronized void write(final long pos, final byte[] b, final int off, final int len) throws IOException {
if (len == 0) return;
this.ra.seek(pos);
this.ra.write(b, off, len);
}
// logging support // logging support
protected String name = null; protected String name = null;
@ -34,12 +61,6 @@ public abstract class AbstractIOChunks implements IOChunksInterface {
return name; return name;
} }
// pseudo-native methods:
abstract public long length() throws IOException;
abstract public void write(long pos, byte[] b, int off, int len) throws IOException;
abstract public void close() throws IOException;
abstract public void readFully(long pos, final byte[] b, int off, int len) throws IOException;
public synchronized byte readByte(final long pos) throws IOException { public synchronized byte readByte(final long pos) throws IOException {
final byte[] b = new byte[1]; final byte[] b = new byte[1];
this.readFully(pos, b, 0, 1); this.readFully(pos, b, 0, 1);
@ -120,4 +141,17 @@ public abstract class AbstractIOChunks implements IOChunksInterface {
return s; return s;
} }
public synchronized void close() throws IOException {
if (this.ra != null) this.ra.close();
this.ra = null;
}
protected void finalize() throws Throwable {
if (this.ra != null) this.close();
super.finalize();
}
public void deleteOnExit() {
this.ra.deleteOnExit();
}
} }

@ -18,7 +18,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

@ -22,7 +22,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.records; package net.yacy.kelondro.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

@ -18,7 +18,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro.io.random; package net.yacy.kelondro.io;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
Loading…
Cancel
Save