KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
bus
★ 13
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
velox-testing
:
No description available.
investigation-data-broker-opt-out-pages
:
Data for The Markup and CalMatters story "We caught companies making it harder to delete your personal data online"
c3d
:
Cxmpute 3D Lab
2190513_DS-ICE_2025s1
:
No description available.
go-fetch
:
go-fetch: Graph Oriented Fast Edge Traversal Cache Hub (Graph AI Agent Memory for Dgraph and Neo4j)
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
bus
?
Download (.md)
<div align="center"> <h1>[ bus ]</h1> Reasonably fast & simple pub-sub written for Java applications. Mainly for sequential/single-threaded applications. <br>Did this only for experimental reasons. Contributions are welcome if you want to add or optimise something. </div> <div align="center"> # [ how to use ] </div> **Step 1**: <br> Create new event bus instance, so you can actually use all of its capabilities. Example of how to create the instance: ```java import net.redinginer.eventbus.EventBus; EventBus eventBus = EventBus.create(); // subscribe, publish or unsubscribe events ``` **Step 2**: <br> Create your first event. Events must inherit the **AbstractEvent** class, as the bus highly depends on it. <br>Currently, the abstraction provides only one property - cancelled. But it should be enough for most apps. <br>Example on how to create the event: ```java import net.redinginer.eventbus.AbstractEvent; public final class SimpleEvent extends AbstractEvent { // here, you define the properties of the event, // for example: private final String string; public SimpleEvent(String string) { this.string = string; } public String getString() { return this.string; } } ``` **Step 3 (and last)**: <br> Create your first listener, that can listen to events. Listeners are defined by **@Subscribe** annotation, and any method w/o it is ignored. <br>Methods also have strict checks, for example, they can't return anything, cannot have more than 1 parameter, and the parameter type must be assignable from **AbstractEvent**. <br>Example on how to listen for the events, publish them, and unsubscribe after: ```java // here goes your listener class import net.redinginer.eventbus.EventPriority; import net.redinginer.eventbus.Subscribe; public class SimpleListener { @Subscribe(priority = EventPriority.HIGHEST) public void handleFirst(SimpleEvent event) { System.out.println("This event will be called, as nothing else cancels it."); System.out.println("Here goes the string:"); System.out.println(event.getString()); System.out.println("And now, we are cancelling the event."); event.setCancelled(true); } @Subscribe(priority = EventPriority.HIGH, ignoreCancelled = true) public void handleSecond(SimpleEvent event) { System.out.println("This method won't be called when we cancelled the event."); System.out.println("But here goes the string:"); System.out.println(event.getString()); } } // here goes your main class import net.redinginer.eventbus.EventBus; EventBus eventBus = ... // the event bus instance you acquired SimpleListener listener = new SimpleListener(); eventBus.subscribe(listener); // this subscribes the listener eventBus.publish(new SimpleEvent("Test!")); // this publishes the event eventBus.unsubscribe(listener); // this unsubscribes the listener (must be the same object ref!) ``` <div align="center"> # [ benchmarks ] | Benchmark | Mode | Cnt | Score | Error | Units | |------------------------------------------------------------------------------------------------------------------------------------|------|-----|------------|-------------|-------| | [PostBenchmark.benchmarkPublish (listenerCount = 10)](src/jmh/java/net/redinginer/eventbus/benchmark/PostBenchmark.java) | avgt | 20 | 176.818 | ± 1.201 | ns/op | | [PostBenchmark.benchmarkPublish (listenerCount = 100)](src/jmh/java/net/redinginer/eventbus/benchmark/PostBenchmark.java) | avgt | 20 | 4525.797 | ± 305.273 | ns/op | | [PostBenchmark.benchmarkPublish (listenerCount = 1000)](src/jmh/java/net/redinginer/eventbus/benchmark/PostBenchmark.java) | avgt | 20 | 598266.246 | ± 14102.518 | ns/op | | [SubscribeBenchmark](src/jmh/java/net/redinginer/eventbus/benchmark/SubscribeBenchmark.java) | avgt | 20 | 112324.134 | ± 8671.304 | ns/op | | [SubscribeUnsubscribeBenchmark](src/jmh/java/net/redinginer/eventbus/benchmark/SubscribeUnsubscribeBenchmark.java) | avgt | 20 | 115887.395 | ± 9880.149 | ns/op | </div> <div align="center"> # [ additional notes ] Project was built using Java 21 (specifically Adoptium OpenJDK 21), and Gradle 9.0.0, with the help of JMH 1.3.7. <br>For any documentation, just look into the code, and you should figure it out pretty easily. <br>Also, I know that there is a room of improvement (for example, in publishing, because we need to traverse the linked list now), <br>But I wanted to test the idea of using linked-lists, as an experiment on how fast we could go. </div>