org.apache.jackrabbit.mk.store
Class DefaultRevisionStore

java.lang.Object
  extended by org.apache.jackrabbit.mk.store.DefaultRevisionStore
All Implemented Interfaces:
Closeable, NodeStore, RevisionProvider, RevisionStore

public class DefaultRevisionStore
extends Object
implements Closeable

Default revision store implementation, passing calls to a Persistence and a BlobStore, respectively and providing caching.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.jackrabbit.mk.store.RevisionStore
RevisionStore.PutToken
 
Field Summary
static String CACHE_SIZE
           
static int DEFAULT_CACHE_SIZE
           
protected  GCPersistence gcpm
           
 
Constructor Summary
DefaultRevisionStore(Persistence pm)
           
DefaultRevisionStore(Persistence pm, GCPersistence gcpm)
          Alternative constructor that allows disabling of garbage collection for an in-memory test repository.
 
Method Summary
 void close()
           
 void compare(NodeState before, NodeState after, NodeStateDiff diff)
          Compares the given two node states.
protected  void compareChildNodes(NodeState before, NodeState after, NodeStateDiff diff)
          Compares the child nodes of the given two node states.
protected  void compareProperties(NodeState before, NodeState after, NodeStateDiff diff)
          Compares the properties of the given two node states.
 RevisionStore.PutToken createPutToken()
          Create a put token.
protected static int determineInitialCacheSize()
           
 void gc()
          Perform a garbage collection.
 ChildNodeEntriesMap getCNEMap(Id id)
           
 StoredCommit getCommit(Id id)
           
 StoredCommit getHeadCommit()
           
 Id getHeadCommitId()
           
 Id getId(NodeState node)
          Adapts the given NodeState to the corresponding identifier.
 StoredNode getNode(Id id)
           
 NodeState getNodeState(StoredNode node)
          Adapts the given StoredNode to a corresponding NodeState instance.
 NodeState getRoot()
          Returns the latest state of the content tree.
 StoredNode getRootNode(Id commitId)
           
 void initialize()
           
 void lockHead()
          Lock the head.
protected  void markCommit(StoredCommit commit)
          Mark a commit.
protected  Id markCommits()
          Mark all commits and nodes in a garbage collection cycle.
 Id putCNEMap(RevisionStore.PutToken token, ChildNodeEntriesMap map)
           
 Id putCommit(RevisionStore.PutToken token, MutableCommit commit)
          Store a new commit.
 Id putHeadCommit(RevisionStore.PutToken token, MutableCommit commit, Id branchRootId)
          Put a new head commit.
 Id putNode(RevisionStore.PutToken token, MutableNode node)
           
 void unlockHead()
          Unlock the head.
protected  void verifyInitialized()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_SIZE

public static final String CACHE_SIZE
See Also:
Constant Field Values

DEFAULT_CACHE_SIZE

public static final int DEFAULT_CACHE_SIZE
See Also:
Constant Field Values

gcpm

protected final GCPersistence gcpm
Constructor Detail

DefaultRevisionStore

public DefaultRevisionStore(Persistence pm)

DefaultRevisionStore

public DefaultRevisionStore(Persistence pm,
                            GCPersistence gcpm)
Alternative constructor that allows disabling of garbage collection for an in-memory test repository.

Parameters:
pm - persistence manager
gcpm - the same persistence manager, or null for no GC
Method Detail

initialize

public void initialize()
                throws Exception
Throws:
Exception

close

public void close()
Specified by:
close in interface Closeable

verifyInitialized

protected void verifyInitialized()

determineInitialCacheSize

protected static int determineInitialCacheSize()

createPutToken

public RevisionStore.PutToken createPutToken()
Description copied from interface: RevisionStore
Create a put token.

Specified by:
createPutToken in interface RevisionStore
Returns:
put token

putNode

public Id putNode(RevisionStore.PutToken token,
                  MutableNode node)
           throws Exception
Specified by:
putNode in interface RevisionStore
Throws:
Exception

putCNEMap

public Id putCNEMap(RevisionStore.PutToken token,
                    ChildNodeEntriesMap map)
             throws Exception
Specified by:
putCNEMap in interface RevisionStore
Throws:
Exception

lockHead

public void lockHead()
Description copied from interface: RevisionStore
Lock the head. Must be called prior to putting a new head commit.

Specified by:
lockHead in interface RevisionStore
See Also:
RevisionStore.putHeadCommit(PutToken, MutableCommit, Id), RevisionStore.unlockHead()

putHeadCommit

