public static void write(List<Connection> conLst, TransactionMessage message) throws Exception { // 向多server发送数据包 boolean isSended = false; // int sendNum = 0; int id = message.getId(); for (Connection con : conLst) { if (!con.isConFlag()) continue; try { send(con.getSocket(), message); String logStr = ""; // 发心跳包 if (id == SocketConfig.HB) { // 写入日志 logStr = " IP为" + con.getSocket().toString() + "的向从机发送心跳包数据"; } else { // 发业务 int messageId = SocketConfig.getB_ID(message.getData()); // 条件中的5类业务(hmuserver向webserver发送数据)只向一个server发送 add by yuht // 2013.11.05 if ((messageId == MsgConst.Up_HMU_SWVERSION || messageId == MsgConst.UP_PKG_DOMAIN || messageId == MsgConst.UP_UPG_RECORD || messageId == MsgConst.INSERT_UPG_RECORD || messageId == MsgConst.NAGIOS)) isSended = true; logStr = "To-" + con.getIp() + " 发送事务ID:" + id + " 消息ID:" + messageId; } ClientStart.printLog(logStr); sendNum++; } catch (Exception e) { // 如果出现异常则表示此次Socket通信中断(相当于服务端挂掉),需要待重连后方能使用 // 因此需要从事务列表中异常心跳包 // e.printStackTrace(); // ClientStart.socketFlag = false; System.out.println("send to " + con.getIp() + " exception!"); con.setConFlag(false); // throw e; } // 发送成功即停止发送 if (isSended) break; } // 如果sever全部未发送成功计入队列 下次发送 if (sendNum == 0 && id != SocketConfig.HB && !message.isReload()) ClientTransactionAccepted.setTransactionAccepted(message.getData()); }