package io.vertx.spi.cluster.ignite.impl;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.cluster.NodeInfo;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryReader;
import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.binary.Binarylizable;
public class IgniteNodeInfo implements Binarylizable {
private NodeInfo nodeInfo;
public IgniteNodeInfo() {
}
public IgniteNodeInfo(NodeInfo nodeInfo) {
this.nodeInfo = nodeInfo;
}
@Override
public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeString("host", nodeInfo.host());
writer.writeInt("port", nodeInfo.port());
JsonObject metadata = nodeInfo.metadata();
writer.writeByteArray("meta", metadata != null ? metadata.toBuffer().getBytes() : null);
}
@Override
public void readBinary(BinaryReader reader) throws BinaryObjectException {
String host = reader.readString("host");
int port = reader.readInt("port");
byte[] bytes = reader.readByteArray("meta");
nodeInfo = new NodeInfo(host, port, bytes != null ? new JsonObject(Buffer.buffer(bytes)) : null);
}
public NodeInfo unwrap() {
return nodeInfo;
}
}