public void executeBatchNodeCmd(SQLCtrlCommand cmdHandler) { this.cmdHandler = cmdHandler; final int initCount = session.getTargetCount(); runningCount.set(initCount); nodeCount = initCount; failed.set(false); faileCount.set(0); // 执行 int started = 0; for (RouteResultsetNode rrn : session.getTargetKeys()) { if (rrn == null) { LOGGER.error("null is contained in RoutResultsetNodes, source = " + session.getSource()); continue; } final BackendConnection conn = session.getTarget(rrn); if (conn != null) { conn.setResponseHandler(this); cmdHandler.sendCommand(session, conn); ++started; } } if (started < nodeCount) { runningCount.set(started); LOGGER.warn("some connection failed to execut " + (nodeCount - started)); /** * assumption: only caused by front-end connection close. <br> * Otherwise, packet must be returned to front-end */ failed.set(true); } }
public void doHeartBeat(BackendConnection conn, String sql) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("do heartbeat for con " + conn); } try { HeartBeatCon hbCon = new HeartBeatCon(conn); boolean notExist = (allCons.putIfAbsent(hbCon.conn.getId(), hbCon) == null); if (notExist) { conn.setResponseHandler(this); conn.query(sql); } } catch (Exception e) { executeException(conn, e); } }