diff --git a/net/src/main/java/com/zfoo/net/router/attachment/SignalAttachment.java b/net/src/main/java/com/zfoo/net/router/attachment/SignalAttachment.java index 7de58db3..d4c9e457 100644 --- a/net/src/main/java/com/zfoo/net/router/attachment/SignalAttachment.java +++ b/net/src/main/java/com/zfoo/net/router/attachment/SignalAttachment.java @@ -26,6 +26,10 @@ public class SignalAttachment implements IAttachment { public static final short PROTOCOL_ID = 0; + /** + * EN:Negative signalId are allowed + * CN:允许负数的signalId + */ public static final AtomicInteger ATOMIC_ID = new AtomicInteger(0); /** diff --git a/net/src/main/java/com/zfoo/net/session/Session.java b/net/src/main/java/com/zfoo/net/session/Session.java index bcbdd2fb..0e4226b5 100644 --- a/net/src/main/java/com/zfoo/net/session/Session.java +++ b/net/src/main/java/com/zfoo/net/session/Session.java @@ -28,9 +28,9 @@ public class Session implements Closeable { private static final AtomicLong ATOMIC_LONG = new AtomicLong(0); /** - * The globally unique ID of the session + * The globally unique ID of the session and the negative sid are allowed */ - private long sid; + private long sid = ATOMIC_LONG.incrementAndGet(); private Channel channel; @@ -52,10 +52,6 @@ public class Session implements Closeable { if (channel == null) { throw new IllegalArgumentException("channel cannot be empty"); } - this.sid = ATOMIC_LONG.incrementAndGet(); - if (this.sid <= 0) { - throw new IllegalArgumentException("sid cannot be 0"); - } this.channel = channel; } @@ -91,10 +87,6 @@ public class Session implements Closeable { return sid; } - public void setSid(long sid) { - this.sid = sid; - } - public Channel getChannel() { return channel; } diff --git a/net/src/main/java/com/zfoo/net/session/SessionManager.java b/net/src/main/java/com/zfoo/net/session/SessionManager.java index 3cf4bf0f..57d7b965 100644 --- a/net/src/main/java/com/zfoo/net/session/SessionManager.java +++ b/net/src/main/java/com/zfoo/net/session/SessionManager.java @@ -68,8 +68,8 @@ public class SessionManager implements ISessionManager { } @Override - public Session getServerSession(long id) { - return serverSessionMap.get(id); + public Session getServerSession(long sid) { + return serverSessionMap.get(sid); } @Override @@ -105,8 +105,8 @@ public class SessionManager implements ISessionManager { } @Override - public Session getClientSession(long id) { - return clientSessionMap.get(id); + public Session getClientSession(long sid) { + return clientSessionMap.get(sid); } @Override diff --git a/protocol/src/main/java/com/zfoo/protocol/util/ReflectionUtils.java b/protocol/src/main/java/com/zfoo/protocol/util/ReflectionUtils.java index 009b9d25..3191f494 100644 --- a/protocol/src/main/java/com/zfoo/protocol/util/ReflectionUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/util/ReflectionUtils.java @@ -330,7 +330,7 @@ public abstract class ReflectionUtils { var methodName = "get" + StringUtils.capitalize(fieldName); try { - clazz.getDeclaredMethod(methodName, null); + clazz.getDeclaredMethod(methodName); return methodName; } catch (NoSuchMethodException e) { // java的get方法对boolean值有可能对应get或者is,所以尝试获取两种不同的get方法,当两种都获取不到才抛异常 @@ -340,14 +340,14 @@ public abstract class ReflectionUtils { // 如果属性名以大写字母开头,属性名直接用作 getter/setter 方法中 get/set 的后部分。例如属性名为Name,对应的方法是getName/setName。 methodName = "get" + fieldName; try { - clazz.getDeclaredMethod(methodName, null); + clazz.getDeclaredMethod(methodName); return methodName; } catch (NoSuchMethodException e) { } methodName = "is" + StringUtils.capitalize(fieldName); try { - clazz.getDeclaredMethod(methodName, null); + clazz.getDeclaredMethod(methodName); return methodName; } catch (NoSuchMethodException e) { throw new RunException("field:[{}] has no getMethod or isMethod in class:[{}]", field.getName(), clazz.getCanonicalName());