KEvent alternatives and similar libraries
Based on the "Misc" category.
Alternatively, view KEvent alternatives based on common mentions on social networks and blogs.
-
jclasslib
jclasslib bytecode editor is a tool that visualizes all aspects of compiled Java class files and the contained bytecode. -
kotlin-logging
Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade. -
kotlin-telegram-bot
🤖 A wrapper for the Telegram Bot API written in Kotlin -
kotlinx.atomicfu
The idiomatic way to use atomic operations in Kotlin -
tinylog
tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android -
lingua
The most accurate natural language detection library for Java and the JVM, suitable for long and short text alike -
Kotlift
Kotlift is the first source-to-source language transpiler from Kotlin to Swift -
kotlinx.reflect.lite
Lightweight library allowing to introspect basic stuff about Kotlin symbols -
Humanizer.jvm
Humanizer.jvm meets all your jvm needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities. -
actions-on-google-kotlin
Unofficial Actions on Google SDK for Kotlin and Java -
klutter
A mix of random small libraries for Kotlin, the smallest reside here until big enough for their own repository. -
solr-undertow
Solr / SolrCloud running in high performance server - tiny, fast startup, simple to configure, easy deployment without an application server. -
kassava
This library provides some useful kotlin extension functions for implementing toString(), hashCode() and equals() without all of the boilerplate. -
SimpleDNN
SimpleDNN is a machine learning lightweight open-source library written in Kotlin designed to support relevant neural network architectures in natural language processing tasks -
units-of-measure
Type-safe dimensional analysis and unit conversion in Kotlin. -
kotlin-futures
A collections of extension functions to make the JVM Future, CompletableFuture, ListenableFuture API more functional and Kotlin like. -
TLSLibrary
Simple TlsLibrary written in Kotlin - Provides DSL for creating TLS connections -
scientist
A kotlin library for refactoring code. Port of GitHub's scientist. -
kasechange
🐫🐍🍢🅿 Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case -
kjob
A lightweight coroutine based persistent job/cron scheduler written in Kotlin -
PrimeCalendar
PrimeCalendar provides all of the java.util.Calendar functionalities for Persian, Hijri, and ... dates. It is also possible to convert dates to each other. -
kotlin-pluralizer
:sunny: Kotlin extension to pluralize and singularize strings -
kformula
Mathematical expression engine written in Kotlin, running on JVM. -
kase-format
Multiplatform kotlin string case conversion and detection library.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of KEvent or a related project?
README
KEvent
A powerful in-process event dispatcher based on Kotlin and Coroutines.
Feature List
- Implement publish–subscribe pattern
- Tiny (56.4kb jar) and super fast (no reflection)
- Usable in plenty scenarios: plain kotlin, server side, android, javafx, swing
- Use Enum as event type, so you don't have to create numerous event classes
- Support 4 event dispatch modes with 3 subscriber thread modes
| DispatchMode\ThreadMode | POSTING | BACKGROUND | UI | |--------------------------|:-------:|:----------:|:----:| | INSTANTLY | √ | × | × | | SEQUENTIAL | × | √ | √ | | CONCURRENT | × | √ | × | | ORDERED_CONCURRENT | × | √ | × |
- Support a bunch of advanced features:
- event blocking
- event dispatch cancellation
- sticky events
- subscriber priority
- subscriber tag
- subscribe multiple event types with same subscriber
- multiple ways to subscribe and unsubscribe
- provide a helpful subscriber interface
- Thread safe
- Fully tested
Download
Gradle Kotlin DSL
implementation("org.rationalityfrontline:kevent:1.0.0")
Gradle Groovy DSL
implementation 'org.rationalityfrontline:kevent:1.0.0'
Maven
<dependency>
<groupId>org.rationalityfrontline</groupId>
<artifactId>kevent</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
Usage
import java.lang.ClassCastException
enum class EventTypes {
UNIT_EVENT,
STRING_EVENT,
}
private class ExampleSubscriber : KEventSubscriber {
fun registerSubscribers() {
subscribe<Unit>(EventTypes.UNIT_EVENT) { event ->
println("${"ExampleSubscriber.lambda".padEnd(35)}: $event")
}
subscribe(EventTypes.STRING_EVENT, ::onStringEvent)
subscribeMultiple(listOf(
EventTypes.UNIT_EVENT,
EventTypes.STRING_EVENT,
), ::onAnyEvent)
}
fun unregisterSubscribers() {
unsubscribeAll()
}
private fun onStringEvent(event: Event<String>) {
println("${"ExampleSubscriber.onStringEvent".padEnd(35)}: $event")
}
private fun onAnyEvent(event: Event<Any>) {
try {
when (event.type) {
EventTypes.UNIT_EVENT -> event.data as Unit
EventTypes.STRING_EVENT -> event.data as String
}
} catch (e: ClassCastException) {
println("Different event data types might come with same event type: ${e.message}")
}
println("${"ExampleSubscriber.onAnyEvent".padEnd(35)}: $event")
}
}
private fun topLevelOnStringEvent(event: Event<String>) {
println("${"topLevelOnStringEvent".padEnd(35)}: $event")
}
fun main() {
KEvent.subscribe<Unit>(EventTypes.UNIT_EVENT, tag = "main") { event ->
println("${"main.lambda".padEnd(35)}: $event")
}
KEvent.subscribe(EventTypes.STRING_EVENT, ::topLevelOnStringEvent)
val subscriber = ExampleSubscriber()
subscriber.registerSubscribers()
KEvent.post(EventTypes.UNIT_EVENT, Unit)
KEvent.post(EventTypes.STRING_EVENT, "KEvent is awesome!")
KEvent.post(EventTypes.STRING_EVENT, 42)
subscriber.unregisterSubscribers()
KEvent.removeSubscribersByTag("main")
KEvent.unsubscribe(EventTypes.STRING_EVENT, ::topLevelOnStringEvent)
}
Running the code above will produce the following outputs:
main.lambda : Event(type=UNIT_EVENT, data=kotlin.Unit, dispatchMode=INSTANTLY, isSticky=false)
ExampleSubscriber.lambda : Event(type=UNIT_EVENT, data=kotlin.Unit, dispatchMode=INSTANTLY, isSticky=false)
ExampleSubscriber.onAnyEvent : Event(type=UNIT_EVENT, data=kotlin.Unit, dispatchMode=INSTANTLY, isSticky=false)
topLevelOnStringEvent : Event(type=STRING_EVENT, data=KEvent is awesome!, dispatchMode=INSTANTLY, isSticky=false)
ExampleSubscriber.onStringEvent : Event(type=STRING_EVENT, data=KEvent is awesome!, dispatchMode=INSTANTLY, isSticky=false)
ExampleSubscriber.onAnyEvent : Event(type=STRING_EVENT, data=KEvent is awesome!, dispatchMode=INSTANTLY, isSticky=false)
topLevelOnStringEvent : Event(type=STRING_EVENT, data=42, dispatchMode=INSTANTLY, isSticky=false)
ExampleSubscriber.onStringEvent : Event(type=STRING_EVENT, data=42, dispatchMode=INSTANTLY, isSticky=false)
Different event data types might come with same event type: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
ExampleSubscriber.onAnyEvent : Event(type=STRING_EVENT, data=42, dispatchMode=INSTANTLY, isSticky=false)
For advanced features, please refer to the corresponding test specifications:
- threading (dispatch modes and thread modes)
- event blocking
- event dispatch cancellation
- sticky events
- subscriber priority
- subscriber tag ## Performance There is a sample benchmark code in the repository, you can clone this repository and run the benchmark on your own machine. Here is the benchmark results on my machine:
Conditions\AvgCallTime(ms) | INSTANTLY | SEQUENTIAL | CONCURRENT | ORDERED_CONCURRENT |
---|---|---|---|---|
event-1;subs-10000;tc-false;st-false | 4.28E-05 | 0.00136298 | 0.014001329 | 2.0647497 |
event-1;subs-10000;tc-true;st-false | 10.513036 | 10.69949 | 2.6430638 | 2.8060534 |
event-10000;subs-1;tc-false;st-false | 6.81E-04 | 0.03349961 | 0.01899664 | 0.025285339 |
event-10000;subs-1;tc-true;st-false | 10.477978 | 2.6560345 | 2.6473286 | 2.7563891 |
event-1000;subs-10000;tc-false;st-false | 4.62E-05 | 4.32E-04 | 0.014056747 | 0.00546798 |
event-1;subs-10000;tc-false;st-true | 0.01410701 | |||
event-1;subs-10000;tc-true;st-true | 2.6499982 | |||
event-10000;subs-1;tc-false;st-true | 0.02116017 | |||
event-10000;subs-1;tc-true;st-true | 2.65346 | |||
event-1000;subs-10000;tc-false;st-true | 0.01399993 |
event = event num subs = subscriber num tc = if subscribers are time-consuming (sleep 10ms in the above benchmark) st = if the event is sticky (and subscribers are added after the event was posted)
[Machine Info]
CPU: Intel(R) Core(TM) i5-6500 @ 3.20GHz (4C4T)
Memory: 8 + 4 = 12GB, DDR4 SDRAM, 2133MHz
OS: Window 10 Enterprise 64 bit version 1909
JDK: OpenJDK 14.0.1+7 64 bit
License
KEvent is released under the Apache 2.0 license.
Copyright 2020 RationalityFrontline
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*Note that all licence references and agreements mentioned in the KEvent README section above
are relevant to that project's source code only.