use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowServer 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;
RowDataPacket row = getRow(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);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowSqlResultSet method getRow.
private static RowDataPacket getRow(int i, String user, String sql, int count, int resultSetSize, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(i));
row.add(StringUtil.encode(user, charset));
row.add(LongUtil.toBytes(count));
row.add(StringUtil.encode(sql, charset));
row.add(IntegerUtil.toBytes(resultSetSize));
return row;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowSqlResultSet 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;
int i = 0;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
ConcurrentHashMap<String, SqlResultSet> map = userStat.getSqlResultSizeRecorder().getSqlResultSet();
if (map != null) {
for (SqlResultSet sqlResultSet : map.values()) {
RowDataPacket row = getRow(++i, user, sqlResultSet.getSql(), sqlResultSet.getCount(), sqlResultSet.getResultSetSize(), 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);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowHeartbeatDetail method getRows.
private static List<RowDataPacket> getRows(String name, String charset) {
List<RowDataPacket> list = new LinkedList<RowDataPacket>();
MycatConfig conf = MycatServer.getInstance().getConfig();
// host nodes
String type = "";
String ip = "";
int port = 0;
DBHeartbeat hb = null;
Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
for (PhysicalDBPool pool : dataHosts.values()) {
for (PhysicalDatasource ds : pool.getAllDataSources()) {
if (name.equals(ds.getName())) {
hb = ds.getHeartbeat();
type = ds.getConfig().getDbType();
ip = ds.getConfig().getIp();
port = ds.getConfig().getPort();
break;
}
}
}
if (hb != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Queue<HeartbeatRecorder.Record> heatbeartRecorders = hb.getRecorder().getRecordsAll();
for (HeartbeatRecorder.Record record : heatbeartRecorders) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(name, charset));
row.add(StringUtil.encode(type, charset));
row.add(StringUtil.encode(ip, charset));
row.add(IntegerUtil.toBytes(port));
long time = record.getTime();
String timeStr = sdf.format(new Date(time));
row.add(StringUtil.encode(timeStr, charset));
row.add(LongUtil.toBytes(record.getValue()));
list.add(row);
}
} else {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
list.add(row);
}
return list;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowHeartbeatDetail method response.
public static void response(ManagerConnection c, String stmt) {
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;
Pair<String, String> pair = ManagerParseHeartbeat.getPair(stmt);
String name = pair.getValue();
for (RowDataPacket row : getRows(name, 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);
}
Aggregations