Search in sources :

Example 1 with NIOProcessor

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

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

Example 2 with NIOProcessor

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

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 = CobarServer.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;
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) ArrayList(java.util.ArrayList) NIOProcessor(com.alibaba.cobar.net.NIOProcessor)

Example 3 with NIOProcessor

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

the class ShowThreadPool method getExecutors.

private static List<NameableExecutor> getExecutors() {
    List<NameableExecutor> list = new LinkedList<NameableExecutor>();
    CobarServer server = CobarServer.getInstance();
    list.add(server.getInitExecutor());
    list.add(server.getTimerExecutor());
    list.add(server.getManagerExecutor());
    for (NIOProcessor p : server.getProcessors()) {
        list.add(p.getHandler());
        list.add(p.getExecutor());
        list.add(p.getCommitter());
    }
    return list;
}
Also used : NameableExecutor(com.alibaba.cobar.util.NameableExecutor) NIOProcessor(com.alibaba.cobar.net.NIOProcessor) LinkedList(java.util.LinkedList) CobarServer(com.alibaba.cobar.CobarServer)

Example 4 with NIOProcessor

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

the class ShowConnectionSQL 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.isClosed()) {
                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 5 with NIOProcessor

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

the class ShowProcessor 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;
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        RowDataPacket row = getRow(p, c.getCharset());
        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 : 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)

Aggregations

NIOProcessor (com.alibaba.cobar.net.NIOProcessor)12 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)6 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)6 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)6 ByteBuffer (java.nio.ByteBuffer)6 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)5 NIOAcceptor (com.alibaba.cobar.net.NIOAcceptor)2 CobarServer (com.alibaba.cobar.CobarServer)1 SystemConfig (com.alibaba.cobar.config.model.SystemConfig)1 ManagerConnectionFactory (com.alibaba.cobar.manager.ManagerConnectionFactory)1 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)1 BackendConnection (com.alibaba.cobar.net.BackendConnection)1 NIOConnector (com.alibaba.cobar.net.NIOConnector)1 ServerConnection (com.alibaba.cobar.server.ServerConnection)1 ServerConnectionFactory (com.alibaba.cobar.server.ServerConnectionFactory)1 NameableExecutor (com.alibaba.cobar.util.NameableExecutor)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1