Interface JournalManager
- All Known Implementing Classes:
DefaultJournalManager
Typical way to use journal subsystem is to call enqueue(JournalEntry)
to queue new entries that should be actioned on each cluster node. Later on
queued entries can be processed by calling
on each cluster node. Subsequent calls to processEntries will be
passed only entries that were added since the last call on that cluster
node.
- Since:
- 5.6
-
Method Summary
Modifier and TypeMethodDescriptionint
countEntries
(@NonNull JournalIdentifier journalId) Counts the number of entries in a journal.long
enqueue
(@NonNull JournalEntry entry) Adds the given entry to a journal.void
enqueue
(@NonNull Collection<JournalEntry> entries) Adds a collection of entries to a journal.long
getMostRecentId
(@NonNull JournalIdentifier journalIdentifier) Gets the most recent entry in the journal for the given journal identifierpeek
(@NonNull JournalIdentifier journalId, int maxEntries) Return a copy of journal entries that are waiting to be processed.<V> V
processNewEntries
(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull Function<Iterable<JournalEntry>, @NonNull EntryProcessorResult<V>> entryProcessor) Processes journal entries that were added since the last time this method was called for this journal on this cluster node.int
removeEntriesOlderThanExclusive
(@NonNull Date date, Collection<String> excludingJournalNames) Removes entries from journals that were created before the given date.int
removeEntriesOlderThanInclusive
(@NonNull Date date, Collection<String> journalNames) Removes entries from journals that were created before the given date.void
reset
(@NonNull JournalIdentifier journalId) Resets the state of the journal so that all entries currently in the journal will be skipped.void
setMostRecentId
(@NonNull JournalIdentifier journalIdentifier, long id) Stores the most recent journal entry id in the journal storevoid
setMostRecentId
(@NonNull JournalEntry journalEntry) Stores the most recent journal entry id in the journal storevoid
Waits long enough to ensure that entries added before calling this method will be available to subsequent call toprocessNewEntries(JournalIdentifier, int, Function)
.
-
Method Details
-
enqueue
Adds the given entry to a journal.New journal is automatically created if a journal with the given name does not exists.
- Parameters:
entry
- entry to persist- Returns:
- id generated for the entry
- Throws:
org.springframework.dao.DataAccessException
- if the entry could not be persisted
-
enqueue
Adds a collection of entries to a journal.
- Parameters:
entries
- entries to persist- Throws:
ServiceException
- if one of entries could not be persisted. In this case, the transaction is rolled back and no entries are persisted- Since:
- 8.2.0
-
processNewEntries
<V> V processNewEntries(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull Function<Iterable<JournalEntry>, @NonNull EntryProcessorResult<V>> entryProcessor) throws org.springframework.dao.DataAccessExceptionProcesses 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
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.
- 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:
org.springframework.dao.DataAccessException
- if entries could not be fetched or the journal state could not be saved- Since:
- 7.0.1
-
waitForRecentEntriesToBecomeVisible
Waits long enough to ensure that entries added before calling this method will be available to subsequent call toprocessNewEntries(JournalIdentifier, int, Function)
.- Throws:
InterruptedException
- if the thread got interrupted
-
peek
Return a copy of journal entries that are waiting to be processed.- 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
-
reset
Resets the state of the journal so that all entries currently in the journal will be skipped.- Parameters:
journalId
- identifier of the journal to reset
-
countEntries
Counts the number of entries in a journal.- Parameters:
journalId
- identifier of the journal
-
getIgnoreWithinMillis
long getIgnoreWithinMillis()- Returns:
- the time that new entries are ignored
-
getMostRecentId
Optional<JournalEntry> getMostRecentId(@NonNull JournalIdentifier journalIdentifier) throws org.springframework.dao.DataAccessException Gets the most recent entry in the journal for the given journal identifier- Parameters:
journalIdentifier
- journal to obtain the most recent entry- Returns:
- the most recent entry or
Optional.empty()
if none found - Throws:
org.springframework.dao.DataAccessException
-
setMostRecentId
void setMostRecentId(@NonNull JournalIdentifier journalIdentifier, long id) throws org.springframework.dao.DataAccessException Stores the most recent journal entry id in the journal store- Parameters:
journalIdentifier
- identifier of the journal to store the most recent idid
- value of the most recent id- Throws:
org.springframework.dao.DataAccessException
- if entries could not be fetched or the journal state could not be saved
-
setMostRecentId
Stores the most recent journal entry id in the journal store- Parameters:
journalEntry
- journal entry to store as the most recent- Throws:
org.springframework.dao.DataAccessException
- if entries could not be fetched or the journal state could not be saved
-
removeEntriesOlderThanExclusive
Removes entries from journals that were created before the given date. Excluding journal if name match with excludingJournalName- Parameters:
date
-excludingJournalNames
-- Returns:
- Since:
- 9.3.0
-
removeEntriesOlderThanInclusive
Removes entries from journals that were created before the given date. Excluding journal if name match with journalNames- Parameters:
date
-journalNames
-- Returns:
- Since:
- 9.3.0
-