Search in sources :

Example 11 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowTime method execute.

public static void execute(ManagerConnection c, int type) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    RowDataPacket row = getRow(type);
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 12 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowVariables method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    for (Map.Entry<String, String> e : variables.entrySet()) {
        RowDataPacket row = getRow(e.getKey(), e.getValue(), c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowCommand method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
        RowDataPacket row = getRow(p, c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 14 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowConnection method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
    for (NIOProcessor p : processors) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (fc != null) {
                RowDataPacket row = getRow(fc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 15 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class ShowDataSource method execute.

public static void execute(ManagerConnection c, String name) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, List<PhysicalDatasource>> dataSources = new HashMap<String, List<PhysicalDatasource>>();
    if (null != name) {
        PhysicalDBNode dn = conf.getDataNodes().get(name);
        if (dn != null) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    } else {
        for (PhysicalDBNode dn : conf.getDataNodes().values()) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    }
    for (Map.Entry<String, List<PhysicalDatasource>> dsEntry : dataSources.entrySet()) {
        String dnName = dsEntry.getKey();
        for (PhysicalDatasource ds : dsEntry.getValue()) {
            RowDataPacket row = getRow(dnName, ds, c.getCharset());
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) List(java.util.List) LinkedList(java.util.LinkedList) FieldPacket(io.mycat.net.mysql.FieldPacket) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FieldPacket (io.mycat.net.mysql.FieldPacket)84 ByteBuffer (java.nio.ByteBuffer)75 EOFPacket (io.mycat.net.mysql.EOFPacket)74 RowDataPacket (io.mycat.net.mysql.RowDataPacket)69 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)9 NIOProcessor (io.mycat.net.NIOProcessor)7 UserStat (io.mycat.statistic.stat.UserStat)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SchemaConfig (io.mycat.config.model.SchemaConfig)4 MycatConfig (io.mycat.config.MycatConfig)3 FrontendConnection (io.mycat.net.FrontendConnection)3 BackendConnection (io.mycat.backend.BackendConnection)2 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)2 UserConfig (io.mycat.config.model.UserConfig)2 ServerConnection (io.mycat.server.ServerConnection)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2