use of com.alibaba.cobar.net.NIOProcessor in project cobar by alibaba.
the class ShowBackend method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
String charset = c.getCharset();
for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if (bc != null) {
RowDataPacket row = getRow(bc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
}
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
}
use of com.alibaba.cobar.net.NIOProcessor in project cobar by alibaba.
the class KillQueryHandler method handle.
public static void handle(String stmt, int offset, final ServerConnection c) {
String id = stmt.substring(offset).trim();
if (StringUtil.isEmpty(id)) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "NULL connection id");
} else {
// get value
long value = 0;
try {
value = Long.parseLong(id);
} catch (NumberFormatException e) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Invalid connection id:" + id);
return;
}
// kill query itself
if (value == c.getId()) {
c.cancel(null);
return;
}
// get the connection and kill query
FrontendConnection fc = null;
NIOProcessor[] processors = CobarServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
break;
}
}
if (fc != null) {
if (fc instanceof ServerConnection) {
((ServerConnection) fc).cancel(c);
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unknown command");
}
} else {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
}
}
}
Aggregations