IndexInputBuffer.java revision f0a048d41a13eca4cba405da9403c2469ca3d1ea
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* The buffer class is used to process a buffer from the temporary index files
* during phase 2 processing.
*/
{
/** Possible states while reading a record. */
private static enum RecordState
{
}
static final long UNDEFINED_SIZE = -1;
private final IndexManager indexMgr;
private final FileChannel channel;
private final long begin;
private final long end;
private final int bufferID;
private long offset;
private final ByteBuffer cache;
/** Next fields are the fetched record data. */
private ImportRecord record;
/**
* Creates a new index input buffer.
*
* @param indexMgr
* The index manager.
* @param channel
* The index file channel.
* @param begin
* The position of the start of the buffer in the scratch file.
* @param end
* The position of the end of the buffer in the scratch file.
* @param bufferID
* The buffer ID.
* @param cacheSize
* The cache size.
* @throws IOException
* If an IO error occurred when priming the cache.
*/
IndexInputBuffer(IndexManager indexMgr, FileChannel channel, long begin, long end, int bufferID, int cacheSize)
throws IOException
{
this.offset = 0;
loadCache();
}
private void loadCache() throws IOException
{
long bytesToRead;
{
}
else
{
}
int bytesRead = 0;
while (bytesRead < bytesToRead)
{
}
}
/**
* Returns {@code true} if this buffer has more data.
*
* @return {@code true} if this buffer has more data.
* @throws IOException
* If an IO error occurred.
*/
boolean hasMoreData() throws IOException
{
}
{
{
// ensure record fetched
try
{
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
}
return record;
}
/**
* Reads the next record from the buffer, skipping any remaining data in the
* current record.
*
* @throws IOException
* If an IO error occurred.
*/
void fetchNextRecord() throws IOException
{
switch (recordState)
{
case START:
// Nothing to skip.
break;
case NEED_INSERT_ID_SET:
// The previous record's ID sets were not read, so skip them both.
break;
case NEED_DELETE_ID_SET:
// The previous record's delete ID set was not read, so skip it.
break;
}
}
{
ensureData(20);
return keyBuffer.toByteString();
}
private int getInt() throws IOException
{
}
private long getLong() throws IOException
{
}
/**
* Reads the next ID set from the record and merges it with the provided ID set.
*
* @param idSet
* The ID set to be merged.
* @throws IOException
* If an IO error occurred.
*/
{
{
throw new IllegalStateException();
}
ensureData(20);
for (int k = 0; k < keyCount; k++)
{
// idSet will be null if skipping.
{
if (entryID == UNDEFINED_SIZE)
{
}
else
{
}
}
}
switch (recordState)
{
case START:
throw new IllegalStateException();
case NEED_INSERT_ID_SET:
break;
case NEED_DELETE_ID_SET:
break;
}
}
{
{
loadCache();
return true;
}
{
loadCache();
return true;
}
return false;
}
/** {@inheritDoc} */
public int compareTo(IndexInputBuffer o)
{
// used in remove.
if (this == o)
{
return 0;
}
if (cmp == 0)
{
}
return cmp;
}
/** {@inheritDoc} */
{
+ ", indexMgr=" + indexMgr + "bufferID=" + bufferID + ", record=" + record + ", recordState=" + recordState
+ ")";
}
}