⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mytest2eventpullsource.java

📁 Java下Comet的实现框架Pushlet例子。 实现实时推送数据到客户端。 服务器每隔30-500MS产生一个随机数
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -