public class DefaultJournalService extends Object implements JournalService
JournalService
.Constructor and Description |
---|
DefaultJournalService(JournalManager journalManager) |
Modifier and Type | Method and Description |
---|---|
int |
countEntries(@NonNull JournalIdentifier journalId)
Counts the number of entries in a journal.
|
long |
enqueue(@NonNull JournalEntry entry)
Adds the given entry to a journal.
|
Iterable<JournalEntry> |
peek(@NonNull JournalIdentifier journalId,
int maxEntries)
Return a copy of journal entries that are waiting to be processed.
|
<V> V |
processEntries(@NonNull JournalIdentifier journalId,
int maxEntries,
@NonNull 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(@NonNull JournalIdentifier journalId)
Resets the state of the journal so that all entries currently in the
journal will be skipped.
|
void |
waitForRecentEntriesToBecomeVisible()
Waits long enough to ensure that entries added before calling this
method will be available to subsequent call to
JournalService.processNewEntries(JournalIdentifier, int, Function) . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
processNewEntries
public DefaultJournalService(JournalManager journalManager)
public long enqueue(@NonNull JournalEntry entry) throws ServiceException
JournalService
New journal is automatically created if a journal with the given name does not exists.
enqueue
in interface JournalService
entry
- entry to persistServiceException
- if the entry could not be persistedpublic <V> V processEntries(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull com.google.common.base.Function<Iterable<JournalEntry>,EntryProcessorResult<V>> entryProcessor) throws ServiceException
JournalService
This method does not return entries that were added immediately before
calling this method. Use JournalService.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 JournalService
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 timeServiceException
- if entries could not be fetched or the journal state could not be savedpublic void waitForRecentEntriesToBecomeVisible() throws InterruptedException
JournalService
JournalService.processNewEntries(JournalIdentifier, int, Function)
.waitForRecentEntriesToBecomeVisible
in interface JournalService
InterruptedException
- if the thread got interruptedpublic Iterable<JournalEntry> peek(@NonNull JournalIdentifier journalId, int maxEntries) throws ServiceException
JournalService
peek
in interface JournalService
journalId
- only entries with this journal id will be returnedmaxEntries
- maximum number of entries to returnServiceException
- if entries could not be fetchedpublic void reset(@NonNull JournalIdentifier journalId) throws ServiceException
JournalService
reset
in interface JournalService
journalId
- identifier of the journal to resetServiceException
- if the reset failspublic int countEntries(@NonNull JournalIdentifier journalId) throws ServiceException
JournalService
countEntries
in interface JournalService
journalId
- identifier of the journalServiceException
- if entries could not be countedCopyright © 2003–2021 Atlassian. All rights reserved.