org.apache.jackrabbit.mk.store
Class DefaultRevisionStore

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

public class DefaultRevisionStore
extends Object
implements RevisionStore, 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()
           
 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()
           
 StoredNode getNode(Id id)
           
 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, ChildNodeEntries map)
           
 Id putCommit(RevisionStore.PutToken token, MutableCommit commit)
          Store a new commit.
 Id putHeadCommit(RevisionStore.PutToken token, MutableCommit commit, Id branchRootId, Id branchRevId)
          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,
                    ChildNodeEntries 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, Id), RevisionStore.unlockHead()

putHeadCommit

public Id putHeadCommit(RevisionStore.PutToken token,
                        MutableCommit commit,
                        Id branchRootId,
                        Id branchRevId)
                 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
branchRevId - current branch head, i.e. last commit on this branch, 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

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


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