Search in sources :

Example 6 with FrontendConnection

use of com.alibaba.cobar.net.FrontendConnection in project cobar by alibaba.

the class ShowConnection method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (fc != null) {
                RowDataPacket row = getRow(fc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // write buffer
    c.write(buffer);
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) NIOProcessor(com.alibaba.cobar.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 7 with FrontendConnection

use of com.alibaba.cobar.net.FrontendConnection 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);
        }
    }
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) ServerConnection(com.alibaba.cobar.server.ServerConnection) NIOProcessor(com.alibaba.cobar.net.NIOProcessor)

Aggregations

FrontendConnection (com.alibaba.cobar.net.FrontendConnection)7 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)5 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)2 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)2 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)2 ByteBuffer (java.nio.ByteBuffer)2 NIOConnection (com.alibaba.cobar.net.NIOConnection)1 BufferQueue (com.alibaba.cobar.net.buffer.BufferQueue)1 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)1 ServerConnection (com.alibaba.cobar.server.ServerConnection)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1