📄 mytest.java
字号:
package nl.justobjects.pushlet.test;
import java.util.Date;
import nl.justobjects.pushlet.client.PushletClient;
import nl.justobjects.pushlet.client.PushletClientListener;
import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.Protocol;
import nl.justobjects.pushlet.util.PushletException;
public class MyTest implements PushletClientListener, Protocol {
private static String SUBJECT = "/stocks/aexonlinewispy";
private static final String MODE = MODE_STREAM;
public static long maxWaitTime = 0;
public static long minWaitTime = 5000;
public static int maxWaitNo = 0;
public static int minWaitNo = 0;
public static int below200 = 0;
public static int b200to400 = 0;
public static int b400to600 = 0;
public static int b600to800 = 0;
public static int b800to1000 = 0;
public static int b1000to1200 = 0;
public static int b1200to1400 = 0;
public static int b1400to1600 = 0;
public static int b1600to1800 = 0;
public static int b1800to2000 = 0;
public static int b2000to2400 = 0;
public static int b2400to2800 = 0;
public static int b2800to3200 = 0;
public static int up3200 = 0;
public static int unkind = 0;
public static long totalWaitTime = 0;
public static long totalRunTimes = 0;
public MyTest(String aHost, int aPort) {
// Create and start a Pushlet client; we receive callbacks
// through onHeartbeat() and onData().
try {
PushletClient pushletClient = new PushletClient(aHost, aPort);
pushletClient.setDebug(true);
pushletClient.join();
pushletClient.listen(this, MODE, SUBJECT);
// pushletClient.joinListen(this, MODE, SUBJECT);
System.out.println("here pushletClient started");
p("pushletClient started MyTest");
} catch (PushletException pe) {
p("Error in setting up pushlet session pe=" + pe);
}
}
/** Error occurred. */
public void onError(String message) {
p("onAbort onError: " + message);
}
/** Abort event from server. */
public void onAbort(Event theEvent) {
p("onAbort received: " + theEvent.toString());
}
/** Data event from server. */
public void onData(Event theEvent) {
// Calculate round trip delay
//p("theEvent.toXML() : " + theEvent.toXML());
// p("here is the city :" + theEvent.getField("city"));
p("name : " + theEvent.getField("name"));
p("rate : " + theEvent.getField("rate"));
Date now = new Date();
Date date = new Date(theEvent.getField("time"));
//----------------------------------------------------------
long time = now.getTime() - date.getTime();
totalWaitTime += time;
//条件表达式的执行顺序为:先求解表达式1,若值为非0,表示条件为真,则求解表达式2,此时表达式2的值就作为整个条件表达式的值;
//若表达式1的值为0,表示条件为假,则求解表达式3,表达式3的值就是整个条件表达式的值
minWaitTime = (minWaitTime < time) ? minWaitTime : time;
maxWaitTime = (maxWaitTime < time) ? time : maxWaitTime;
if(maxWaitTime <= time){
maxWaitNo = new Integer(theEvent.getField("rate"));
}
if(minWaitTime >= time){
minWaitNo = new Integer(theEvent.getField("rate"));
}
p("延时时间 : " + time + "毫秒。");
if (time > 2000){
p("------------------------奇了-- >2000 max ----------------------------");
p("time : " + theEvent.getField("time"));
p("now : " + now.toString());
}
if (time <200){
p("------------------------奇了--- <200 min ---------------------------");
p("time : " + theEvent.getField("time"));
p("now : " + now.toString());
}
int sw = (int)time/200;
switch (sw) {
case 0:
below200++;
break;
case 1:
b200to400++;
break;
case 2:
b400to600++;
break;
case 3:
b600to800++;
break;
case 4:
b800to1000++;
break;
case 5:
b1000to1200++;
break;
case 6:
b1200to1400++;
break;
case 7:
b1400to1600++;
break;
case 8:
b1600to1800++;
break;
case 9:
b1800to2000++;
break;
case 10:
b2000to2400++;
break;
case 11:
b2000to2400++;
break;
case 12:
b2400to2800++;
break;
case 13:
b2400to2800++;
break;
case 14:
b2800to3200++;
break;
case 15:
b2800to3200++;
break;
case 16:
up3200++;
break;
default:
unkind++;
break;
}
// p("here is the EPCCode :" + theEvent.getField("epc"));
// p("p_event :" + theEvent.getField("p_event"));
// p("p_time : " + theEvent.getField("p_time"));
// p("p_from : " + theEvent.getField("p_from"));
// p("p_mode : " + theEvent.getField("p_mode"));
showSummery();
}
private void showSummery() {
System.out.println();
//每10次输出一下统计信息
totalRunTimes++;
if(totalRunTimes % 23 == 0){
p(" ");
p(" ");
p("--------------哇咔咔 统计信息开始----------- ");
p("总共获取调用了多少次 : " + totalRunTimes + "次");
p("最大延时时间 : " + maxWaitTime + "毫秒");
p("最大延迟产生的rate : " + maxWaitNo);
p("最小延时时间 : " + minWaitTime + "毫秒");
p("最小延迟产生的rate : " + minWaitNo);
p("平均延时时间 : " + totalWaitTime/totalRunTimes + "毫秒");
p(" ");
p("200以下出现次数 :" + below200);
p("200-400出现次数 :" + b200to400);
p("400-600出现次数 :" + b400to600);
p("600-800出现次数 :" + b600to800);
p("800-1000出现次数 :" + b800to1000);
p("1000-1200出现次数 :" + b1000to1200);
p("1200-1400出现次数 :" + b1200to1400);
p("1400-1600出现次数 :" + b1400to1600);
p("1600-1800出现次数 :" + b1600to1800);
p("1800-2000出现次数 :" + b1800to2000);
p("2000-2400出现次数 :" + b2000to2400);
p("2400-2800出现次数 :" + b2400to2800);
p("2800-3200出现次数 :" + b2800to3200);
p("3200以上出现次数 :" + up3200);
p("未能统计的次数 :" + unkind);
p(" ");
p(" ");
System.out.println();
}
}
/** Heartbeat event from server. */
public void onHeartbeat(Event theEvent) {
p("onHeartbeat received: " + theEvent.toString());
}
/** Generic print. */
public static void p(String s) {
System.out.println("[MyTest] " + s);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
new MyTest("localhost", 8080);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -