int offset=overhead.getInitialRegion();
byte[] offsetBuffer=overhead.read( offset, INITIAL_REGION_SIZE);
int version=NetByte.quadToInt( offsetBuffer, 0);
if ( version!=DIR_ALLOC_VERSION)
{
throw new ObjectStoreException( "Mismatched version:" + version);
}
entryOffset=NetByte.quadToInt( offsetBuffer, 4);
classOffset=NetByte.quadToInt( offsetBuffer, 8);
rootOffset=NetByte.quadToInt( offsetBuffer, 12);
entryList=(EntryPageList)overheadStreams.readObject(
entryOffset);
entryList.initialize( overheadStreams);
classList=(ClassList)overheadStreams.readObject( classOffset);
if ( rootOffset!=0)
rootObject=(Serializable)overheadStreams.
readObject( rootOffset);
}
// Traverse class list; create class and index maps and stream
// pairs
classList.factory=factory;
classList.classMap=new HashMap();
classList.classChangeLock=new Semaphore();
classList.indexMap=new HashMap();
indexPageFlushLock=new Semaphore();
for ( Iterator i=classList.classEntries.iterator(); i.hasNext();)
{
ClassEntry entry=(ClassEntry)i.next();
classList.classMap.put( Class.forName( entry.className),
entry);
DiskAllocator allocator=createDiskAllocator(entry.fileName,128,DiskAllocator.FORCE_EXIST);
ObjectStreamCustomizer customizer=factory.getCustomizer(
Class.forName( entry.className));
entry.objectStreams=new StreamPair( allocator,
customizer);
if ( entry.indices.size()>0)
{
entry.indexStreams=new StreamPair(
createDiskAllocator(entry.fileName + "i", FAVORED_CHUNK_SIZE,DiskAllocator.FORCE_EXIST), customizer);
for ( Iterator j=entry.indices.iterator(); j.hasNext();)
{
IndexEntry indexEntry=(IndexEntry)j.next();
indexEntry.index=new Index( this,
indexEntry, entry.indexStreams);
classList.indexMap.put( indexEntry.indexName,
indexEntry.index);
}
}
}
}
catch ( ObjectStoreException ose)
{
emergencyCleanup( ose);
}
catch ( ClassNotFoundException cnfe)
{
emergencyCleanup( new ObjectStoreException( "Should never happen", cnfe));
}
catch ( IOException ioe)
{
ioe.printStackTrace();
emergencyCleanup( new ObjectStoreException( "Failed to initialize", ioe));
}
catch ( DiskAllocatorException dae)
{
emergencyCleanup( new ObjectStoreException( "Allocator failure", dae));
}
// Initialize index page cache
indexPageMap=new HashMap( INDEX_PAGE_CACHE_SIZE+1);
indexPageLRU=new ArrayList( INDEX_PAGE_CACHE_SIZE+1);
}