Search in sources :

Example 26 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class ShowHelp 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 (String key : keys) {
        RowDataPacket row = getRow(key, helps.get(key), 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);
    // post write
    c.write(buffer);
}
Also used : 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 27 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class ShowRouter 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 28 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class ShowSQLDetail method execute.

public static void execute(ManagerConnection c, long sql) {
    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 (int i = 0; i < 3; i++) {
        RowDataPacket row = getRow(sql, 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) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 29 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class ShowSQLExecute 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 (int i = 0; i < 3; i++) {
        RowDataPacket row = getRow(1000 * (i + 1), 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) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 30 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket 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)

Aggregations

FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)43 ByteBuffer (java.nio.ByteBuffer)40 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)38 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)37 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)6 CobarConfig (com.alibaba.cobar.CobarConfig)5 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)3 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)3 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)3 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)2 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)2 ResultSetHeaderPacket (com.alibaba.cobar.net.mysql.ResultSetHeaderPacket)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)1 UserConfig (com.alibaba.cobar.config.model.UserConfig)1 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)1