Search in sources :

Example 1 with HeartbeatPacket

use of com.alibaba.cobar.net.mysql.HeartbeatPacket in project cobar by alibaba.

the class Heartbeat method response.

public static void response(ServerConnection c, byte[] data) {
    HeartbeatPacket hp = new HeartbeatPacket();
    hp.read(data);
    if (CobarServer.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));
        }
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket) ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) HeartbeatPacket(com.alibaba.cobar.net.mysql.HeartbeatPacket)

Example 2 with HeartbeatPacket

use of com.alibaba.cobar.net.mysql.HeartbeatPacket in project cobar by alibaba.

the class CobarDetector method heartbeat.

public void heartbeat() {
    if (isAuthenticated) {
        HeartbeatPacket hp = new HeartbeatPacket();
        hp.packetId = 0;
        hp.command = MySQLPacket.COM_HEARTBEAT;
        hp.id = heartbeat.detectCount.incrementAndGet();
        hp.write(this);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(heartbeat.requestMessage(CobarHeartbeat.SEND, String.valueOf(hp.id).getBytes()));
        }
    } else {
        authenticate();
    }
}
Also used : HeartbeatPacket(com.alibaba.cobar.net.mysql.HeartbeatPacket)

Aggregations

HeartbeatPacket (com.alibaba.cobar.net.mysql.HeartbeatPacket)2 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)1 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)1