mytest2eventpullsource.java
来自「Java下Comet的实现框架Pushlet例子。 实现实时推送数据到客户端。」· Java 代码 · 共 39 行
JAVA
39 行
package nl.justobjects.pushlet.test;
import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.EventPullSource;
import nl.justobjects.pushlet.util.Rand;
public class MyTest2EventPullSource {
public static class wyyCityPullSource extends EventPullSource {
static String[] cities = { "222222city1", null, "222222city2", null,
"22222city3", null, "22222city4", null, "222222city5", null };
@Override
protected long getSleepTime() {
return Rand.randomLong(0, 3000);
}
@Override
protected Event pullEvent() {
int cityNumber = Rand.randomInt(0, (cities.length) / 2 - 1);
int nextCityIndex = 2 * cityNumber;
Event event = Event.createDataEvent("/mytest");
event.setField("number", "" + cityNumber);
event.setField("city", cities[nextCityIndex]);
if (cities[nextCityIndex + 1] == null) {
cities[nextCityIndex + 1] = "" + Rand.randomInt(5, 10);
}
int currentCityValue = new Integer(cities[nextCityIndex + 1])
.intValue();
int newCityValue = currentCityValue + Rand.randomInt(-2, 2);
event.setField("value", "" + newCityValue);
return event;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?