在 给玩家动态绑定逻辑服节点 时 会抛出异常,代码如下:
// 绑定消息
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
看异常信息好像是 userIdList 不支持序列化。
把 userIdList 转为 ArrayList 试下。
类似如下代码
xxxList.stream()
// 这种是不支持序列化的
.toList();
xxxList.stream()
// 支持序列化的
.collect(Collectors.toList());
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
通过EndPointLogicServerMessage
动态判断逻辑服务了以后,有什么方法可以获取某个逻辑服务已绑定的用户呢?
以及如何根据userId查询用户被绑定到了哪个逻辑服务呢?
通过EndPointLogicServerMessage 动态判断逻辑服务了以后,有什么方法可以获取某个逻辑服务已绑定的用户呢?
以及如何根据userId查询用户被绑定到了哪个逻辑服务呢?
有多种方式:
ExternalBizRegion 接口,对外服业务扩展;开发者可以通过实现这个接口,向游戏逻辑服提供一些,如
ExternalBizRegion 扩展可以参考:
https://www.yuque.com/iohao/game/ivxsw5
UserSessionAttr.endPointLogicServerId 是保存玩家绑定逻辑服的属性。
如果需要保存 logicServerId , 也可以通过 ExternalBizRegion 接口来实现;
放到 UserSession 的扩展属性中保存一下,之后可以使用 元信息扩展 attachmentData 来传递到游戏逻辑服中。
看情况吧,怎么方便怎么来都行。
登录 后才可以发表评论