Skip to content

API for altering how the characteristics of EventBus / EventListener are determined #72

@ZZZank

Description

@ZZZank

The API of EventBus7 is quite unique, making it hard to migrate from previous version, and basically impossible if backward compatibility is required.

The main burden of migration is the change in how some key data are determined, for example:

  • event priority is determined by byte instead of enum EventPriority
  • whether an event is cancellable is determined by implement Cancellable instead of @CancellableEvent
  • whether an event is cancelled is determined by predicate.test(...) instead of event.isCancelled()

So backward compatibility should be much easier if these process can be customized. This can be done by adding an API for determining the characteristic of EventBus / EventListener. There's a rough example:

// null -> fall through

public interface BusCharacteristicProvider {
    @Nullable Boolean isCancellable(Class<? extends Event> eventType);
    @Nullable Boolean isMonitorAware(Class<? extends Event> eventType);
    @Nullable Boolean isSelfPosting(Class<? extends Event> eventType);
    @Nullable Boolean isSelfDestructing(Class<? extends Event> eventType)
}

interface ListenerCharacteristicProvider {
    @Nullable Byte getPriority(Method method, Class<?> parent);
    @Nullable BiPredicate<EventListener, Event> getCancellationReader(EventListener listener, Method method);
}

then implementations can provide compatibility with old code by providing customized XXXCharacteristicProvider, for example using Event::isCancelled as the return value of getCancellationReader(...) can bring backward compatibility with old event cancelling.

Note that the API here is quite rough and not performance-wise, there's probably be a better option

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions