Class TimestampBasedEventStore

java.lang.Object
com.atlassian.crowd.event.TimestampBasedEventStore
All Implemented Interfaces:
EventStore

public class TimestampBasedEventStore extends Object implements EventStore
A cluster-safe implementation of EventStore that uses the entity creation and update timestamp, and the persisted tombstone information to create an event stream. The produced event streams may be different than the ones produced by @link com.atlassian.crowd.event.EventStoreGeneric, but should lead to creating the same state to the caller replaying the stream (i.e. doing an incremental sync), assuming all operations are idempotent (i.e. adding an entity that's added is not an error, but causes an update; deleting a missing entity is not an error).

Some caveats: - to alleviate for timestamp skew and operations that are not committed when fetching the events, the implementation produces a sync token that will cause events from a few minutes before the sync to be returned again during the next sync. As long as events are idempotent this shouldn't change the state of the caller. - some events make recreating the event stream impossible, and will throw EventTokenExpiredException as per contract because of the replaying this will make incremental sync impossible for the duration of the backoff - alias events are returned in a simplified form, that's different from EventStoreGeneric - as the only usage is to abort incremental sync when an aliasing event occurs, they're all transformed into alias tombstones, and returned a alias deletions - to limit the size of the list materialized in memory, there's a limit to how many events the implementation will return before throwing EventTokenExpiredException. The implementation MIGHT return larger lists if they are already materialized and there's no point in throwing them away.
  • Field Details

    • TIMESTAMP_SLOP_TOLERANCE

      public static final long TIMESTAMP_SLOP_TOLERANCE
  • Constructor Details

  • Method Details

    • getCurrentEventToken

      public String getCurrentEventToken(List<Long> directoryIds)
      Description copied from interface: EventStore
      Returns a token that can be used for querying events that have happened after the token was generated.

      If the event token has not changed since the last call to this method, it is guaranteed that no new events have been received.

      The format of event token is implementation specific and can change without a warning.

      Specified by:
      getCurrentEventToken in interface EventStore
      Parameters:
      directoryIds - the ids of directories that the token should include events for
      Returns:
      token that can be used for querying events that have happened after the token was generated.
    • getNewEvents

      @Transactional public Events getNewEvents(String eventToken, List<Long> directoryIds) throws EventTokenExpiredException
      Description copied from interface: EventStore
      Returns an events object which contains a new eventToken and events that happened after the given eventToken was generated.

      If for any reason event store is unable to retrieve events that happened after the event token was generated, an EventTokenExpiredException will be thrown. The caller is then expected to call EventStore.getCurrentEventToken(List) again before asking for new events.

      Specified by:
      getNewEvents in interface EventStore
      Parameters:
      eventToken - event token that was retrieved by a call to EventStore.getCurrentEventToken(List) or EventStore.getNewEvents(String, List)
      directoryIds - the ids of directories to retrieve events for
      Returns:
      events object which contains a new eventToken and events that happened after the given eventToken was generated.
      Throws:
      EventTokenExpiredException - if events that happened after the event token was generated can not be retrieved
    • getNewEvents

      @Transactional public Events getNewEvents(String eventToken, Application application) throws EventTokenExpiredException
      Description copied from interface: EventStore
      Returns an events object which contains a new eventToken and events that happened after the given eventToken was generated.

      If for any reason event store is unable to retrieve events that happened after the event token was generated, an EventTokenExpiredException will be thrown. The caller is then expected to call EventStore.getCurrentEventToken(List) again before asking for new events.

      Specified by:
      getNewEvents in interface EventStore
      Parameters:
      eventToken - event token that was retrieved by a call to EventStore.getCurrentEventToken(List) or EventStore.getNewEvents(String, List)
      application - the application to retrieve events for
      Returns:
      events object which contains a new eventToken and events that happened after the given eventToken was generated.
      Throws:
      EventTokenExpiredException - if events that happened after the event token was generated can not be retrieved
    • storeOperationEvent

      public void storeOperationEvent(OperationEvent event)
      Description copied from interface: EventStore
      Stores the given event. Implementations MIGHT limit the amount of events stored, and MIGHT not store the event at all if it can be recreated by other means.
      Specified by:
      storeOperationEvent in interface EventStore
      Parameters:
      event - event to be stored
    • handleApplicationEvent

      public void handleApplicationEvent(Object event)
      Description copied from interface: EventStore
      Notifies the store that an application event happened that might make it impossible to recreate the event stream. Depending on the implementation the store MIGHT remove all relevant events, or mark them as invalid. After the call the store MUST NOT present an event stream that might not be valid as a result of the event.
      Specified by:
      handleApplicationEvent in interface EventStore
      Parameters:
      event - the atlassian-events event triggering the action