Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: FEATURE: Centralized event handling #177

Closed

Conversation

bwaidelich
Copy link
Member

@bwaidelich bwaidelich commented Feb 28, 2018

This centralizes the invokation of when*() event handlers to a central
class that ensures the following invokation order:

  1. beforeInvokingEventListenerMethod() (when implementing ActsBeforeInvokingEventListenerMethodsInterface)
  2. when*() (the actual event handler)
  3. saveHighestAppliedSequenceNumber() (when implementing AsynchronousEventListenerInterface)
  4. afterInvokingEventListenerMethod() (when implementing ActsAfterInvokingEventListenerMethodsInterface)

This allows EventListeners to wrap the event handling in transactions for example:

class SomeEventListener implements AsynchronousEventListenerInterface, ActsBeforeInvokingEventListenerMethodsInterface, ActsAfterInvokingEventListenerMethodsInterface
{
  public function beforeInvokingEventListenerMethod(EventInterface $event): void
  {
    // start transaction
  }

  public function whenSomeEvent(SomeEvent $event): void
  {
     // db interaction
  }

  public function saveHighestAppliedSequenceNumber(int $sequenceNumber): void
  {
    // update sequence number in db
  }

  public function afterInvokingEventListenerMethod(EventInterface $event): void
  {
    // commit transaction
  }
}

This change...

  • Renames EventListenerLocator to EventListenerManager – the class
    is now also responsible for invoking event listeners
  • Removes EventPublisher::catchUp() and moves the remaining logic to
    the EventCommandController
  • Introduces an ActsAfterInvokingEventListenerMethodsInterface marker
    interface, that is used similarily to ActsBeforeInvokingEventListenerMethodsInterface
    and allows to wrap event handling in a transaction
  • Introduces a new EventCantBeAppliedException that allows for easier handling of
    exceptions during event handling (see Event watcher should not quit upon errors/exceptions #161)
  • Removes an unused projectionCache configuration

Related: #159

This centralizes the invokation of `when*()` event handlers to a central
class that ensures the following invokation order:

# `beforeInvokingEventListenerMethod()` (when implementing `ActsBeforeInvokingEventListenerMethodsInterface`)
# `when*()` (the actual event handler)
# `saveHighestAppliedSequenceNumber()` (when implementing `AsynchronousEventListenerInterface`)
# `afterInvokingEventListenerMethod()` (when implementing `ActsAfterInvokingEventListenerMethodsInterface`)

This allows EventListeners to wrap the event handling in transactions for example:

```
class SomeEventListener implements AsynchronousEventListenerInterface, ActsBeforeInvokingEventListenerMethodsInterface, ActsAfterInvokingEventListenerMethodsInterface
{
  public function beforeInvokingEventListenerMethod(EventInterface $event): void
  {
    // start transaction
  }

  public function whenSomeEvent(SomeEvent $event): void
  {
     // db interaction
  }

  public function saveHighestAppliedSequenceNumber(int $sequenceNumber): void
  {
    // update sequence number in db
  }

  public function afterInvokingEventListenerMethod(EventInterface $event): void
  {
    // commit transaction
  }
}
```

This change...

* Renames `EventListenerLocator` to `EventListenerManager` – the class
  is now also responsible for *invoking* event listeners
* Removes `EventPublisher::catchUp()` and moves the remaining logic to
  the `EventCommandController`
* Introduces an `ActsAfterInvokingEventListenerMethodsInterface` marker
  interface, that is used similarily to `ActsBeforeInvokingEventListenerMethodsInterface`
  and allows to wrap event handling in a transaction
* Introduces a new `EventCantBeAppliedException` that allows for easier handling of
  exceptions during event handling (see neos#161)
* Removes an unused `projectionCache` configuration

Related: neos#159
@bwaidelich
Copy link
Member Author

NOTE: To be transaction-safe the getHighestAppliedSequenceNumber() method has to be called after beforeInvokingEventListenerMethod() but I don't know (yet) how to achieve this

@bwaidelich bwaidelich changed the title FEATURE: Centralized event handling WIP: FEATURE: Centralized event handling Mar 1, 2018
@bwaidelich
Copy link
Member Author

We now have a plan for a rework that includes "HighestAppliedSequenceNumber" retrieval/update in the transaction. I'll push a follow-up asap

@bwaidelich
Copy link
Member Author

WIP WIP WIP

@skurfuerst
Copy link
Member

@bwaidelich we can close this one, right?

@bwaidelich
Copy link
Member Author

yes

@bwaidelich bwaidelich closed this Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants