org.planx.xmlstore.koala.storage
Class SegmentManager

java.lang.Object
  extended by org.planx.xmlstore.koala.storage.StorageManager
      extended by org.planx.xmlstore.koala.storage.SegmentManager
All Implemented Interfaces:
Loader<RelativeDualReference<Locator,LocalLocator>,SystemNode>

public class SegmentManager
extends StorageManager

A SegmentManager manages multiple segments with unique SourceIds. In memory, each segment is represented by a MemoryFileSystem and on disk all segments are persisted in a single LocalFileSystem.

Note, that during sharing/garbage collection the SourceId of a segment may change which can be interpreted as the old segment disappearing and a new segment being created. Updating references to the old segment is not the responsibility of the SegmentManager.

TODO: Implement caching of in-memory segments. TODO: Consider stopping recursive save only if a node's cached locator is native to this SegmentManager.

The main class for this package that manages saving, loading, sharing, and garbage collection. The StorageManager operates on LocalLocator which has two properties: First, they contain a Locator which can be used with the SegmentManager to save and load data. Second, they support behind-the-scenes updating when the sharer has determined some references to be equivalent. To track live LocalLocators a RootManager is used. Thus, the StorageManager combines the capabilities of the SegmentManager and the RootManager to provided the information needed for the Sharer.

Author:
Thomas Ambus

Constructor Summary
SegmentManager(String name)
           
SegmentManager(String name, StorageConfiguration config)
          Creates a SegmentManager loading previously saved data from disk using the specified name or creating a new manager that will save data using the name.
 
Method Summary
 void addRootListener(LocatorListener l)
           
 LocalLocator asMemoryRoot(LocalLocator loc)
          Returns a weak, in-memory root for a strong root.
 Segment cacheRetrieve(SourceId id)
           
 void close()
          Flushes and closes.
 boolean contains(SourceId id)
          Returns true if and only if a live segment exists with the specified SourceId.
 void delete(SourceId id)
          Frees the on-disk space occupied by the data in the segment with the specified SourceId and invalidates any in-memory copy of the segment.
 void flush()
           
 void flushWrite()
          Commits all data written to the single in-memory write segment to permanent storage and creates a new, empty in-memory write segment.
 RootManager getRootManager()
           
 Sharer getSharer()
           
 Segment getWriteSegment()
           
 Set<SourceId> ids()
          Returns a set view of all the segments' SourceIds.
 int inMemorySegments()
          Returns the number of Segments currently in memory.
 SystemNode load(LocalLocator l)
          Loads a node.
 SystemNode load(RelativeDualReference<Locator,LocalLocator> ref)
          Attempts to load directly using the Locator of the RelativeDualReference and if the segment's state has changed instead loads using the relative reference.
 void persist(Segment segment)
          Saves the segment to persistent storage adding the segment to the segments managed by this SegmentManager.
 int persistedSegments()
          Returns the number of Segments currently on disk.
 void register(Segment s)
           
 MultiMap<SourceId,SourceId> relations()
           
 void release(LocalLocator loc)
          Releases a root that was previously retained.
 void removeRootListener(LocatorListener l)
           
 void retain(LocalLocator loc)
          Requests that a root be kept permanently alive.
 Segment retrieve(SourceId id)
          Returns an in-memory representation of the data contained in the segment with the specified SourceId.
 LocalLocator save(SystemNode node)
          Saves the node to the single in-memory write segment unless the node already has a Locator associated with it.
 long size()
          Returns the on-disk size of the associated LocalFileSystem.
 BijectiveMap<SourceId,SourceId> states()
          Returns a mapping from segment ids to state ids.
 String toString()
           
 
Methods inherited from class org.planx.xmlstore.koala.storage.StorageManager
instance, instance
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SegmentManager

public SegmentManager(String name)
               throws IOException
Throws:
IOException

SegmentManager

public SegmentManager(String name,
                      StorageConfiguration config)
               throws IOException
