public String controlDoor(final String siteId,String order,final String shutdown,final String loginId,final String ip) throws NumberFormatException, UnknownHostException, IOException{
if(ip.equals(null) || order.equals(null)){
log.info("ip地址、设备id、命令不能为空");
return null;
}
Socket socket = null;
try {
socket = new Socket(ip,Integer.valueOf(Constants.DBMAP.get("WS_DOORLOCK_PORT")));
} catch (Exception e) {
log.info("***********连接失败*************"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
return "fail";
}
log.info("***********连接已经成功*************"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
DataInputStream dis = new DataInputStream(socket.getInputStream());
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
// 执行开门动作
String result = openDoor(siteId, order, loginId, ip, socket, dis, dos);
// 开门成功
if("true".equals(result))
{
Timer timer = new Timer();
// 当开门成功6s后 自动关门
timer.schedule(new TimerTask() {
@Override
public void run() {
String flagString = "false";
Socket socket = null;
DataInputStream dis = null;
DataOutputStream dos = null;
try
{
socket = new Socket(ip,Integer.valueOf(Constants.DBMAP.get("WS_DOORLOCK_PORT")));
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
flagString =closeDoor(siteId, shutdown,loginId, ip, dis, dos, socket);
}
catch (UnknownHostException e)
{
log.error("第1次关门失败!!");
e.printStackTrace();
}
catch (IOException e)
{
log.error("第1次关门失败!!");
e.printStackTrace();
}
finally
{
// 如果关门失败 则启动保护线程 继续执行关门动作
if ("false".equals(flagString)||flagString.endsWith("false"))
{
TimeoutThread time = new TimeoutThread(2000,dis);
for(int i=1;i<5;i++)
{
try
{
Thread.sleep(400);
} catch (InterruptedException e)
{
e.printStackTrace();
}
if ("false".equals(flagString)||flagString.endsWith("false"))
{
try
{
socket = new Socket(ip,Integer.valueOf(Constants.DBMAP.get("WS_DOORLOCK_PORT")));
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
flagString = closeDoor(siteId, shutdown,loginId, ip, dis, dos, socket);
if ("false".equals(flagString)||flagString.endsWith("false"))
log.error("第"+(i+1)+"次关门失败!!");
}
catch (NumberFormatException e)
{
flagString = "false";
详细解决方案
Cannot refer to a non-final variable result inside an inner class
热度:425 发布时间:2016-04-21 23:10:41.0
相关解决方案
- Class not found: com.mchange.v2.c3p0.ComboPooledDataSource,该怎么处理
- org.apache.jasper.JasperException: Unable to compile class for JSP:该怎么解决
- org.apache.jasper.JasperException: Unable to compile class for JSP:解决思路
- !使用JDNI时,报 Cannot create JDBC driver of class '' for connect URL 'null'
- Unable to load class for JSP,该如何处理
- 新手Dialect class not found
- 警告: Could not find action or result 什么原因?该如何解决
- Caused by: org.hibernate.MappingException: Association references un地图ped class: com.elone.pm.product.dao.TAttribute
- strust2 No result defined for action and result input有关问题
- 关于Struts2 jQuery Plugin的 Result,该如何处理
- Error creating bean with name 'sessionFactory' defined in class path resource解决方法
- Unable to compile class for JSP找不出异常
- struts2 下传一段时间后报错No result defined for action and result input重启后便没有有关问题了
- Could not load JDBC driver class 咋回事
- No setter found for property 'sessionFactoroy' in class 'com.iBBS.dao.impl.UserI解决思路
- getHibernateTemplate().get(entity.Class,serializabel id) 如何报java.lang.NullPointerException的错误
- jsp中出现the local variable zhang is never read求大神见教
- 小弟我在tomcat里的Server.xml部署web项目报Error instantiating servlet class
- Jsp + Oracle 怎么取回id,报错getInt not implemented for class oracle.jdbc.driver.T4CRo
- 不好意思,问下 <result>/{1}.jsp</result> 是什么意思,小弟我没有 1.jsp文件啊
- ssh项目hibernate 异常:org.hibernate.MappingException: Association references unmapped class: Message
- JSP数据分页报After end of result set异常
- No result defined for action com.tes.web.action.FirstAction and result success,该怎么处理
- java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUt,该如何处理
- Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver'解决方法
- class path resource [applicationContext.xml] does not exist解决方法
- ids for this class must be manually assigned before calling save(): po.Project解决方法
- java面试例题惑 之变量初始顺序,变量覆盖,字符串池,final,finally区别