183 Star 1.7K Fork 511

渔民小镇 / ioGame

 / 详情

EndPointLogicServerMessage 异常

已完成
创建于  
2022-08-04 17:02

在 给玩家动态绑定逻辑服节点 时 会抛出异常,代码如下:

  // 绑定消息
        EndPointLogicServerMessage endPointLogicServerMessage = new EndPointLogicServerMessage()
                // 需要绑定的玩家,示例中只取了当前请求匹配的玩家
                .setUserList(userIdList)
                // 需要绑定的逻辑服id
                .setLogicServerId(logicServerId)
                // true 为绑定,false 为取消绑定
                .setBinding(true);

        // 发送消息到网关
        ProcessorContext processorContext = BrokerClientHelper.me().getProcessorContext();
        processorContext.invokeOneway(endPointLogicServerMessage);

异常信息:


com.alipay.remoting.exception.SerializationException: Exception caught when serialize content of rpc request command!
	at com.alipay.remoting.rpc.protocol.RpcRequestCommand.serializeContent(RpcRequestCommand.java:137) ~[bolt-1.6.5.jar:na]
	at com.alipay.remoting.rpc.RpcCommand.serialize(RpcCommand.java:105) ~[bolt-1.6.5.jar:na]
	at com.alipay.remoting.rpc.RpcRemoting.toRemotingCommand(RpcRemoting.java:353) ~[bolt-1.6.5.jar:na]
	at com.alipay.remoting.rpc.RpcRemoting.oneway(RpcRemoting.java:119) ~[bolt-1.6.5.jar:na]
	at com.alipay.remoting.rpc.RpcClient.oneway(RpcClient.java:204) ~[bolt-1.6.5.jar:na]
	at com.iohao.game.bolt.broker.core.client.BrokerClientItem.internalOneway(BrokerClientItem.java:253) ~[bolt-core-17.1.8.jar:na]
	at com.iohao.game.bolt.broker.core.client.BrokerClientItem.invokeOneway(BrokerClientItem.java:214) ~[bolt-core-17.1.8.jar:na]
.......
 **Caused by: java.lang.RuntimeException: Unable to make field private final java.lang.Object[] java.util.ImmutableCollections$ListN.elements accessible: module java.base does not "opens java.util" to unnamed module @7530ad9c** 
 field: com.iohao.game.action.skeleton.protocol.processor.EndPointLogicServerMessage.userList
 class: com.iohao.game.action.skeleton.protocol.processor.EndPointLogicServerMessage (object=EndPointLogicServerMessage(logicServerId=2_1, userList=[1], binding=true))
	........

临时解决方法:
添加 jvm 启动参数:
--add-opens java.base/java.util=ALL-UNNAMED

评论 (7)

shenjk 创建了任务
渔民小镇 添加了
 
提问与交流
标签
展开全部操作日志

看异常信息好像是 userIdList 不支持序列化。

把 userIdList 转为 ArrayList 试下。


类似如下代码

xxxList.stream()
        // 这种是不支持序列化的
        .toList();

xxxList.stream()
        // 支持序列化的
        .collect(Collectors.toList());

:+1: 确实是这样的

通过EndPointLogicServerMessage 动态判断逻辑服务了以后,有什么方法可以获取某个逻辑服务已绑定的用户呢?
以及如何根据userId查询用户被绑定到了哪个逻辑服务呢?

通过EndPointLogicServerMessage 动态判断逻辑服务了以后,有什么方法可以获取某个逻辑服务已绑定的用户呢?
以及如何根据userId查询用户被绑定到了哪个逻辑服务呢?

有多种方式:

  1. 通过第三方产品,如redis,sql 等,开发者自己维护一下。
  2. 通过 ExternalBizRegion 扩展

ExternalBizRegion 接口,对外服业务扩展;开发者可以通过实现这个接口,向游戏逻辑服提供一些,如

  1. 只存在于游戏对外服中的数据
  2. 只有游戏对外服可以做的事

ExternalBizRegion 扩展可以参考:
https://www.yuque.com/iohao/game/ivxsw5


UserSessionAttr.endPointLogicServerId 是保存玩家绑定逻辑服的属性。

通过扩展ExternalBizRegion 可以获取用户在哪个逻辑服,不过由于获取的logicServerId的hash值,在业务中使用比较麻烦,最后还是选择通过redis或sql来维护,也能实现更多业务场景

shenjk 任务状态待办的 修改为已完成

如果需要保存 logicServerId , 也可以通过 ExternalBizRegion 接口来实现;
放到 UserSession 的扩展属性中保存一下,之后可以使用 元信息扩展 attachmentData 来传递到游戏逻辑服中。

参考:
https://gitee.com/iohao/iogame/issues/I5J96X

看情况吧,怎么方便怎么来都行。

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
5475 iohao 1653332816
Java
1
https://gitee.com/iohao/ioGame.git
git@gitee.com:iohao/ioGame.git
iohao
ioGame
ioGame

搜索帮助