use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
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);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowSQLExecute 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 (int i = 0; i < 3; i++) {
RowDataPacket row = getRow(1000 * (i + 1), 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.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowSQLLarge method execute.
public static void execute(ManagerConnection c, boolean isClear) {
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, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<UserSqlLargeStat.SqlLarge> sqls = userStat.getSqlLargeRowStat().getSqls();
for (UserSqlLargeStat.SqlLarge sql : sqls) {
if (sql != null) {
RowDataPacket row = getRow(user, sql, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
//读取大结果集SQL后,清理
userStat.getSqlLargeRowStat().clear();
}
}
// 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.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowSQLSumUser method execute.
public static void execute(ManagerConnection c, boolean isClear) {
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()) {
i++;
//getRow(sqlStat,sql, c.getCharset());
RowDataPacket row = getRow(userStat, i, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
if (isClear) {
userStat.clearRwStat();
}
}
// 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.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowSysLog method execute.
public static void execute(ManagerConnection c, int numLines) {
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 filename = SystemConfig.getHomePath() + File.separator + "logs" + File.separator + "mycat.log";
String[] lines = getLinesByLogFile(filename, numLines);
boolean linesIsEmpty = true;
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (line != null) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(line.substring(0, 19), c.getCharset()));
row.add(StringUtil.encode(line.substring(19, line.length()), c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
linesIsEmpty = false;
}
}
if (linesIsEmpty) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode("NULL", c.getCharset()));
row.add(StringUtil.encode("NULL", 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);
}
Aggregations