Search in sources :

Example 41 with RowDataPacket

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);
}
Also used : ResultSetHeaderPacket(com.alibaba.cobar.net.mysql.ResultSetHeaderPacket) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 42 with RowDataPacket

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;
}
Also used : CobarHeartbeat(com.alibaba.cobar.heartbeat.CobarHeartbeat) MySQLDetector(com.alibaba.cobar.heartbeat.MySQLDetector) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) MySQLHeartbeat(com.alibaba.cobar.heartbeat.MySQLHeartbeat) CobarDetector(com.alibaba.cobar.heartbeat.CobarDetector)

Example 43 with RowDataPacket

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;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 44 with RowDataPacket

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);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) NIOProcessor(com.alibaba.cobar.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 45 with RowDataPacket

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;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) CommandCount(com.alibaba.cobar.statistic.CommandCount)

Aggregations

RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)61 ByteBuffer (java.nio.ByteBuffer)38 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)37 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)37 CobarConfig (com.alibaba.cobar.CobarConfig)7 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)6 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)6 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)4 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)3 ArrayList (java.util.ArrayList)3 CobarNode (com.alibaba.cobar.CobarNode)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)2 CobarHeartbeat (com.alibaba.cobar.heartbeat.CobarHeartbeat)2 MySQLHeartbeat (com.alibaba.cobar.heartbeat.MySQLHeartbeat)2 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)2 ResultSetHeaderPacket (com.alibaba.cobar.net.mysql.ResultSetHeaderPacket)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 CobarCluster (com.alibaba.cobar.CobarCluster)1