use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class SampleResponseHandler method response.
public static void response(SampleConnection c, String message) {
byte packetId = 0;
ByteBuffer buffer = c.allocate();
// header
ResultSetHeaderPacket header = new ResultSetHeaderPacket();
header.packetId = ++packetId;
header.fieldCount = 1;
buffer = header.write(buffer, c);
// fields
FieldPacket[] fields = new FieldPacket[header.fieldCount];
for (FieldPacket field : fields) {
field = new FieldPacket();
field.packetId = ++packetId;
field.charsetIndex = CharsetUtil.getIndex("Cp1252");
field.name = "SampleServer".getBytes();
field.type = Fields.FIELD_TYPE_VAR_STRING;
buffer = field.write(buffer, c);
}
// eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c);
// rows
RowDataPacket row = new RowDataPacket(header.fieldCount);
row.add(message != null ? encode(message, c.getCharset()) : encode("HelloWorld!", c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowBackend method getRow.
private static RowDataPacket getRow(BackendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(c.getProcessor().getName().getBytes());
row.add(LongUtil.toBytes(c.getId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
if (c instanceof CobarDetector) {
CobarDetector detector = (CobarDetector) c;
CobarHeartbeat heartbeat = detector.getHeartbeat();
row.add(detector.isAuthenticated() ? "true".getBytes() : "false".getBytes());
row.add(detector.isQuit() ? "true".getBytes() : "false".getBytes());
row.add(heartbeat.isChecking() ? "true".getBytes() : "false".getBytes());
row.add(heartbeat.isStop() ? "true".getBytes() : "false".getBytes());
row.add(LongUtil.toBytes(heartbeat.getStatus()));
} else if (c instanceof MySQLDetector) {
MySQLDetector detector = (MySQLDetector) c;
MySQLHeartbeat heartbeat = detector.getHeartbeat();
row.add(detector.isAuthenticated() ? "true".getBytes() : "false".getBytes());
row.add(detector.isQuit() ? "true".getBytes() : "false".getBytes());
row.add(heartbeat.isChecking() ? "true".getBytes() : "false".getBytes());
row.add(heartbeat.isStop() ? "true".getBytes() : "false".getBytes());
row.add(LongUtil.toBytes(heartbeat.getStatus()));
} else {
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
}
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowCollation method getRow.
private static RowDataPacket getRow(String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add("utf8_general_ci".getBytes());
row.add("utf8".getBytes());
row.add(IntegerUtil.toBytes(33));
row.add("Yes".getBytes());
row.add("Yes".getBytes());
row.add(LongUtil.toBytes(1));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowCommand method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
RowDataPacket row = getRow(p, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowCommand method getRow.
private static RowDataPacket getRow(NIOProcessor processor, String charset) {
CommandCount cc = processor.getCommands();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(processor.getName().getBytes());
row.add(LongUtil.toBytes(cc.initDBCount()));
row.add(LongUtil.toBytes(cc.queryCount()));
row.add(LongUtil.toBytes(cc.stmtPrepareCount()));
row.add(LongUtil.toBytes(cc.stmtExecuteCount()));
row.add(LongUtil.toBytes(cc.stmtCloseCount()));
row.add(LongUtil.toBytes(cc.pingCount()));
row.add(LongUtil.toBytes(cc.killCount()));
row.add(LongUtil.toBytes(cc.quitCount()));
row.add(LongUtil.toBytes(cc.otherCount()));
return row;
}
Aggregations