Search in sources :

Example 6 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class RaftState method loadState.

/**
 * Deserialize state from an inputstream
 *
 * @param in             inputstream
 * @throws IOException   on any IO error
 */
@Override
public void loadState(InputStream in) throws IOException {
    int len = Util.readVarInt(in);
    Buffer buf = new Buffer(len);
    in.read(buf.array(), 0, len);
    buf.position(len);
    buf.flip();
    int count = buf.getVarInt();
    for (int i = 0; i < count; i++) {
        Session session = new Session(buf);
        sessions.put(session.getName(), session);
    }
    record = new ClusterRecord(buf);
}
Also used : Buffer(tezc.base.common.Buffer) ByteBuffer(java.nio.ByteBuffer) ClusterRecord(tezc.core.record.ClusterRecord) Session(tezc.core.cluster.Session)

Example 7 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class ConfigCommand method encode.

/**
 * Encode the command to a raw buffer
 */
@Override
public void encode() {
    if (!rawReady) {
        int len = ProtoUtil.byteLen(RegisterCommand.TYPE) + record.encodedLen();
        rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
        rawMsg.putVarInt(len);
        rawMsg.put(ConfigCommand.TYPE);
        record.encode(rawMsg);
        rawMsg.flip();
        rawReady = true;
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Example 8 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class NoOPCommand method encode.

/**
 * Encode the command
 */
@Override
public void encode() {
    if (!rawReady) {
        int len = ProtoUtil.byteLen(TYPE);
        rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
        rawMsg.putVarInt(len);
        rawMsg.put(TYPE);
        rawMsg.flip();
        rawReady = true;
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Example 9 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class RegisterCommand method encode.

/**
 * Encode the command
 */
@Override
public void encode() {
    if (!rawReady) {
        int len = ProtoUtil.byteLen(RegisterCommand.TYPE) + ProtoUtil.stringLen(name);
        rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
        rawMsg.putVarInt(len);
        rawMsg.put(RegisterCommand.TYPE);
        rawMsg.putString(name);
        rawMsg.flip();
        rawReady = true;
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Example 10 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class UnregisterCommand method encode.

/**
 * Encode the command
 */
@Override
public void encode() {
    if (!rawReady) {
        int len = ProtoUtil.byteLen(UnregisterCommand.TYPE) + ProtoUtil.varIntLen(id);
        rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
        rawMsg.putVarInt(len);
        rawMsg.put(RegisterCommand.TYPE);
        rawMsg.putVarInt(id);
        rawMsg.flip();
        rawReady = true;
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Aggregations

Buffer (tezc.base.common.Buffer)28 ByteBuffer (java.nio.ByteBuffer)16 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 StandardOpenOption (java.nio.file.StandardOpenOption)2 Session (tezc.core.cluster.Session)2 ClusterRecord (tezc.core.record.ClusterRecord)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 State (tezc.State)1