use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.
the class KillConnection method getList.
private static List<FrontendConnection> getList(String stmt, int offset, ManagerConnection mc) {
String ids = stmt.substring(offset).trim();
if (ids.length() > 0) {
String[] idList = SplitUtil.split(ids, ',', true);
List<FrontendConnection> fcList = new ArrayList<FrontendConnection>(idList.length);
NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
for (String id : idList) {
long value = 0;
try {
value = Long.parseLong(id);
} catch (NumberFormatException e) {
continue;
}
FrontendConnection fc = null;
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
fcList.add(fc);
break;
}
}
}
return fcList;
}
return null;
}
use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.
the class ShowSession 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 process : MycatServer.getInstance().getProcessors()) {
for (FrontendConnection front : process.getFrontends().values()) {
if (!(front instanceof ServerConnection)) {
continue;
}
ServerConnection sc = (ServerConnection) front;
RowDataPacket row = getRow(sc, c.getCharset());
if (row != null) {
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.FrontendConnection 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);
}
use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.
the class FrontendConnectionFactory method make.
public FrontendConnection make(NetworkChannel channel) throws IOException {
channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
FrontendConnection c = getConnection(channel);
MycatServer.getInstance().getConfig().setSocketParams(c, true);
return c;
}
use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.
the class KillConnection method response.
public static void response(String stmt, int offset, ManagerConnection mc) {
int count = 0;
List<FrontendConnection> list = getList(stmt, offset, mc);
if (list != null) {
for (NIOConnection c : list) {
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append("killed by manager").toString());
c.close("kill by manager");
count++;
}
}
OkPacket packet = new OkPacket();
packet.packetId = 1;
packet.affectedRows = count;
packet.serverStatus = 2;
packet.write(mc);
}
Aggregations