Search in sources :

Example 21 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowThreadPool 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;
    List<NameableExecutor> executors = getExecutors();
    for (NameableExecutor exec : executors) {
        if (exec != null) {
            RowDataPacket row = getRow(exec, 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 : NameableExecutor(io.mycat.util.NameableExecutor) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 22 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowThreadPool method getRow.

private static RowDataPacket getRow(NameableExecutor exec, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(exec.getName(), charset));
    row.add(IntegerUtil.toBytes(exec.getPoolSize()));
    row.add(IntegerUtil.toBytes(exec.getActiveCount()));
    row.add(IntegerUtil.toBytes(exec.getQueue().size()));
    row.add(LongUtil.toBytes(exec.getCompletedTaskCount()));
    row.add(LongUtil.toBytes(exec.getTaskCount()));
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 23 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowVariables method getRow.

private static RowDataPacket getRow(String name, String value, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(name, charset));
    row.add(StringUtil.encode(value, charset));
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 24 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowWhiteHost 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;
    Map<String, List<UserConfig>> map = MycatServer.getInstance().getConfig().getFirewall().getWhitehost();
    for (String key : map.keySet()) {
        List<UserConfig> userConfigs = map.get(key);
        String users = "";
        for (int i = 0; i < userConfigs.size(); i++) {
            if (i > 0) {
                users += "," + userConfigs.get(i).getName();
            } else {
                users += userConfigs.get(i).getName();
            }
        }
        RowDataPacket row = getRow(key, users, 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) ArrayList(java.util.ArrayList) List(java.util.List) UserConfig(io.mycat.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 25 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowHeartbeat method getRows.

private static List<RowDataPacket> getRows() {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(ds.getName().getBytes());
            row.add(ds.getConfig().getDbType().getBytes());
            if (hb != null) {
                row.add(ds.getConfig().getIp().getBytes());
                row.add(IntegerUtil.toBytes(ds.getConfig().getPort()));
                row.add(IntegerUtil.toBytes(hb.getStatus()));
                row.add(IntegerUtil.toBytes(hb.getErrorCount()));
                row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
                row.add(LongUtil.toBytes(hb.getTimeout()));
                row.add(hb.getRecorder().get().getBytes());
                String lat = hb.getLastActiveTime();
                row.add(lat == null ? null : lat.getBytes());
                row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
            } else {
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
            }
            list.add(row);
        }
    }
    return list;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList)

Aggregations

RowDataPacket (io.mycat.net.mysql.RowDataPacket)269 FieldPacket (io.mycat.net.mysql.FieldPacket)143 ByteBuffer (java.nio.ByteBuffer)140 EOFPacket (io.mycat.net.mysql.EOFPacket)137 MycatConfig (io.mycat.config.MycatConfig)20 LinkedList (java.util.LinkedList)16 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)14 NIOProcessor (io.mycat.net.NIOProcessor)14 SchemaConfig (io.mycat.config.model.SchemaConfig)13 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)13 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)12 UserStat (io.mycat.statistic.stat.UserStat)12 IOException (java.io.IOException)12 Map (java.util.Map)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)10 ServerConnection (io.mycat.server.ServerConnection)10 BinaryRowDataPacket (io.mycat.net.mysql.BinaryRowDataPacket)8 File (java.io.File)8 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 BufferedReader (java.io.BufferedReader)6