public Id putHeadCommit(RevisionStore.PutToken token,
                        MutableCommit commit,
                        Id branchRootId)
                 throws Exception
Description copied from interface: RevisionStore
Put a new head commit. Must be called while holding a lock on the head.

Specified by:
putHeadCommit in interface RevisionStore
Parameters:
token - put token
commit - commit
branchRootId - former branch root id, if this is a merge; otherwise null
Returns:
head commit id
Throws:
Exception - if an error occurs
See Also:
RevisionStore.lockHead()

putCommit

public Id putCommit(RevisionStore.PutToken token,
                    MutableCommit commit)
             throws Exception
Description copied from interface: RevisionStore
Store a new commit.

Unlike putHeadCommit(MutableCommit), this method does not affect the current head commit and therefore doesn't require a lock on the head.

Specified by:
putCommit in interface RevisionStore
Parameters:
token - put token
commit - commit
Returns:
new commit id
Throws:
Exception - if an error occurs

unlockHead

public void unlockHead()
Description copied from interface: RevisionStore
Unlock the head.

Specified by:
unlockHead in interface RevisionStore
See Also:
RevisionStore.lockHead()

getNode

public StoredNode getNode(Id id)
                   throws NotFoundException,
                          Exception
Specified by:
getNode in interface RevisionProvider
Throws:
NotFoundException
Exception

getCNEMap

public ChildNodeEntriesMap getCNEMap(Id id)
                              throws NotFoundException,
                                     Exception
Specified by:
getCNEMap in interface RevisionProvider
Throws:
NotFoundException
Exception

getCommit

public StoredCommit getCommit(Id id)
                       throws NotFoundException,
                              Exception
Specified by:
getCommit in interface RevisionProvider
Throws:
NotFoundException
Exception

getRootNode

public StoredNode getRootNode(Id commitId)
                       throws NotFoundException,
                              Exception
Specified by:
getRootNode in interface RevisionProvider
Throws:
NotFoundException
Exception

getHeadCommit

public StoredCommit getHeadCommit()
                           throws Exception
Specified by:
getHeadCommit in interface RevisionProvider
Throws:
Exception

getHeadCommitId

public Id getHeadCommitId()
                   throws Exception
Specified by:
getHeadCommitId in interface RevisionProvider
Throws:
Exception

compare

public void compare(NodeState before,
                    NodeState after,
                    NodeStateDiff diff)
Description copied from interface: NodeStore
Compares the given two node states. Any found differences are reported by calling the relevant added, changed or deleted methods of the given handler.

Specified by:
compare in interface NodeStore
Parameters:
before - node state before changes
after - node state after changes
diff - handler of node state differences

gc

public void gc()
Perform a garbage collection. If a garbage collection cycle is already running, this method returns immediately.


markCommits

protected Id markCommits()
                  throws Exception
Mark all commits and nodes in a garbage collection cycle. Can be customized by subclasses. The default implementation preserves all commits that were created within 60 minutes of the current head commit.

If this method throws an exception, the cycle will be stopped without sweeping.

Returns:
first commit id that will be preserved
Throws:
Exception - if an error occurs

markCommit

protected void markCommit(StoredCommit commit)
                   throws Exception
Mark a commit. This marks all nodes belonging to this commit as well.

Parameters:
commit - commit
Throws:
Exception - if an error occurs

getNodeState

public NodeState getNodeState(StoredNode node)
Description copied from interface: RevisionProvider
Adapts the given StoredNode to a corresponding NodeState instance.

Specified by:
getNodeState in interface RevisionProvider
Parameters:
node - stored node instance
Returns:
node state adapter

getId

public Id getId(NodeState node)
Description copied from interface: RevisionProvider
Adapts the given NodeState to the corresponding identifier.

Specified by:
getId in interface RevisionProvider
Parameters:
node - node state
Returns:
node identifier

getRoot

public NodeState getRoot()
Description copied from interface: NodeStore
Returns the latest state of the content tree.

Specified by:
getRoot in interface NodeStore
Returns:
root node state

compareProperties

protected void compareProperties(NodeState before,
                                 NodeState after,
                                 NodeStateDiff diff)
Compares the properties of the given two node states.

Parameters:
before - node state before changes
after - node state after changes
diff - handler of node state differences

compareChildNodes

protected void compareChildNodes(NodeState before,
                                 NodeState after,
                                 NodeStateDiff diff)
Compares the child nodes of the given two node states.

Parameters:
before - node state before changes
after - node state after changes
diff - handler of node state differences


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.