zeromemes / alpine Goto Github PK
View Code? Open in Web Editor NEWA lightweight event system for Java 8+
License: MIT License
A lightweight event system for Java 8+
License: MIT License
How do I add this as a external library in my project?
Help needed
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
.
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
.
Alpine 2.0!?
Hey so I wanted to mess around in the code for a bit but I saw that event.events.PacketEvent is nowhere to be found in it
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.
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.
Self explanatory
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.
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.
Precursor to completion of #12
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.
The example code should be in a separate gradle project, not the test
source set.
public static final EventBus EVENT_BUS = new EventManager();
throws
Required type: EventBus
Provided: EventManager
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.