public static void response(ServerConnection c, byte[] data) { HeartbeatPacket hp = new HeartbeatPacket(); hp.read(data); if (MycatServer.getInstance().isOnline()) { OkPacket ok = new OkPacket(); ok.packetId = 1; ok.affectedRows = hp.id; ok.serverStatus = 2; ok.write(c); if (HEARTBEAT.isInfoEnabled()) { HEARTBEAT.info(responseMessage("OK", c, hp.id)); } } else { ErrorPacket error = new ErrorPacket(); error.packetId = 1; error.errno = ErrorCode.ER_SERVER_SHUTDOWN; error.message = String.valueOf(hp.id).getBytes(); error.write(c); if (HEARTBEAT.isInfoEnabled()) { HEARTBEAT.info(responseMessage("ERROR", c, hp.id)); } } }
public static void execute(String stmt, ManagerConnection c) { int count = 0; Pair<String[], Integer> keys = ManagerParseStop.getPair(stmt); if (keys.getKey() != null && keys.getValue() != null) { long time = keys.getValue().intValue() * 1000L; Map<String, PhysicalDBPool> dns = MycatServer.getInstance().getConfig().getDataHosts(); for (String key : keys.getKey()) { PhysicalDBPool dn = dns.get(key); if (dn != null) { dn.getSource().setHeartbeatRecoveryTime(TimeUtil.currentTimeMillis() + time); ++count; StringBuilder s = new StringBuilder(); s.append(dn.getHostName()).append(" stop heartbeat '"); logger.warn(s.append(FormatUtil.formatTime(time, 3)).append("' by manager.")); } } } OkPacket packet = new OkPacket(); packet.packetId = 1; packet.affectedRows = count; packet.serverStatus = 2; packet.write(c); }
public static void execute(String stmt, ManagerConnection c) { MycatServer.getInstance().offline(); ok.write(c); }