Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 539d8fe

Browse files
authored
Merge pull request #23 from SLNE-Development/19-improve-packet-listener-performance
refactor: simplify Netty listener registration and update NettyPacket…
2 parents c423525 + 804a77a commit 539d8fe

File tree

6 files changed

+28
-665
lines changed

6 files changed

+28
-665
lines changed

surf-cloud-api/surf-cloud-api-common/api/surf-cloud-api-common.api

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ public abstract interface annotation class dev/slne/surf/cloud/api/common/meta/S
254254
}
255255

256256
public abstract interface annotation class dev/slne/surf/cloud/api/common/meta/SurfNettyPacketHandler : java/lang/annotation/Annotation {
257-
public abstract fun classes ()[Ljava/lang/Class;
258-
public abstract fun condition ()Ljava/lang/String;
259257
public abstract fun id ()Ljava/lang/String;
260-
public abstract fun value ()[Ljava/lang/Class;
261258
}
262259

263260
public abstract interface class dev/slne/surf/cloud/api/common/netty/NettyClient {
@@ -1237,17 +1234,14 @@ public final class dev/slne/surf/cloud/api/common/netty/packet/NettyPacket$Compa
12371234
}
12381235

12391236
public final class dev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo {
1240-
public static final synthetic fun box-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
1241-
public static fun constructor-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/network/Connection;
1237+
public fun <init> (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)V
1238+
public final fun component1 ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
1239+
public final fun copy (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
1240+
public static synthetic fun copy$default (Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;Ldev/slne/surf/cloud/api/common/netty/network/Connection;ILjava/lang/Object;)Ldev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo;
12421241
public fun equals (Ljava/lang/Object;)Z
1243-
public static fun equals-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;Ljava/lang/Object;)Z
1244-
public static final fun equals-impl0 (Ldev/slne/surf/cloud/api/common/netty/network/Connection;Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Z
12451242
public final fun getOrigin ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
12461243
public fun hashCode ()I
1247-
public static fun hashCode-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)I
12481244
public fun toString ()Ljava/lang/String;
1249-
public static fun toString-impl (Ldev/slne/surf/cloud/api/common/netty/network/Connection;)Ljava/lang/String;
1250-
public final synthetic fun unbox-impl ()Ldev/slne/surf/cloud/api/common/netty/network/Connection;
12511245
}
12521246

12531247
public final class dev/slne/surf/cloud/api/common/netty/packet/Packet_extensionKt {

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/meta/SurfNettyPacketHandler.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package dev.slne.surf.cloud.api.common.meta
22

33
import org.springframework.aot.hint.annotation.Reflective
4-
import org.springframework.core.annotation.AliasFor
5-
import kotlin.reflect.KClass
64

75
/**
86
* Annotation for marking methods in a component as packet handlers.
@@ -17,8 +15,5 @@ import kotlin.reflect.KClass
1715
)
1816
@Reflective
1917
annotation class SurfNettyPacketHandler(
20-
@get:AliasFor("classes") val value: Array<KClass<*>> = [],
21-
@get:AliasFor("values") val classes: Array<KClass<*>> = [],
22-
val condition: String = "",
2318
val id: String = ""
2419
)

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/packet/NettyPacketInfo.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package dev.slne.surf.cloud.api.common.netty.packet
22

33
import dev.slne.surf.cloud.api.common.netty.network.Connection
44

5-
@JvmInline
6-
value class NettyPacketInfo(val origin: Connection)
5+
data class NettyPacketInfo(val origin: Connection)

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/registry/listener/NettyListenerRegistry.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import dev.slne.surf.cloud.api.common.netty.packet.NettyPacketInfo
66
import dev.slne.surf.cloud.api.common.util.isSuspending
77
import dev.slne.surf.cloud.api.common.util.mutableObject2ObjectMapOf
88
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
9-
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
109
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
1110
import it.unimi.dsi.fastutil.objects.ObjectSet
1211
import java.lang.reflect.Method
1312
import java.lang.reflect.Modifier
1413
import kotlin.coroutines.Continuation
15-
import kotlin.jvm.java
16-
import kotlin.reflect.jvm.kotlinFunction
1714

1815
object NettyListenerRegistry {
1916
private val listeners =

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/registry/listener/RegisteredListener.kt

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package dev.slne.surf.cloud.core.common.netty.registry.listener
33
import dev.slne.surf.cloud.api.common.netty.exception.SurfNettyListenerRegistrationException
44
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
55
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacketInfo
6-
import kotlinx.coroutines.Dispatchers
7-
import kotlinx.coroutines.withContext
86
import tech.hiddenproject.aide.reflection.LambdaWrapperHolder
97
import tech.hiddenproject.aide.reflection.annotation.Invoker
108
import java.lang.reflect.Method
@@ -49,35 +47,32 @@ class RegisteredListener(
4947
}
5048
}
5149

52-
suspend fun handle(packet: NettyPacket, info: NettyPacketInfo) =
53-
withContext(Dispatchers.IO) {
54-
when (invokerType) {
55-
InvokerType.ONE_PARAM -> {
56-
if (suspending) {
57-
(invoker as RegisteredListenerSuspendInvoker1).handle(bean, packet)
58-
} else {
59-
(invoker as RegisteredListenerInvoker1).handle(bean, packet)
60-
}
61-
}
62-
63-
InvokerType.TWO_PARAMS -> {
64-
if (suspending) {
65-
(invoker as RegisteredListenerSuspendInvoker2).handle(bean, packet, info)
66-
} else {
67-
(invoker as RegisteredListenerInvoker2).handle(bean, packet, info)
68-
}
69-
}
70-
71-
InvokerType.TWO_PARAMS_REVERSED -> {
72-
if (suspending) {
73-
(invoker as RegisteredListenerSuspendInvoker2Rev).handle(bean, info, packet)
74-
} else {
75-
(invoker as RegisteredListenerInvoker2Rev).handle(bean, info, packet)
76-
}
77-
}
50+
suspend fun handle(packet: NettyPacket, info: NettyPacketInfo) = when (invokerType) {
51+
InvokerType.ONE_PARAM -> {
52+
if (suspending) {
53+
(invoker as RegisteredListenerSuspendInvoker1).handle(bean, packet)
54+
} else {
55+
(invoker as RegisteredListenerInvoker1).handle(bean, packet)
56+
}
57+
}
58+
59+
InvokerType.TWO_PARAMS -> {
60+
if (suspending) {
61+
(invoker as RegisteredListenerSuspendInvoker2).handle(bean, packet, info)
62+
} else {
63+
(invoker as RegisteredListenerInvoker2).handle(bean, packet, info)
7864
}
7965
}
8066

67+
InvokerType.TWO_PARAMS_REVERSED -> {
68+
if (suspending) {
69+
(invoker as RegisteredListenerSuspendInvoker2Rev).handle(bean, info, packet)
70+
} else {
71+
(invoker as RegisteredListenerInvoker2Rev).handle(bean, info, packet)
72+
}
73+
}
74+
}
75+
8176
private enum class InvokerType {
8277
ONE_PARAM,
8378
TWO_PARAMS,

0 commit comments

Comments
 (0)