Search in sources :

Example 1 with BaseCode

use of io.dingodb.server.protocol.code.BaseCode 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)

Example 2 with BaseCode

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

the class MetaServiceHandler method onTagMessage.

private void onTagMessage(Message message, Channel channel) {
    ByteBuffer buffer = ByteBuffer.wrap(message.toBytes());
    Code code = Code.valueOf(PrimitiveCodec.readZigZagInt(buffer));
    if (code instanceof BaseCode) {
        switch((BaseCode) code) {
            case PING:
                channel.registerMessageListener(this::onMessage);
                channel.send(PONG.message());
                return;
            case OTHER:
                return;
            default:
                channel.send(UNSUPPORTED_CODE.message());
                break;
        }
    }
    onMessage(message, channel);
}
Also used : BaseCode(io.dingodb.server.protocol.code.BaseCode) ByteBuffer(java.nio.ByteBuffer) Code(io.dingodb.server.protocol.code.Code) BaseCode(io.dingodb.server.protocol.code.BaseCode) MetaServiceCode(io.dingodb.server.protocol.code.MetaServiceCode)

Aggregations

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