Creates a SegmentManager loading previously saved data from disk using the specified name or creating a new manager that will save data using the name.

Throws:
IOException
Method Detail

load

public SystemNode load(LocalLocator l)
                throws IOException
Loads a node. Looks up (and possibly loads) the segment containing the locator and then loads the node from that segment.

Specified by:
load in class StorageManager
Throws:
IOException

load

public SystemNode load(RelativeDualReference<Locator,LocalLocator> ref)
                throws IOException
Attempts to load directly using the Locator of the RelativeDualReference and if the segment's state has changed instead loads using the relative reference.

Specified by:
load in interface Loader<RelativeDualReference<Locator,LocalLocator>,SystemNode>
Specified by:
load in class StorageManager
Throws:
IOException

save

public LocalLocator save(SystemNode node)
                  throws IOException
Saves the node to the single in-memory write segment unless the node already has a Locator associated with it.

TODO: Should perhaps only stop recursive save if the locator is native to this SegmentManager and not another one.

Specified by:
save in class StorageManager
Throws:
IOException

retain

public void retain(LocalLocator loc)
Description copied from class: StorageManager
Requests that a root be kept permanently alive.

Specified by:
retain in class StorageManager

release

public void release(LocalLocator loc)
             throws UnknownReferenceException
Releases a root that was previously retained.

Specified by:
release in class StorageManager
Throws:
UnknownReferenceException

asMemoryRoot

public LocalLocator asMemoryRoot(LocalLocator loc)
Description copied from class: StorageManager
Returns a weak, in-memory root for a strong root. TODO: Perhaps strong roots should have a different type?

Specified by:
asMemoryRoot in class StorageManager

addRootListener

public void addRootListener(LocatorListener l)
Specified by:
addRootListener in class StorageManager

removeRootListener

public void removeRootListener(LocatorListener l)
Specified by:
removeRootListener in class StorageManager

getRootManager

public RootManager getRootManager()

getSharer

public Sharer getSharer()

flushWrite

public void flushWrite()
                throws IOException
Commits all data written to the single in-memory write segment to permanent storage and creates a new, empty in-memory write segment.

Throws:
IOException

getWriteSegment

public Segment getWriteSegment()
                        throws IOException
Throws:
IOException

register

public void register(Segment s)
              throws IOException
Throws:
IOException

delete

public void delete(SourceId id)
            throws IOException
Frees the on-disk space occupied by the data in the segment with the specified SourceId and invalidates any in-memory copy of the segment.

Throws:
IOException

persist

public void persist(Segment segment)
             throws IOException
Saves the segment to persistent storage adding the segment to the segments managed by this SegmentManager.

Throws:
IOException

retrieve

public Segment retrieve(SourceId id)
                 throws IOException
Returns an in-memory representation of the data contained in the segment with the specified SourceId.

Throws:
IOException

cacheRetrieve

public Segment cacheRetrieve(SourceId id)
                      throws IOException
Throws:
IOException

contains

public boolean contains(SourceId id)
Returns true if and only if a live segment exists with the specified SourceId.


ids

public Set<SourceId> ids()
Returns a set view of all the segments' SourceIds.


relations

public MultiMap<SourceId,SourceId> relations()

states

public BijectiveMap<SourceId,SourceId> states()
Returns a mapping from segment ids to state ids.


flush

public void flush()
           throws IOException
Specified by:
flush in class StorageManager
Throws:
IOException

close

public void close()
           throws IOException
Flushes and closes.

Specified by:
close in class StorageManager
Throws:
IOException

size

public long size()
          throws IOException
Returns the on-disk size of the associated LocalFileSystem.

Specified by:
size in class StorageManager
Throws:
IOException

inMemorySegments

public int inMemorySegments()
Returns the number of Segments currently in memory.


persistedSegments

public int persistedSegments()
Returns the number of Segments currently on disk.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2005 Plan-X. All Rights Reserved.