org.apache.jackrabbit.core.journal
Class AbstractJournal

java.lang.Object
  extended by org.apache.jackrabbit.core.journal.AbstractJournal
All Implemented Interfaces:
Journal
Direct Known Subclasses:
DatabaseJournal, FileJournal, MemoryJournal

public abstract class AbstractJournal
extends Object
implements Journal

Base journal implementation.


Constructor Summary
AbstractJournal()
           
 
Method Summary
protected abstract  void append(AppendRecord record, InputStream in, int length)
          Append a record backed by a file.
protected  void appending(AppendRecord record)
          Notification method called by an appended record at creation time.
protected  RecordProducer createProducer(String identifier)
          Create the record producer for a given identifier.
protected abstract  void doLock()
          Lock the journal revision.
protected  void doSync(long startRevision)
          Synchronize contents from journal.
protected abstract  void doUnlock(boolean successful)
          Unlock the journal revision.
 RecordConsumer getConsumer(String identifier)
          Return the consumer given its identifier.
 String getId()
          Return this journal's identifier.
 NamePathResolver getNamePathResolver()
          Return this journal's NamePathResolver.
 RecordProducer getProducer(String identifier)
          Return the record producer for a given identifier.
 File getRepositoryHome()
          Return the repository home.
 NamespaceResolver getResolver()
          Return this journal's namespace resolver.
 String getRevision()
           
 void init(String id, NamespaceResolver resolver)
          Initialize journal.
 void lockAndSync()
          Lock the journal revision, disallowing changes from other sources until {@link #unlock has been called, and synchronizes to the latest change.
 void register(RecordConsumer consumer)
          Register a record consumer.
 void setRepositoryHome(File repHome)
          Set the repository home.
 void setRevision(String revision)
           
 void sync()
          Synchronize contents from journal.
 void unlock(boolean successful)
          Unlock the journal revision.
 boolean unregister(RecordConsumer consumer)
          Unregister a record processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jackrabbit.core.journal.Journal
close, getInstanceRevision, getRecords, getRecords
 

Constructor Detail

AbstractJournal

public AbstractJournal()
Method Detail

init

public void init(String id,
                 NamespaceResolver resolver)
          throws JournalException
Initialize journal.

Specified by:
init in interface Journal
Parameters:
id - id this journal should use to write its own records
resolver - resolver used when reading/writing records
Throws:
JournalException - if an error occurs

register

public void register(RecordConsumer consumer)
              throws JournalException
Register a record consumer.

Specified by:
register in interface Journal
Parameters:
consumer - record consumer
Throws:
JournalException - if an error occurs

unregister

public boolean unregister(RecordConsumer consumer)
Unregister a record processor.

Specified by:
unregister in interface Journal
Parameters:
consumer - record processor to unregister
Returns:
true if the consumer was previously registered; false otherwise

getConsumer

public RecordConsumer getConsumer(String identifier)
Return the consumer given its identifier.

Parameters:
identifier - identifier
Returns:
consumer associated with identifier; null if no consumer is associated with identifier

getProducer

public RecordProducer getProducer(String identifier)
Return the record producer for a given identifier.

Specified by:
getProducer in interface Journal
Parameters:
identifier - identifier
Returns:
the record producer for a given identifier.

createProducer

protected RecordProducer createProducer(String identifier)
Create the record producer for a given identifier. May be overridden by subclasses.

Parameters:
identifier - producer identifier

sync

public void sync()
          throws JournalException
Synchronize contents from journal. This will compare the journal's revision with the revisions of all registered consumers and invoke their RecordConsumer.consume(org.apache.jackrabbit.core.journal.Record) method when their identifier matches the one found in the records.

Specified by:
sync in interface Journal
Throws:
JournalException - if an error occurs

doSync

protected void doSync(long startRevision)
               throws JournalException
Synchronize contents from journal. May be overridden by subclasses.

Parameters:
startRevision - start point (exclusive)
Throws:
JournalException - if an error occurs

lockAndSync

public void lockAndSync()
                 throws JournalException
Lock the journal revision, disallowing changes from other sources until {@link #unlock has been called, and synchronizes to the latest change.

Throws:
JournalException - if an error occurs

unlock

public void unlock(boolean successful)
Unlock the journal revision.

Parameters:
successful - flag indicating whether the update process was successful

doLock

protected abstract void doLock()
                        throws JournalException
Lock the journal revision. Subclass responsibility.

Throws:
JournalException - if an error occurs

appending

protected void appending(AppendRecord record)
Notification method called by an appended record at creation time. May be overridden by subclasses to save some context information inside the appended record.

Parameters:
record - record that was appended

append

protected abstract void append(AppendRecord record,
                               InputStream in,
                               int length)
                        throws JournalException
Append a record backed by a file. On exit, the new revision must have been set inside the appended record. Subclass responsibility.

Parameters:
record - record to append
in - input stream
length - number of bytes in input stream
Throws:
JournalException - if an error occurs

doUnlock

protected abstract void doUnlock(boolean successful)
Unlock the journal revision. Subclass responsibility.

Parameters:
successful - flag indicating whether the update process was successful

getId

public String getId()
Return this journal's identifier.

Returns:
journal identifier

getResolver

public NamespaceResolver getResolver()
Return this journal's namespace resolver.

Returns:
namespace resolver

getNamePathResolver

public NamePathResolver getNamePathResolver()
Return this journal's NamePathResolver.

Returns:
name and path resolver

setRepositoryHome

public void setRepositoryHome(File repHome)
Set the repository home.

Parameters:
repHome - repository home
Since:
JR 1.5

getRepositoryHome

public File getRepositoryHome()
Return the repository home.

Returns:
the repository home
Since:
JR 1.5

getRevision

public String getRevision()
Returns:
the path of the cluster node's local revision file

setRevision

public void setRevision(String revision)
Parameters:
revision - the path of the cluster node's local revision file to set


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.