Search in sources :

Example 6 with FrontendConnection

use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.

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.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (!fc.isClosed()) {
                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);
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 7 with FrontendConnection

use of io.mycat.net.FrontendConnection in project Mycat-Server by MyCATApache.

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 = MycatServer.getInstance().getProcessors();
        for (NIOProcessor p : processors) {
            if ((fc = p.getFrontends().get(value)) != null) {
                break;
            }
        }
        if (fc != null) {
            fc.close("killed");
            getOkPacket().write(c);
        } else {
            c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
        }
    }
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection) NIOProcessor(io.mycat.net.NIOProcessor)

Aggregations

FrontendConnection (io.mycat.net.FrontendConnection)7 NIOProcessor (io.mycat.net.NIOProcessor)5 EOFPacket (io.mycat.net.mysql.EOFPacket)3 FieldPacket (io.mycat.net.mysql.FieldPacket)3 RowDataPacket (io.mycat.net.mysql.RowDataPacket)3 ByteBuffer (java.nio.ByteBuffer)3 NIOConnection (io.mycat.net.NIOConnection)1 OkPacket (io.mycat.net.mysql.OkPacket)1 ServerConnection (io.mycat.server.ServerConnection)1 ArrayList (java.util.ArrayList)1