📄 activetestthread.java
字号:
package com.ut.smgp.api.thread;
import com.ut.smgp.api.structure.*;
import com.ut.smgp.api.logic.*;
import com.ut.smgp.api.configure.*;
import com.ut.smgp.api.*;
import java.net.*;
import java.util.*;
public class activeTestThread extends Thread{
private int cycle=0;
private socketStruct socket=null;
socketLogic send=new socketLogic();
initStruct init=new initStruct();
private int ctl=0;
private int timeout=0;
private deliverVector deliverQueue;
private int type;
/*************************************************************************
* cycle unit: second
*
*/
public activeTestThread(socketStruct socket,initStruct init,deliverVector deliverQueue,int type)
{
this.cycle=init.getActiveTestCycle();
this.socket=socket;
this.init=init;
this.deliverQueue=deliverQueue;
this.type=type;
}
/*************************************************************************
*
* 获取通讯连接
*
*/
public socketStruct getConnection()
{
return socket;
}
/*********************************************************************
*
* 设置通信端口
*/
public void setSocket(socketStruct socket)
{
this.socket=socket;
}
/*******************************************************
*
* 发送控制变量
*
*/
public void setCtl(int ctl)
{
this.ctl=ctl;
}
public void run()
{
for(;;)
{
if(ctl==1) break;
if(send.activeTest(socket,1,configure.SOCKET_SO_TIMEOUT,deliverQueue,type)!=0)
{//发送失败
int result=1;
for(int i=0;i<configure.ACTIVE_TEST_RETRY-1;i++)
if(send.activeTest(socket,1,configure.SOCKET_SO_TIMEOUT,deliverQueue,type)==0)
{
result=0;
break;
}
if(result==1)
{//发送重试失败,重新建立连接*/
smgpLogic smgp = new smgpLogic();
try {
socket.socket = new Socket(init.getServerIp(), init.getServerPort());
socket.socket.setSoTimeout(configure.SOCKET_SO_TIMEOUT);
}
catch (Exception e) {
System.out.println("activeTestThread:" + e);
}
smgp.login(init, socket);
}
}
try{
Thread.sleep( (long)cycle);
}catch(InterruptedException e)
{System.out.println("activeTestThread:"+e);}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -