You are browsing as a guest. Sign up (or log in) to start making projects!

Java Utils

  • 8 Devlogs
  • 80 Total hours

A collection of java utils, primarily focusing on an event bus framework.

Ship #1 Pending review

I built java-utils, a collection of high-performance Java utilities and APIs designed for Java 21+.
It provides optimised and robust core features, featuring a high-performance event dispatching system, a multi layered and priority based service loading framework, thread safe object registries, and more.

Features:
High performance polymorphic event dispatching system (event bus) supporting priority-based routing and cancellation logic. It utilises SPI loaded compile time generated invoker factories for reflection free dispatch when compiled with the annotation processor, alongside high performance fallbacks via LambdaMetafactory and MethodHandle.
A multilayered and priority service loading framework. Provided ServiceLayers are passed to ServiceBootstrap to create ServiceRegistry, which allows users to find and locate implementations by providing the registry with a contract class, where the layers will locate the implementations.
Thread safe freezable object Registry<T> with a mutate and freeze lifecycle, allowing safe registration during bootstrap before turning strictly read only on freeze.
Config helpers to aid config serialisation with Kaleido Config (e.g. implement ISerializableEnum<T> on an enum to make it serialisable, ElementOrList type to either take a single element or a list)
Reflection wrapper designed to try comply with the Java Language Specification (JLS)

  • 8 devlogs
  • 80h
Try project → See source code →
Open comments for this post

5h 8m 57s logged

Event Bus:

Make MainBus#get static instead of instance method to allow users to utilise the provided MainBus

Service API:

Fix ClassLoaderServiceLoader not working in module environments by declaring Module#addUses

Add MutableServiceLayer for manual service layers and create factory method for configuring them

Registry:

Add static factory methods to create MutableMappedIdRegistry and MutableKeylessRegistry instances

Other:

Add demo subproject (CC0 license) showcasing features and how to use eventbus, registry and service api

Update build workflow to publish demo artifact

Add release github workflow to automatically publish artifacts when a release is created

Promote config helpers, registry and service api from WIP to experimental

Update README with event bus demo image

0
0
5
Open comments for this post

8h 29m 16s logged

Event bus:
Disallowed @Weak on static event handlers for reflection discovered methods. Static handlers do not have a listener to bound to and thus have no reason to be declared as weak listeners; this additionally improves parity with the annotation processor.

Service API:
Added factory methods to create ServiceLayer instances across different ClassLoaders and ModuleLayers.

Registry system:
The registry system was redesigned essentially from the ground up.
MutableRegistry has been detached from Registry, and extending interfaces such as MutableMappedRegistry provide additional features (e.g. key -> value mappings)
Key -> value mappings are now supported via MappedRegistry and its implementors and ID mappings have been added via the IdRegistry interface. Current implementations like SimpleMutableKeylessRegistry and SimpleMutableMappedIdRegistry provide O(1) operations for lookup and registration whilst still supporting concurrent operations via BoundedSnapshotMap and BoundedSnapshotList as each registration is immutable.

Other:
Updated build workflow
Added USAGE documentation to README showing how to add the library as a dependency in Gradle.

0
0
6
Open comments for this post

10h 1m 54s logged

Remove read lock on event dispatch by providing an activeTable Supplier to pass events to if this DispatchTable is closed, allowing #dispatch to race with #close safely.
Decouple creation of DispatchTable from Flattener
Add option to disable recursion guard in EventBusBuilder
Further optimize event dispatch for guarded event buses by removing ThreadLocal#remove call. This remains safe as it is a lightweight 1 length int[] array.
Fix ClassValueDispatchTable not dispatching events
Improve internal RecursionGuard usability by accepting a Runnable instead of manual #increment and #resetTo(int) calls.
Updated unit tests where appropriate to account for refactors
Added JMH benchmarks for guarded and unguarded recursion event buses
Updated README with benchmark results.

0
0
13
Open comments for this post

9h 23m 34s logged

Added support for compile time generated @Weak instance and static event processors.
Full refactor of the annotation processor to cleanup the code structure and improve safety via compile time validation.
New abstract MethodDescriptor implemented by alongside some implementations like ElementMethodDescriptor (annotation processor variant), ReflectionMethodDescriptor (runtime reflection variant) and MethodKeyDescriptor (cached reflection variant), used to compare methods cleanly.
Individual method registration has not yet been implemented. MethodDescriptor will be utilised to locate individual handlers.

0
0
11
Open comments for this post

11h 37m 57s logged

Introduced compile-time generated event listeners via an Annotation Processor (AP automatically generates SPI implementations) to reduce runtime reflection which will fallback to reflection path (LambdaMetafactory + MethodHandle fallback) on failure. Currently only built for instance event listeners: static listeners and direct method registrations will be implemented in the future.
The annotation processor looks for classes annotated with @CompiledEventHandlers and generates a SubscriberInvokerFactory which holds an EventSubscriberInvoker for each method.
Refactored the reflection subscriber path (EventSubscriberCompiler and EventHandlerCompiler) to follow SOLID better and improve extensibility
Update unit tests to work with the updated code

0
0
16
Open comments for this post

3h 27m 21s logged

Fixed issues with configuration caching
Repackage and add javadoc to config helpers
Improved usability by improving javadoc.
Renamed Linkable to SubscribtionAware to better fit the name.
Finalized EventBusBuilder by adding a register to global registry flag, replacing event consumers with dedicated functional interfaces, updating ErrorHandler to have throwUnchecked helper and replacing the old deprecated EventBus with the new one
Repackage and rename module to com.github.rcubedev.utils

0
0
22
Open comments for this post

30h 33m 29s logged

Deprecated the old EventBus god object, in favour for the new EventBus implementation which now better following SOLID, improving debugging and DX. It utilises composition, where all features are separated into different classes for testability. Migrated from a flat array dispatch table to a class value dispatch table for O(1) handler lookups after caching vs O(n) before.

0
0
12

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…