Add Callback Event Handling #26

Merged
kske merged 3 commits from f/callback-handler into develop 2021-11-05 08:49:07 +01:00
Owner

The EventHandler class has been converted to an interface, with the reflection specific part being moved to the new ReflectiveEventHandler class. Callback event handlers implement the same interface through the CallbackEventHandler class.

The event handlers are defined in the new handler package, which is not exported by the eventbus.core module.

Closes #21

The EventHandler class has been converted to an interface, with the reflection specific part being moved to the new ReflectiveEventHandler class. Callback event handlers implement the same interface through the CallbackEventHandler class. The event handlers are defined in the new handler package, which is not exported by the `eventbus.core` module. Closes #21
kske self-assigned this 2021-11-02 19:34:20 +01:00
kske added 1 commit 2021-11-02 19:34:20 +01:00
ee688929fd
Add callback event handling
The EventHandler class has been converted to an interface, with the
reflection specific part being moved to the new ReflectiveEventHandler
class. Callback event handlers implement the same interface through the
CallbackEventHandler class.

The event handlers are defined in the new handler package, which is not
exported by the eventbus.core module.
kske requested review from mpk 2021-11-02 19:34:23 +01:00
kske requested review from delvh 2021-11-02 19:34:23 +01:00
delvh requested changes 2021-11-04 14:32:50 +01:00
@ -241,0 +277,4 @@
* @since 1.2.0
* @see #registerListener(Class, Consumer, boolean, int)
*/
public <E> void registerListener(Class<E> eventType, Consumer<E> callback,
Owner

Consumer<E> eventListener?

`Consumer<E> eventListener`?
kske marked this conversation as resolved
@ -241,0 +293,4 @@
* @since 1.2.0
* @see #registerListener(Class, Consumer, boolean, int)
*/
public <E> void registerListener(Class<E> eventType, Consumer<E> callback, int priority) {
Owner

eventListener?

eventListener?
kske marked this conversation as resolved
@ -241,0 +307,4 @@
* @param priority the priority to assign to the listener
* @since 1.2.0
*/
public <E> void registerListener(Class<E> eventType, Consumer<E> callback, boolean polymorphic,
Owner

eventListener?

eventListener?
kske marked this conversation as resolved
@ -0,0 +9,4 @@
* @author Kai S. K. Engelbart
* @since 1.2.0
*/
public class CallbackEventHandler implements EventHandler {
Owner

final?

final?
kske marked this conversation as resolved
@ -0,0 +12,4 @@
public class CallbackEventHandler implements EventHandler {
private final Class<?> eventType;
private final Consumer<Object> callback;
Owner

What about Consumer ?

What about Consumer<?> ?
Author
Owner

This wouldn't work, as `callback.accept(event)' would complain about an incompatible argument type.

This wouldn't work, as `callback.accept(event)' would complain about an incompatible argument type.
delvh marked this conversation as resolved
@ -0,0 +20,4 @@
* Constructs a callback event handler.
*
* @param <E> the event type of the handler
* @param eventType the event type of the handler
Owner

😆

:laugh:
kske marked this conversation as resolved
@ -0,0 +30,4 @@
public <E> CallbackEventHandler(Class<E> eventType, Consumer<E> callback, boolean polymorphic,
int priority) {
this.eventType = eventType;
this.callback = (Consumer<Object>) callback;
Owner

😆

:laugh:
kske marked this conversation as resolved
@ -0,0 +45,4 @@
int getPriority();
/**
* @return whether this handler is polymorphic
Owner

... accepts subtypes of the event type as well

... accepts subtypes of the event type as well
kske marked this conversation as resolved
kske added 1 commit 2021-11-04 15:54:41 +01:00
kske requested review from delvh 2021-11-04 15:54:46 +01:00
kske added 1 commit 2021-11-04 15:55:29 +01:00
delvh approved these changes 2021-11-04 23:16:16 +01:00
kske merged commit e67b64678b into develop 2021-11-05 08:49:07 +01:00
kske deleted branch f/callback-handler 2021-11-05 08:49:07 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: zdm/event-bus#26
No description provided.