com.atlassian.confluence.impl.journal
Class DefaultJournalManager

java.lang.Object
  extended by com.atlassian.confluence.impl.journal.DefaultJournalManager
All Implemented Interfaces:
JournalManager, JournalManagerBackdoor

public class DefaultJournalManager
extends java.lang.Object
implements JournalManager, JournalManagerBackdoor

This is the default implementation of JournalManager.

Since:
5.6

Constructor Summary
DefaultJournalManager(JournalDao journalDao, JournalStateStore journalStateStore, long ignoreWithinMillis)
           
 
Method Summary
 int countEntries(JournalIdentifier journalId)
          Counts the number of entries in a journal.
 long enqueue(JournalEntry entry)
          Adds the given entry to a journal.
 long getIgnoreWithinMillis()
           
 java.lang.Iterable<JournalEntry> peek(JournalIdentifier journalId, int maxEntries)
          Return a copy of journal entries that are waiting to be processed.
<V> V
processEntries(JournalIdentifier journalId, int maxEntries, com.google.common.base.Function<java.lang.Iterable<JournalEntry>,EntryProcessorResult<V>> entryProcessor)
          Processes journal entries that were added since the last time this method was called for this journal on this cluster node.
 void reset(JournalIdentifier journalId)
          Resets the state of the journal so that all entries currently in the journal will be skipped.
 void setIgnoreWithinMillis(long ignoreWithinMillis)
           
 void waitForRecentEntriesToBecomeVisible()
          Waits long enough to ensure that entries added before calling this method will be available to subsequent call to JournalManager.processEntries(JournalIdentifier, int, com.google.common.base.Function).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJournalManager

public DefaultJournalManager(JournalDao journalDao,
                             JournalStateStore journalStateStore,
                             long ignoreWithinMillis)
Parameters:
ignoreWithinMillis - entries added within the last given milliseconds are ignored
Method Detail

enqueue

public long enqueue(@Nonnull
                    JournalEntry entry)
Description copied from interface: JournalManager
Adds the given entry to a journal.

New journal is automatically created if a journal with the given name does not exists.

Specified by:
enqueue in interface JournalManager
Parameters:
entry - entry to persist
Returns:
id generated for the entry

peek

public java.lang.Iterable<JournalEntry> peek(@Nonnull
                                             JournalIdentifier journalId,
                                             int maxEntries)
Description copied from interface: JournalManager
Return a copy of journal entries that are waiting to be processed.

Specified by:
peek in interface JournalManager
Parameters:
journalId - only entries with this journal id will be returned
maxEntries - maximum number of entries to return
Returns:
a copy of journal entries that are waiting to be processed

reset

public void reset(@Nonnull
                  JournalIdentifier journalId)
Description copied from interface: JournalManager
Resets the state of the journal so that all entries currently in the journal will be skipped.

Specified by:
reset in interface JournalManager
Parameters:
journalId - identifier of the journal to reset

countEntries

public int countEntries(@Nonnull
                        JournalIdentifier journalId)
Description copied from interface: JournalManager
Counts the number of entries in a journal.

Specified by:
countEntries in interface JournalManager
Parameters:
journalId - identifier of the journal

processEntries

public <V> V processEntries(@Nonnull
                            JournalIdentifier journalId,
                            int maxEntries,
                            @Nonnull
                            com.google.common.base.Function<java.lang.Iterable<JournalEntry>,EntryProcessorResult<V>> entryProcessor)
                 throws org.springframework.dao.DataAccessException
Description copied from interface: JournalManager
Processes journal entries that were added since the last time this method was called for this journal on this cluster node.

This method does not return entries that were added immediately before calling this method. Use JournalManager.waitForRecentEntriesToBecomeVisible() for ensuring these entries will be included.

This method can miss some entries due to identifier assignment and entry insertion not being an atomic operation. The risk of missed entries can be reduced by creating new entries as close to transaction commit as possible.

If entryProcessor throws an exception, the same entries will be returned again when this method is next called for this journal on this cluster node.

New journal is automatically created if a journal with the given name does not exists.

Specified by:
processEntries in interface JournalManager
Parameters:
journalId - only entries with this journal id will be returned
maxEntries - maximum number of entries to process
entryProcessor - function that will process entries that were added since the last time
Returns:
result of entryProcessor
Throws:
org.springframework.dao.DataAccessException - if entries could not be fetched or the journal state could not be saved

waitForRecentEntriesToBecomeVisible

public void waitForRecentEntriesToBecomeVisible()
                                         throws java.lang.InterruptedException
Description copied from interface: JournalManager
Waits long enough to ensure that entries added before calling this method will be available to subsequent call to JournalManager.processEntries(JournalIdentifier, int, com.google.common.base.Function).

Specified by:
waitForRecentEntriesToBecomeVisible in interface JournalManager
Throws:
java.lang.InterruptedException - if the thread got interrupted

getIgnoreWithinMillis

public long getIgnoreWithinMillis()
Specified by:
getIgnoreWithinMillis in interface JournalManagerBackdoor

setIgnoreWithinMillis

public void setIgnoreWithinMillis(long ignoreWithinMillis)
Specified by:
setIgnoreWithinMillis in interface JournalManagerBackdoor


Copyright © 2003-2014 Atlassian. All Rights Reserved.