- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
好吧,也许没有损坏。
那么,一些背景知识。我最近将我的 Red5 驱动的游戏从 red5 的 Windows 构建转移到在 Debian Squeeze 上运行的游戏。我有一个游戏大厅,它使用共享对象来维护各种可用游戏的列表。
单个游戏在所述 SharedObject 中存储为 HashMap[String, Object],与它的 game_id 相对应。 HashMap 的几个属性是 ArrayLists,特别是 players(连接的玩家 ID 的 ArrayList[Integer])和 votes(另一个 ArrayList[Integer] 的玩家)提交了投票)
每当我对这些 ArrayList 中的任何一个进行更改时,某处就会出错,我无法再将 HashMap 写入 SharedObject(setAttribute 返回 false)
创建新游戏(服务器端):
HashMap<String, Object> game = new HashMap<String, Object>();
game.put("id", PendingGameManager.GAME_IDX);
game.put("difficulty", difficulty);
game.put("type", type);
game.put("description", this.getDescription(type, difficulty));
game.put("players", new ArrayList<Integer>());
game.put("coords", coords);
game.put("created", Calendar.getInstance().getTimeInMillis());
game.put("votes", new ArrayList<Integer>());
boolean success = this.gamesSO.setAttribute(Integer.toString(PendingGameManager.GAME_IDX), game);
这执行没有问题,成功返回真。
稍后我检索播放器数组并进行修改:
HashMap<String, Object> game = (HashMap<String, Object>)this.gamesSO.getMapAttribute(Integer.toString(game_id));
ArrayList<Integer> players = (ArrayList<Integer>) game.get("players");
players.add(new Integer(Integer.parseInt((user_id))));
boolean success = this.gamesSO.setAttribute(Integer.toString(game_id), game);
这里成功总是返回false。如果为游戏创建一个新的 HashMap 并从旧的 HashMap 复制每个属性但省略 players 和 votes 这很好,但无论尝试什么,我都无法得到它维护一个数组。我也用 List 和 Vector 尝试过,结果相同。这是我第一次接触 Java,我一直小心翼翼地只添加 Integer 的类实例,而不是原始 int,但为了我所有的努力,我已经没有想法了。
当它在 Windows 上运行完美时,我最初的实现使用 ArrayList[String] 而不是 ArrayList[Integer]
环境:Debian 压缩版 6.0.6jre 1.7Red5 1.0RC2
如有任何帮助或建议,我们将不胜感激!
最佳答案
根据您的 red5 版本信息,这是方法“setAttribute”的实现:
@Override
public boolean setAttribute(String name, Object value) {
log.debug("setAttribute - name: {} value: {}", name, value);
boolean result = true;
ownerMessage.addEvent(Type.CLIENT_UPDATE_ATTRIBUTE, name, null);
if (value == null && super.removeAttribute(name)) {
// Setting a null value removes the attribute
modified = true;
syncEvents.add(new SharedObjectEvent(Type.CLIENT_DELETE_DATA, name, null));
deleteStats.incrementAndGet();
} else if (value != null && super.setAttribute(name, value)) {
// only sync if the attribute changed
modified = true;
syncEvents.add(new SharedObjectEvent(Type.CLIENT_UPDATE_DATA, name, value));
changeStats.incrementAndGet();
} else {
result = false;
}
notifyModified();
return result;
}
我猜值是 != null(但我可能错了)。但在我看来,它会通过“super.setAttribute”调用将该调用转发给它的父类,这是父类/父类(super class)的实现:
/**
* Set an attribute on this object.
*
* @param name the name of the attribute to change
* @param value the new value of the attribute
* @return true if the attribute value was added or changed, otherwise false
*/
public boolean setAttribute(String name, Object value) {
if (name != null) {
if (value != null) {
// update with new value
Object previous = attributes.put(name, value);
// previous will be null if the attribute didn't exist
return (previous == null || !value.equals(previous));
}
}
return false;
}
这里重要的一行(恕我直言):
return (previous == null || !value.equals(previous));
=> "previous"找不到,然后返回false。
问题是我认为:你正在做的这个转换:
HashMap<String, Object> game = (HashMap<String, Object>)this.gamesSO.getMapAttribute(Integer.toString(game_id));
我不认为“this.gamesSO.getMapAttribute(Integer.toString(game_id));”会返回HashMap,我想我还记得Red5有自己的Map类型。
如果你只是调试并添加一个:
System.out.println(this.gamesSO.getMapAttribute(Integer.toString(game_id)));
和/或添加一些调试断点并验证这是什么类型。然后真的投到这个。
我认为您还应该将 map 指定得更详细。像这样的东西:
HashMap<String, MyPlayerBean>
然后创建一个 MyPlayerBean 类,其中包含您真正需要的属性。制作这些 Map/List 对象可能有助于快速入门,但如果您的应用程序开始增长,它可能会变得非常难看。
塞巴斯蒂安
关于java - Red5 - SharedObject 中的 ArrayList 被损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12899224/
在我输入的 javascript 控制台中/(red|green)/g.exec('红绿红绿') 它返回一个包含两个结果的数组:[“红色”,“红色”] 它不应该返回一个包含 4 个结果的数组吗?如:[
所以我目前正在将一个下降大小的程序从 Rebol 3 迁移到 Red。所述程序依赖于与 C 库 (clang) 的大型绑定(bind)。我已经重写了 Red/System 中的绑定(bind)部分,并
是否可以在节点集群上水平扩展 Node-RED? 找不到任何文档。我的场景是每秒处理数百万个事件并使用 Node-RED 实时处理它们。 最佳答案 我在 Google Groups Node-RED
因此,在尝试在 Red 和 Red/System 之间来回编码值时出现了问题。我想访问传递给例程的对象的内脏。 我注意到 Red Runtime 中有一些函数可以在对象上下文中处理诸如此类、get-v
假设我正在使用 MQTT 协议(protocol)从许多设备接收信息,下图是一个设备 block 的简化版本: 因此,我们还假设所有其他设备具有完全相同的图表,除了将更改为 device2 的主题名称
想象一下我已经连接了一个流程,如下所示: 现在希望重新连接到: 看来我的选择是删除现有的电线,然后重新连接它们。我的问题是: 问题 是否可以将连线从一个节点移动到另一个节点,而不是删除和重新创建? 最
有没有办法将现有的 Node-RED 流文件 myflow.json 部署到运行 Node-RED 的远程计算机? 经过多次谷歌搜索,我偶然发现了this discussion在相关的Google群组
我想了解下例中WPF是如何将字符串值(Red)转换成对应的SolidColorBrush的? 我们如何对自定义 DependencyProperty 做同样的事情? 最佳答案 从字符串到 Brush
我想了解下例中WPF是如何将字符串值(Red)转换成对应的SolidColorBrush的? 我们如何对自定义 DependencyProperty 做同样的事情? 最佳答案 从字符串到 Brush
我想合并来自 3 个不同来源的数据(来自 HTTP msg.payload)。 但是,这些 HTTP 请求可能会被多次调用,因此可以多次接收来自同一源的数据。 [{"id":"7ed13b41.131
我需要 Accel 对象作为有效负载对象的一部分: msg.payload.Accel.x : 1 msg.payload.Accel.y : 2 msg.payload.Accel.z : 3 如何
我正在尝试在 Node-RED 中执行简单的 http get 请求。根据在线文档,我必须传递函数中的参数作为 http 请求节点的输入。我的函数如下所示; msg.url = "https://ap
我有一个简单的 php 页面,它输出一个表(已动态创建)。 页面上的文本都是红色标记的,除非你专门放置一个font color元素并强制它变成黑色。 我使用的是 FF 并安装了 Firebug,所以我
setXxx(Color.red) 和 setXxx(Color.RED) 的定义之间的真正区别是什么? 我在网上找到了以下解释。都是关于命名约定的吗? Java originally defined
我正在使用具有以下内容的 Dockerfile,我在树莓派上使用 resin.io 进行部署。 FROM nodered/node-red-docker:rpi-v8 USER root RUN su
这个问题已经有答案了: Difference between Color.red and Color.RED (3 个回答) 已关闭 9 年前。 Color.RED 之间有什么区别吗?变量和 Colo
我可能是盲人,但我找不到我在许多节点实现中看到的功能的文档,因为有: RED.nodes.createNode() RED.nodes.getNode() RED.nodes.eachNode() R
$('#toggle-linecolor').click(function () { chart.yAxis[0].update({ lineColor: li
我用了this GitHub 存储库,用于使用 Electron 创建 Node-Red 桌面应用程序。 现在我想使用 node-red-admin 向这个应用程序添加身份验证。我怎样才能做到这一点?
两种方法都有效吗?两者都一样。 border:2px solid red; 和 border:2px red solid; 最佳答案 W3.org (官方规范)说 border 简写属性的值是这样的:
我是一名优秀的程序员,十分优秀!