-
Notifications
You must be signed in to change notification settings - Fork 6
Implement new module with EventBus API #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be6c1fe
work on eventbus implementation
JavaSaBr 3a28bd2
finalize the first iteration of eventbus module
JavaSaBr f63d3ce
resolve CR comments
JavaSaBr 190e987
update the skill
JavaSaBr d86946b
update readme and test coverage configuration
JavaSaBr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| rootProject.version = "10.0.alpha16" | ||
| rootProject.version = "10.0.alpha17" | ||
| group = 'javasabr.rlib' | ||
|
|
||
| allprojects { | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| plugins { | ||
| id("configure-java") | ||
| id("configure-publishing") | ||
| } | ||
|
|
||
| dependencies { | ||
| api projects.rlibCollections | ||
| } |
124 changes: 124 additions & 0 deletions
124
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/EventBus.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package javasabr.rlib.eventbus; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Provides a typed event bus for subscribing and publishing events by {@link TypeId}. | ||
| * Implementations are expected to support concurrent subscribe, unsubscribe, and send operations. | ||
| * | ||
| * @param <S> the type of type-id set | ||
| * @since 10.0.0 | ||
| */ | ||
| public interface EventBus<S extends EventBus.TypeIdSet> { | ||
|
|
||
| /** | ||
| * Subscribes a consumer to events identified by the provided type id. | ||
| * | ||
| * @param typeId the event type id | ||
| * @param consumer the consumer of events | ||
| * @param <E> the type of event | ||
| * @since 10.0.0 | ||
| */ | ||
| <E extends Event<S>> void subscribe(TypeId<S, E> typeId, Consumer<E> consumer); | ||
|
|
||
| /** | ||
| * Unsubscribes a consumer from events identified by the provided type id. | ||
| * | ||
| * @param typeId the event type id | ||
| * @param consumer the consumer of events | ||
| * @param <E> the type of event | ||
| * @since 10.0.0 | ||
| */ | ||
| <E extends Event<S>> void unsubscribe(TypeId<S, E> typeId, Consumer<E> consumer); | ||
|
|
||
| /** | ||
| * Sends an event to all subscribed consumers in the current thread. | ||
| * This method does not enqueue work and returns only after dispatch is finished. | ||
| * Consumer exceptions are propagated to the caller. | ||
| * | ||
| * @param event the event to send | ||
| * @since 10.0.0 | ||
| */ | ||
| void send(Event<S> event); | ||
|
|
||
| /** | ||
| * Schedules sending an event on the background executor. | ||
| * This method returns immediately after scheduling. | ||
| * Delivery order between different background sends is not guaranteed and depends on the executor policy. | ||
| * Consumer exceptions are handled on the background thread. | ||
| * | ||
| * @param event the event to send | ||
| * @since 10.0.0 | ||
| */ | ||
| void sendInBackground(Event<S> event); | ||
|
|
||
| /** | ||
| * Marks a type-id namespace used to isolate event buses by event family. | ||
| * | ||
| * @since 10.0.0 | ||
| */ | ||
| interface TypeIdSet { | ||
| } | ||
|
|
||
| /** | ||
| * Creates stable {@link TypeId} instances for event types within one type-id namespace. | ||
| * | ||
| * @param <S> the type of type-id set | ||
| * @since 10.0.0 | ||
| */ | ||
| interface TypeIdFactory<S extends TypeIdSet> { | ||
|
|
||
| /** | ||
| * Returns a type id for the specified event type. | ||
| * | ||
| * @param eventType the event class | ||
| * @param <E> the type of event | ||
| * @return the type id of the event class | ||
| * @since 10.0.0 | ||
| */ | ||
| <E extends Event<S>> TypeId<S, E> typeIdOf(Class<E> eventType); | ||
| } | ||
|
|
||
| /** | ||
| * Represents an identity of one event type within a {@link TypeIdSet}. | ||
| * | ||
| * @param <S> the type of type-id set | ||
| * @param <E> the type of event | ||
| * @since 10.0.0 | ||
| */ | ||
| interface TypeId<S extends TypeIdSet, E extends Event<S>> { | ||
|
|
||
| /** | ||
| * Returns the event class associated with this type id. | ||
| * | ||
| * @return the event class | ||
| * @since 10.0.0 | ||
| */ | ||
| Class<E> eventType(); | ||
|
|
||
| /** | ||
| * Returns the numeric id used for fast lookup in event bus internals. | ||
| * | ||
| * @return the numeric event type id | ||
| * @since 10.0.0 | ||
| */ | ||
| int id(); | ||
| } | ||
|
|
||
| /** | ||
| * Represents an event published to an {@link EventBus}. | ||
| * | ||
| * @param <S> the type of type-id set | ||
| * @since 10.0.0 | ||
| */ | ||
| interface Event<S extends TypeIdSet> { | ||
|
|
||
| /** | ||
| * Returns the type id of this event. | ||
| * | ||
| * @return the type id of this event | ||
| * @since 10.0.0 | ||
| */ | ||
| TypeId<S, ? extends Event<S>> typeId(); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
rlib-eventbus/src/main/java/javasabr/rlib/eventbus/EventBusFactory.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package javasabr.rlib.eventbus; | ||
|
|
||
| import javasabr.rlib.eventbus.EventBus.TypeIdFactory; | ||
| import javasabr.rlib.eventbus.EventBus.TypeIdSet; | ||
| import javasabr.rlib.eventbus.impl.DefaultEventBus; | ||
| import javasabr.rlib.eventbus.impl.DefaultTypeIdFactory; | ||
| import lombok.experimental.UtilityClass; | ||
|
|
||
| /** | ||
| * Provides factory methods for creating event bus API components. | ||
| * | ||
| * @since 10.0.0 | ||
| */ | ||
| @UtilityClass | ||
| public class EventBusFactory { | ||
|
|
||
| /** | ||
| * Creates a type-id factory for the provided type-id namespace. | ||
| * | ||
| * @param typeIdSetType the type-id namespace class | ||
| * @param <S> the type of type-id set | ||
| * @return a type-id factory for the namespace | ||
| * @since 10.0.0 | ||
| */ | ||
| public static <S extends TypeIdSet> TypeIdFactory<S> createTypeIdFactory(Class<S> typeIdSetType) { | ||
| return DefaultTypeIdFactory.INSTANCE.typedTypeIdFactory(typeIdSetType); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an event bus instance. | ||
| * The default implementation uses a shared background executor for {@link EventBus#sendInBackground(EventBus.Event)}. | ||
| * | ||
| * @param typeIdFactory the type-id factory associated with this bus API | ||
| * @param <S> the type of type-id set | ||
| * @return a new event bus | ||
| * @since 10.0.0 | ||
| */ | ||
| public static <S extends TypeIdSet> EventBus<S> createEventBus(@SuppressWarnings("unused") TypeIdFactory<S> typeIdFactory) { | ||
| return new DefaultEventBus<>(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.