package com.dy.testServer.console;
|
|
import java.io.PrintWriter;
|
import java.net.InetAddress;
|
import java.net.UnknownHostException;
|
import java.util.Iterator;
|
import java.util.Map;
|
import java.util.Set;
|
|
import com.dy.common.mw.channel.rmi.RmiConfigVo;
|
import com.dy.common.mw.channel.rmi.RmiUnit;
|
import com.dy.testServer.ServerProperties;
|
import com.dy.testServer.forRmi.MwTestClientStatus;
|
import com.dy.testServer.forRmi.Manager;
|
|
public class Command {
|
|
private static final String[] commands ;
|
static{
|
commands = new String[]{
|
"config 查看配置信息",
|
"show 显示mwTest情况",
|
"start 启动mwTest上报数据",
|
"exit 退出",
|
};
|
}
|
|
|
public static boolean dealCommand(String command, PrintWriter prtWrt){
|
boolean exit = false ;
|
if (command.equals("help")) {
|
outCommand(prtWrt);
|
} else if (command.equals("config")) {
|
config(prtWrt);
|
} else if (command.equals("show")) {
|
show(prtWrt);
|
} else if (command.equals("start")) {
|
start(prtWrt);
|
} else if(command.equals("exit")){
|
exit = true ;
|
} else {
|
outError(prtWrt);
|
}
|
return exit ;
|
}
|
private static void outCommand(PrintWriter prtWrt){
|
prtWrt.println("");
|
prtWrt.println("命令");
|
for(String s : commands){
|
prtWrt.println(" " + s);
|
}
|
prtWrt.println("");
|
}
|
private static void outError(PrintWriter prtWrt){
|
prtWrt.println("");
|
prtWrt.println("命令不可识别!");
|
prtWrt.println("");
|
}
|
|
private static void config(PrintWriter prtWrt){
|
prtWrt.println("");
|
prtWrt.println("相关mwTest的配置");
|
prtWrt.println(" 模拟客户的RtuAddr起始号:" + ServerProperties.rtuAddrStart);
|
prtWrt.println(" 模拟客户的RtuAddr截止号:" + ServerProperties.rtuAddrEnd);
|
prtWrt.println(" 每个mwTest分配的RtuAddr数:" + ServerProperties.rtuAddrPerMwTest);
|
prtWrt.println(" 通信中间件IP:" + ServerProperties.tcpServerIp);
|
prtWrt.println(" 通信中间件端口:" + ServerProperties.tcpServerPort);
|
prtWrt.println(" mwTest每RtuAddr号发送数据次数:" + ServerProperties.sendTimes);
|
prtWrt.println("本服务RMI Server配置");
|
String ip = null ;
|
try {
|
ip = InetAddress.getLocalHost().getHostAddress();
|
} catch (UnknownHostException e) {
|
e.printStackTrace();
|
}
|
RmiConfigVo confVo = RmiUnit.getInstance().getAdapter().getConfig() ;
|
if(ip != null){
|
prtWrt.println(" RMI Server:" + ip + ":" + confVo.port + "/" + confVo.context);
|
}else{
|
prtWrt.println(" RMI Server:[ip]:" + confVo.port + "/" + confVo.context);
|
}
|
prtWrt.println("");
|
}
|
|
private static void show(PrintWriter prtWrt){
|
prtWrt.println("");
|
prtWrt.println("当前已注册mwTest客户端数量:" + Manager.id2TokenMap.size());
|
if(Manager.id2TokenMap.size() > 0){
|
prtWrt.println("mwTest客户端及其工作信息");
|
Set<Map.Entry<String, MwTestClientStatus>> set = Manager.token2ClientMap.entrySet() ;
|
Iterator<Map.Entry<String, MwTestClientStatus>> it = set.iterator() ;
|
Map.Entry<String, MwTestClientStatus> ent ;
|
while(it.hasNext()){
|
ent = it.next() ;
|
prtWrt.println(" mwTest客户端(token=" + ent.getKey() + ")");
|
MwTestClientStatus sta = ent.getValue() ;
|
if(sta != null){
|
if(sta.confVo != null){
|
prtWrt.println(" rtuAddr范围:" + sta.confVo.rtuAddrStart + "--" + sta.confVo.rtuAddrEnd);
|
}
|
if(sta.startVo != null){
|
prtWrt.println(" 上报数据:" + (sta.startVo.start?"已经开始":"未开始"));
|
}else{
|
prtWrt.println(" 上报数据:未开始") ;
|
}
|
if(sta.count != null){
|
prtWrt.println(" 已经上报数据:" + sta.count + "条");
|
}
|
if(sta.over != null && sta.over){
|
prtWrt.println(" 上报数据已经完成,共用时:" + sta.seconds + "秒");
|
}
|
}
|
}
|
}
|
prtWrt.println("");
|
}
|
|
private static void start(PrintWriter prtWrt){
|
prtWrt.println("");
|
prtWrt.println(" 已经允许mwTest上报数据了");
|
prtWrt.println("");
|
Manager.enablemwTestStart = true ;
|
}
|
|
|
}
|