use of com.actiontech.dble.net.FrontendConnection in project dble by actiontech.
the class ShowConnectionSQL 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.getPacketId();
for (NIOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (!fc.isClosed()) {
RowDataPacket row = getRow(fc, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.FrontendConnection in project dble by actiontech.
the class KillHandler method handle.
public static void handle(String stmt, int offset, 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 myself
if (value == c.getId()) {
getOkPacket().write(c);
c.write(c.allocate());
return;
}
// get connection and close it
FrontendConnection fc = null;
NIOProcessor[] processors = DbleServer.getInstance().getFrontProcessors();
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
break;
}
}
if (fc != null) {
if (!fc.getUser().equals(c.getUser())) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "can't kill other user's connection" + id);
return;
}
fc.killAndClose("killed");
getOkPacket().write(c);
} else {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
}
}
}
use of com.actiontech.dble.net.FrontendConnection in project dble by actiontech.
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<>(idList.length);
NIOProcessor[] processors = DbleServer.getInstance().getFrontProcessors();
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 com.actiontech.dble.net.FrontendConnection in project dble by actiontech.
the class ReloadConfig method findAndcloseFrontCon.
private static void findAndcloseFrontCon(BackendConnection con) {
if (con instanceof MySQLConnection) {
MySQLConnection mcon1 = (MySQLConnection) con;
for (NIOProcessor processor : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fcon : processor.getFrontends().values()) {
if (fcon instanceof ServerConnection) {
ServerConnection scon = (ServerConnection) fcon;
Map<RouteResultsetNode, BackendConnection> bons = scon.getSession2().getTargetMap();
for (BackendConnection bcon : bons.values()) {
if (bcon instanceof MySQLConnection) {
MySQLConnection mcon2 = (MySQLConnection) bcon;
if (mcon1 == mcon2) {
scon.killAndClose("reload config all");
return;
}
}
}
}
}
}
}
}
use of com.actiontech.dble.net.FrontendConnection in project dble by actiontech.
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);
c.setSocketParams(true);
return c;
}
Aggregations