Class DefaultJournalManager
- All Implemented Interfaces:
JournalManager
JournalManager
.- Since:
- 5.6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Settings for ignoring journal entries added within the last given milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultJournalManager
(JournalDao journalDao, JournalStateStore journalStateStore, DefaultJournalManager.IgnoreSettings ignoreSettings, SearchPlatformConfig searchPlatformConfig, org.springframework.transaction.PlatformTransactionManager transactionManager) -
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 toJournalManager.processNewEntries(JournalIdentifier, int, Function)
.
-
Constructor Details
-
DefaultJournalManager
public DefaultJournalManager(JournalDao journalDao, JournalStateStore journalStateStore, DefaultJournalManager.IgnoreSettings ignoreSettings, SearchPlatformConfig searchPlatformConfig, org.springframework.transaction.PlatformTransactionManager transactionManager)
-
-
Method Details
-
enqueue
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 interfaceJournalManager
- Parameters:
entry
- entry to persist- Returns:
- id generated for the entry
-
enqueue
Description copied from interface:JournalManager
Adds a collection of entries to a journal.
- Specified by:
enqueue
in interfaceJournalManager
- 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
-
peek
Description copied from interface:JournalManager
Return a copy of journal entries that are waiting to be processed.- Specified by:
peek
in interfaceJournalManager
- 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
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 interfaceJournalManager
- Parameters:
journalId
- identifier of the journal to reset
-
countEntries
Description copied from interface:JournalManager
Counts the number of entries in a journal.- Specified by:
countEntries
in interfaceJournalManager
- Parameters:
journalId
- identifier of the journal
-
processNewEntries
public <V> V processNewEntries(@NonNull JournalIdentifier journalId, int maxEntries, @NonNull Function<Iterable<JournalEntry>, @NonNull EntryProcessorResult<V>> entryProcessor) throws org.springframework.dao.DataAccessExceptionDescription 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:
processNewEntries
in interfaceJournalManager
- 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
-
waitForRecentEntriesToBecomeVisible
Description copied from interface:JournalManager
Waits long enough to ensure that entries added before calling this method will be available to subsequent call toJournalManager.processNewEntries(JournalIdentifier, int, Function)
.- Specified by:
waitForRecentEntriesToBecomeVisible
in interfaceJournalManager
- Throws:
InterruptedException
- if the thread got interrupted
-
getIgnoreWithinMillis
public long getIgnoreWithinMillis()- Specified by:
getIgnoreWithinMillis
in interfaceJournalManager
- Returns:
- the time that new entries are ignored
-
getMostRecentId
public Optional<JournalEntry> getMostRecentId(@NonNull JournalIdentifier journalIdentifier) throws org.springframework.dao.DataAccessException Description copied from interface:JournalManager
Gets the most recent entry in the journal for the given journal identifier- Specified by:
getMostRecentId
in interfaceJournalManager
- 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
public void setMostRecentId(@NonNull JournalIdentifier journalIdentifier, long id) throws org.springframework.dao.DataAccessException Description copied from interface:JournalManager
Stores the most recent journal entry id in the journal store- Specified by:
setMostRecentId
in interfaceJournalManager
- 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
public void setMostRecentId(@NonNull JournalEntry journalEntry) throws org.springframework.dao.DataAccessException Description copied from interface:JournalManager
Stores the most recent journal entry id in the journal store- Specified by:
setMostRecentId
in interfaceJournalManager
- 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
public int removeEntriesOlderThanExclusive(@NonNull Date date, Collection<String> excludingJournalNames) Description copied from interface:JournalManager
Removes entries from journals that were created before the given date. Excluding journal if name match with excludingJournalName- Specified by:
removeEntriesOlderThanExclusive
in interfaceJournalManager
- Returns:
-
removeEntriesOlderThanInclusive
Description copied from interface:JournalManager
Removes entries from journals that were created before the given date. Excluding journal if name match with journalNames- Specified by:
removeEntriesOlderThanInclusive
in interfaceJournalManager
- Returns:
-