Search in sources :

Example 1 with RaftServiceCode

use of io.dingodb.server.protocol.code.RaftServiceCode in project dingo by dingodb.

the class CoordinatorStateMachine method onMessage.

private void onMessage(Message message, Channel channel) {
    ByteBuffer buffer = ByteBuffer.wrap(message.toBytes());
    Code code = Code.valueOf(PrimitiveCodec.readZigZagInt(buffer));
    if (code instanceof RaftServiceCode) {
        switch((RaftServiceCode) code) {
            case GET_LEADER_LOCATION:
                getLeaderLocation(channel);
                break;
            case GET_ALL_LOCATION:
                getAllLocation(channel);
                break;
            case LISTEN_LEADER:
                log.info("New leader listener channel, remote: [{}]", channel.remoteAddress());
                leaderListener.add(channel);
                channel.closeListener(leaderListener::remove);
                break;
            default:
                channel.send(UNSUPPORTED_CODE.message());
                break;
        }
    } else if (code instanceof BaseCode) {
        switch((BaseCode) code) {
            case PING:
                channel.registerMessageListener(this::onMessage);
                channel.send(PONG.message());
                break;
            case OTHER:
                break;
            default:
                channel.send(UNSUPPORTED_CODE.message());
                break;
        }
    }
}
Also used : RaftServiceCode(io.dingodb.server.protocol.code.RaftServiceCode) BaseCode(io.dingodb.server.protocol.code.BaseCode) ByteBuffer(java.nio.ByteBuffer) RaftServiceCode(io.dingodb.server.protocol.code.RaftServiceCode) Code(io.dingodb.server.protocol.code.Code) BaseCode(io.dingodb.server.protocol.code.BaseCode)

Aggregations

BaseCode (io.dingodb.server.protocol.code.BaseCode)1 Code (io.dingodb.server.protocol.code.Code)1 RaftServiceCode (io.dingodb.server.protocol.code.RaftServiceCode)1 ByteBuffer (java.nio.ByteBuffer)1