Implement new module with EventBus API#70
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new rlib-eventbus module that introduces a typed EventBus API and default implementation for synchronous and background event dispatch.
Changes:
- Wires
:rlib-eventbusinto the Gradle multi-project build and README usage docs. - Adds EventBus API contracts, factory methods, package nullness metadata, and default implementations.
- Adds tests covering delivery, unsubscribe behavior, invalid IDs, sparse IDs, conflicts, and async dispatch.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
settings.gradle |
Includes the new EventBus module in the build. |
build.gradle |
Bumps the root project version. |
README.md |
Documents the new module and adds a usage example. |
rlib-eventbus/build.gradle |
Defines the new module and its collections dependency. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/EventBus.java |
Adds the public EventBus API and nested type-id contracts. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/EventBusFactory.java |
Adds factory methods for type-id factories and event buses. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/impl/DefaultEventBus.java |
Implements subscription, unsubscription, synchronous dispatch, and background dispatch. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/impl/DefaultTypeIdFactory.java |
Implements stable per-namespace TypeId creation. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/package-info.java |
Marks the public EventBus package as null-marked. |
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/impl/package-info.java |
Marks the implementation package as null-marked. |
rlib-eventbus/src/test/java/javasabr/rlib/eventbus/DefaultEventBusTest.java |
Adds unit coverage for core EventBus behaviors and edge cases. |
|
|
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This branch introduces a new
rlib-eventbusmodule with a very typed low-overhead event bus API. It adds strongly typed subscription/publishing contracts, default implementation with sync/background dispatch, type-id consistency guards, comprehensive edge-case tests, API naming cleanup, and updated documentation (Javadocs, README usage examples, and event flow diagram).Changes Summary
1. New module: typed low-overhead EventBus
:rlib-eventbusand wired it intosettings.gradlerlib-eventbus/build.gradlewith publishing/java configuration and API dependency onrlib-collectionsEventBus:subscribe(...)/unsubscribe(...)send(...)(synchronous)sendInBackground(...)(background dispatch)TypeIdSet,TypeIdFactory,TypeId, andEvent2. Core implementation and dispatch model
DefaultEventBuswith:TypeId.id()IllegalStateExceptionon conflicting IDs)IllegalArgumentException)ForkJoinPool.commonPool()DefaultTypeIdFactorywith per-TypeIdSettyped factories and stable per-event type IDs3. Event flow diagram
flowchart TD A["Create TypeIdFactory<br/>EventBusFactory.createTypeIdFactory"] --> B["Create EventBus<br/>EventBusFactory.createEventBus"] B --> C["Resolve TypeId<br/>typeIdFactory.typeIdOf event type"] C --> D["Subscribe consumer<br/>eventBus.subscribe typeId consumer"] D --> E{Publish mode} E -->|send| F["Dispatch in caller thread"] E -->|sendInBackground| G["Schedule on executor"] G --> H["Dispatch on background thread"] F --> I["Lookup consumers by typeId id"] H --> I I --> J["Invoke subscribed consumers"]4. Usage samples
Synchronous publish:
Background publish:
5. Test coverage for happy paths and edge cases
DefaultEventBusTestwith 10 tests covering:TypeIdhandling for send/unsubscribeTypeIdbehaviorTesting & Validation
./gradlew --no-daemon :rlib-eventbus:test✅./gradlew --no-daemon :rlib-eventbus:compileJava✅./gradlew clean build(recommended)