public class DefaultJournalManager extends Object implements JournalManager, JournalManagerBackdoor
JournalManager
.Constructor and Description |
---|
DefaultJournalManager(JournalDao journalDao,
JournalStateStore journalStateStore,
long ignoreWithinMillis) |
Modifier and Type | Method and Description |
---|---|
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() |
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<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) . |
public DefaultJournalManager(JournalDao journalDao, JournalStateStore journalStateStore, long ignoreWithinMillis)
ignoreWithinMillis
- entries added within the last given milliseconds are ignoredpublic long enqueue(@Nonnull JournalEntry entry)
JournalManager
New journal is automatically created if a journal with the given name does not exists.
enqueue
in interface JournalManager
entry
- entry to persistpublic Iterable<JournalEntry> peek(@Nonnull JournalIdentifier journalId, int maxEntries)
JournalManager
peek
in interface JournalManager
journalId
- only entries with this journal id will be returnedmaxEntries
- maximum number of entries to returnpublic void reset(@Nonnull JournalIdentifier journalId)
JournalManager
reset
in interface JournalManager
journalId
- identifier of the journal to resetpublic int countEntries(@Nonnull JournalIdentifier journalId)
JournalManager
countEntries
in interface JournalManager
journalId
- identifier of the journalpublic <V> V processEntries(@Nonnull JournalIdentifier journalId, int maxEntries, @Nonnull com.google.common.base.Function<Iterable<JournalEntry>,EntryProcessorResult<V>> entryProcessor) throws org.springframework.dao.DataAccessException
JournalManager
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.
processEntries
in interface JournalManager
journalId
- only entries with this journal id will be returnedmaxEntries
- maximum number of entries to processentryProcessor
- function that will process entries that were added
since the last timeorg.springframework.dao.DataAccessException
- if entries could not
be fetched or the journal state could not be savedpublic void waitForRecentEntriesToBecomeVisible() throws InterruptedException
JournalManager
JournalManager.processEntries(JournalIdentifier, int, com.google.common.base.Function)
.waitForRecentEntriesToBecomeVisible
in interface JournalManager
InterruptedException
- if the thread got interruptedpublic long getIgnoreWithinMillis()
getIgnoreWithinMillis
in interface JournalManagerBackdoor
public void setIgnoreWithinMillis(long ignoreWithinMillis)
setIgnoreWithinMillis
in interface JournalManagerBackdoor
Copyright © 2003–2015 Atlassian. All rights reserved.