Class EventLogService
An event that occurs during an update or a processing function within a transaction becomes a fact when the transaction completes successfully. The EventLogService can be used to store this kind of "Change Data Capture" events in a log. An example is the LuceneUpdateService, which should update the index of a document only if the document was successfully written to the database.
The service is bound to the current PersistenceContext and stores a EventLog entity directly in the database to represent an event. These types of events can be queried by clients through the service.
The EventLogService provides a lock/unlock mechanism. An eventLog entry can optional be locked for processing. The topic of the event will be suffixed with '.lock' to indicate that this topic is locked by a running process. If a lock is successful a client can exclusive process this eventLog entry.
The method releaseDeadLocks unlocks eventlog entries which are older than 1 minute. We assume that these events are deadlocks.
- Version:
- 1.0
- Author:
- rsoika
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateEvent
(String topic, String refID) Creates/updates a new event log entry.createEvent
(String topic, String refID, Calendar timeout) Creates/updates a new event log entry.Creates/updates a new event log entry.createEvent
(String topic, String refID, ItemCollection document) Creates/updates a new event log entry.createEvent
(String topic, String refID, ItemCollection document, Calendar timeout) Creates/updates a new event log entry.findAllEvents
(int firstResult, int maxResult) Returns all event log entriesfindEventsByRef
(int maxCount, String ref, String... topic) Finds events for one or many given topics assigned to a given document reference ($uniqueId).findEventsByTimeout
(int maxCount, String... topic) Finds events for one or many given topics within the current timeout.findEventsByTopic
(int maxCount, String... topic) Finds events for one or many given topicsReturns an detached event log entry by its ID.boolean
This method locks an eventLog entry for processing.void
releaseDeadLocks
(long deadLockInterval, String... topic) This method unlocks eventlog entries which are older than 1 minute.void
removeEvent
(String id) Deletes an existing eventLog by its id.void
removeEvent
(EventLog _eventLog) Deletes an existing eventLog.boolean
This method unlocks an eventLog entry.
-
Field Details
-
EVENTLOG_LOCK_DATE
- See Also:
-
-
Constructor Details
-
EventLogService
public EventLogService()
-
-
Method Details
-
createEvent
Creates/updates a new event log entry.- Parameters:
refID
- - uniqueid of the document to be assigned to the eventtopic
- - the topic of the event.- Returns:
- - generated event log entry
-
createEvent
Creates/updates a new event log entry.- Parameters:
refID
- - uniqueid of the document to be assigned to the eventtopic
- - the topic of the event.timeout
- - optional timeout calendar object- Returns:
- - generated event log entry
-
createEvent
Creates/updates a new event log entry.- Parameters:
refID
- - uniqueId of the document to be assigned to the eventtopic
- - the topic of the event.document
- - optional document providing a data map- Returns:
- - generated event log entry
-
createEvent
Creates/updates a new event log entry.- Parameters:
refID
- - uniqueId of the document to be assigned to the eventtopic
- - the topic of the event.document
- - optional document providing a data maptimeout
- - optional timeout calendar object- Returns:
- - generated event log entry
-
createEvent
public EventLog createEvent(String topic, String refID, Map<String, List<Object>> data, Calendar timeout) Creates/updates a new event log entry.- Parameters:
refID
- - uniqueId of the document to be assigned to the eventtopic
- - the topic of the event.data
- - optional data map- Returns:
- - generated event log entry
-
findEventsByTopic
Finds events for one or many given topics- Parameters:
maxCount
- - maximum count of events to be returnedtopic
- - list of topics- Returns:
- - list of eventLogEntries
-
findEventsByTimeout
Finds events for one or many given topics within the current timeout.The attribute 'timeout' is optional. If the timeout is set to a future point of time, the event will be ignored by this method.
- Parameters:
maxCount
- - maximum count of events to be returnedtopic
- - list of topics- Returns:
- - list of eventLogEntries
-
findEventsByRef
Finds events for one or many given topics assigned to a given document reference ($uniqueId). The method returns an empty list if no event log entries exist of the given refId,- Parameters:
maxCount
- - maximum count of events to be returnedref
- - a reference ID for an assigned Document or Workitem instancetopic
- - list of topics- Returns:
- - list of eventLogEntries
-
findAllEvents
Returns all event log entries- Parameters:
firstResult
- - first resultmaxResult
- - maximum count of events to be returned- Returns:
- - list of eventLogEntries
-
removeEvent
Deletes an existing eventLog. The method catches jakarta.persistence.OptimisticLockException as this may occur during parallel requests.- Parameters:
eventLog
-
-
removeEvent
Deletes an existing eventLog by its id. The method catches jakarta.persistence.OptimisticLockException as this may occur during parallel requests.- Parameters:
eventLog
-
-
getEvent
Returns an detached event log entry by its ID.- Parameters:
id
- - id of the eventLog Entry- Returns:
- detached eventLog entry or null if not found
-
lock
This method locks an eventLog entry for processing. The topic will be suffixed with '.lock' to indicate that this topic is locked by a process. If a lock is successful a client can exclusive process this eventLog entry.The method adds a item 'eventlog.lock.date' with a timestamp. This timestamp is used by the method 'autoUnlock' to release locked entries.
- Parameters:
eventLogEntry
-- Returns:
- - true if lock was successful
-
unlock
This method unlocks an eventLog entry. The topic suffix '.lock' will be removed.- Parameters:
eventLogEntry
-- Returns:
- - true if unlock was successful
-
releaseDeadLocks
This method unlocks eventlog entries which are older than 1 minute. We assume that these events are deadlocks.
-