Giter VIP home page Giter VIP logo

alpine's People

Contributors

hexeption avatar leafhacker avatar zeromemes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

alpine's Issues

Dispatch Threads

Currently, all dispatches are immediate, and run on the same thread calling post. Some applications may have reason to defer the processing of events to a "main thread" or some other arbitrary queue.

An implementation of this should probably focus on per-Listener dispatch, since deferring all posted events can already easily be done by extending EventManager.

Race condition between post and unsubscribe

In multi-threaded applications, it's currently possible for calls to unsubscribe to complete while event dispatch is ongoing. This could end up being problematic, such an example could be a cleanup routine that runs immediately after unsubscribe and invalidates objects referenced by an event callback. In these situations, a synchronous ListenerList implementation would be necessary, implemented using either a mutex or read-write lock depending on the setup.

Currently, all ListenerList usages are backed by CopyOnWriteListenerList, which is hard-coded into EventManager.

Extensibility

  • Configurable ListenerList implementation via EventBusBuilder

ListenerList

  • Single-threaded implementation
  • Mutex wrapper
  • Read-write lock wrapper

Custom Event to Listener Maps

There's no way to control the underlying implementation of EventManager.activeListeners.

The current implementation in 3.0.0 is backed by a Reference2ObjectOpenHashMap, which is allowed to infinitely grow. However, some applications may use an EventBus which has a fixed amount of known event types (Baritone 👀). In such a case, a perfect hashing function could be used for optimized lookup.

I'll need to do some research into automatically generating perfect hash functions, and a lot of benchmarking to see if/when something like this can actually have a statistically significant performance benefit.

Coroutines

kotlinx-coroutines is a really powerful library and could probably be added to allow kotlin developers to use this without interfering with the rest of the library.

Since kotlin is fully compatible with java, it may be worth migrating part of the project to kotlin to allow coroutine functioning within the EventBus.

Kotlin Support

While there’s no reason why Kotlin can’t be used with Alpine in its current state, there’s probably language features of Kotlin that can be leveraged for nicer/more efficient usage.

My initial thought on this is addressing nullability in Kotlin. The JetBrains annotations library can be used to provide these hints to the Kotlin compiler.

Generic events cause runtime ClassCastException

If a Listener is created for an event type with a generic type parameter, the type parameter won't be respected at runtime. This can lead to unexpected ClassCastExceptions being thrown.

Adding support for generic events could be an enhancement in the future, but for now, it should throw an exception during discovery.

Listener Priority Considerations

Currently, Listener priority for events is only used for sorting Listener instances in ListenerGroup. This works fine if a single event bus is being used without super listeners. However, when an event is posted to an attachable event bus, the attachable bus will dispatch the event to all of it's registered listeners before any of the children receive it, regardless of priority. Similarly, if super listeners are being used, the listeners subscribing to the exact type of an event will receive the event first, regardless of whether a listener of a super type is subscribed with a higher priority.

Ideally, some sort of mechanism for "global" listener priority should exist to solve this issue. The only way I can think of implementing this is through a multi-stage event dispatch, but that would likely require a small number of fixed event priorities, rather than any arbitrary integer value.

Example subproject

The example code should be in a separate gradle project, not the test source set.

Problem with README

public static final EventBus EVENT_BUS = new EventManager();

throws

Required type: EventBus
Provided: EventManager

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.