Class DefaultJournalService
- All Implemented Interfaces:
JournalService,JournalServiceInternal
- Direct Known Subclasses:
DefaultIndexJournalService
JournalService.- Since:
- 5.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcountEntries(@NonNull JournalIdentifier journalId) Counts the number of entries in a journal.longenqueue(@NonNull JournalEntry entry) Adds the given entry to a journal.getMostRecentId(@NonNull JournalIdentifier journalIdentifier) This will find and return the latest journal entry for the provided journal ID, if one exists.peek(@NonNull JournalIdentifier journalId, int maxEntries) Return a copy of journal entries that are waiting to be processed.<V> VprocessNewEntries(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull 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.intremoveEntriesOlderThan(@NonNull Date date, Collection<String> journalNames) Removes entries from journals that were created before the given date.intremoveEntriesOlderThanExclusive(@NonNull Date date, Collection<String> excludingJournalNames) Removes entries from journals that were created before the given date.voidreset(@NonNull JournalIdentifier journalId) Resets the state of the journal so that all entries currently in the journal will be skipped.voidWaits long enough to ensure that entries added before calling this method will be available to subsequent call toJournalService.processNewEntries(JournalIdentifier, int, Function).
-
Constructor Details
-
DefaultJournalService
-
-
Method Details
-
enqueue
Description copied from interface:JournalServiceAdds the given entry to a journal.New journal is automatically created if a journal with the given name does not exists.
- Specified by:
enqueuein interfaceJournalService- Parameters:
entry- entry to persist- Returns:
- id generated for the entry
- Throws:
ServiceException- if the entry could not be persisted
-
processNewEntries
public <V> V processNewEntries(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull Function<Iterable<JournalEntry>, EntryProcessorResult<V>> entryProcessor) throws ServiceExceptionDescription copied from interface:JournalServiceProcesses 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
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.
- Specified by:
processNewEntriesin interfaceJournalService- Parameters:
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 time- Returns:
- result of entryProcessor
- Throws:
ServiceException- if entries could not be fetched or the journal state could not be saved
-
waitForRecentEntriesToBecomeVisible
Description copied from interface:JournalServiceWaits long enough to ensure that entries added before calling this method will be available to subsequent call toJournalService.processNewEntries(JournalIdentifier, int, Function).- Specified by:
waitForRecentEntriesToBecomeVisiblein interfaceJournalService- Throws:
InterruptedException- if the thread got interrupted
-
peek
public Iterable<JournalEntry> peek(@NonNull JournalIdentifier journalId, int maxEntries) throws ServiceException Description copied from interface:JournalServiceReturn a copy of journal entries that are waiting to be processed.- Specified by:
peekin interfaceJournalService- Parameters:
journalId- only entries with this journal id will be returnedmaxEntries- maximum number of entries to return- Returns:
- a copy of journal entries that are waiting to be processed
- Throws:
ServiceException- if entries could not be fetched
-
reset
Description copied from interface:JournalServiceResets the state of the journal so that all entries currently in the journal will be skipped.- Specified by:
resetin interfaceJournalService- Parameters:
journalId- identifier of the journal to reset- Throws:
ServiceException- if the reset fails
-
countEntries
Description copied from interface:JournalServiceCounts the number of entries in a journal.- Specified by:
countEntriesin interfaceJournalService- Parameters:
journalId- identifier of the journal- Throws:
ServiceException- if entries could not be counted
-
removeEntriesOlderThan
Description copied from interface:JournalServiceInternalRemoves entries from journals that were created before the given date.- Specified by:
removeEntriesOlderThanin interfaceJournalServiceInternal- Returns:
-
removeEntriesOlderThanExclusive
public int removeEntriesOlderThanExclusive(@NonNull Date date, Collection<String> excludingJournalNames) Description copied from interface:JournalServiceInternalRemoves entries from journals that were created before the given date. Excluding journal if name match with excludingJournalName- Specified by:
removeEntriesOlderThanExclusivein interfaceJournalServiceInternal- Returns:
-
getMostRecentId
Description copied from interface:JournalServiceInternalThis will find and return the latest journal entry for the provided journal ID, if one exists.- Specified by:
getMostRecentIdin interfaceJournalServiceInternal
-