git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@657193 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-05-16 20:23:08 +00:00
parent 4ddb3e3f6c
commit 412923da51
1 changed files with 9 additions and 6 deletions

View File

@ -55,9 +55,6 @@ public class HashIndex implements Index, HashIndexMBean {
private int keySize = DEFAULT_KEY_SIZE; private int keySize = DEFAULT_KEY_SIZE;
private int numberOfBins = DEFAULT_BIN_SIZE; private int numberOfBins = DEFAULT_BIN_SIZE;
private int keysPerPage = this.pageSize /this.keySize; private int keysPerPage = this.pageSize /this.keySize;
private DataByteArrayInputStream dataIn;
private DataByteArrayOutputStream dataOut;
private byte[] readBuffer;
private HashBin[] bins; private HashBin[] bins;
private Marshaller keyMarshaller; private Marshaller keyMarshaller;
private long length; private long length;
@ -242,9 +239,6 @@ public class HashIndex implements Index, HashIndexMBean {
this.bins = new HashBin[capacity]; this.bins = new HashBin[capacity];
threshold = calculateThreashold(); threshold = calculateThreashold();
keysPerPage = pageSize / keySize; keysPerPage = pageSize / keySize;
dataIn = new DataByteArrayInputStream();
dataOut = new DataByteArrayOutputStream(pageSize);
readBuffer = new byte[pageSize];
try { try {
openIndexFile(); openIndexFile();
if (indexFile.length() > 0) { if (indexFile.length() > 0) {
@ -375,6 +369,7 @@ public class HashIndex implements Index, HashIndexMBean {
} }
void writeFullPage(HashPage page) throws IOException { void writeFullPage(HashPage page) throws IOException {
DataByteArrayOutputStream dataOut = new DataByteArrayOutputStream(pageSize);
dataOut.reset(); dataOut.reset();
page.write(keyMarshaller, dataOut); page.write(keyMarshaller, dataOut);
if (dataOut.size() > pageSize) { if (dataOut.size() > pageSize) {
@ -385,6 +380,7 @@ public class HashIndex implements Index, HashIndexMBean {
} }
void writePageHeader(HashPage page) throws IOException { void writePageHeader(HashPage page) throws IOException {
DataByteArrayOutputStream dataOut = new DataByteArrayOutputStream(pageSize);
dataOut.reset(); dataOut.reset();
page.writeHeader(dataOut); page.writeHeader(dataOut);
indexFile.seek(page.getId()); indexFile.seek(page.getId());
@ -392,6 +388,9 @@ public class HashIndex implements Index, HashIndexMBean {
} }
HashPage getFullPage(long id) throws IOException { HashPage getFullPage(long id) throws IOException {
byte[] readBuffer = new byte[pageSize];
DataByteArrayInputStream dataIn = new DataByteArrayInputStream();
readBuffer = new byte[pageSize];
indexFile.seek(id); indexFile.seek(id);
indexFile.readFully(readBuffer, 0, pageSize); indexFile.readFully(readBuffer, 0, pageSize);
dataIn.restart(readBuffer); dataIn.restart(readBuffer);
@ -402,6 +401,8 @@ public class HashIndex implements Index, HashIndexMBean {
} }
HashPage getPageHeader(long id) throws IOException { HashPage getPageHeader(long id) throws IOException {
byte[] readBuffer = new byte[pageSize];
DataByteArrayInputStream dataIn = new DataByteArrayInputStream();
indexFile.seek(id); indexFile.seek(id);
indexFile.readFully(readBuffer, 0, HashPage.PAGE_HEADER_SIZE); indexFile.readFully(readBuffer, 0, HashPage.PAGE_HEADER_SIZE);
dataIn.restart(readBuffer); dataIn.restart(readBuffer);
@ -468,6 +469,8 @@ public class HashIndex implements Index, HashIndexMBean {
} }
private void doLoad() throws IOException { private void doLoad() throws IOException {
byte[] readBuffer = new byte[pageSize];
DataByteArrayInputStream dataIn = new DataByteArrayInputStream();
long offset = 0; long offset = 0;
if (loaded.compareAndSet(false, true)) { if (loaded.compareAndSet(false, true)) {
while ((offset + pageSize) <= indexFile.length()) { while ((offset + pageSize) <= indexFile.length()) {