Search in sources :

Example 1 with FrontendConnection

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

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 = MycatServer.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(io.mycat.net.FrontendConnection) ArrayList(java.util.ArrayList) NIOProcessor(io.mycat.net.NIOProcessor)

Example 2 with FrontendConnection

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

the class ShowSession 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;
    for (NIOProcessor process : MycatServer.getInstance().getProcessors()) {
        for (FrontendConnection front : process.getFrontends().values()) {
            if (!(front instanceof ServerConnection)) {
                continue;
            }
            ServerConnection sc = (ServerConnection) front;
            RowDataPacket row = getRow(sc, c.getCharset());
            if (row != null) {
                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) ServerConnection(io.mycat.server.ServerConnection) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 3 with FrontendConnection

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

the class ShowConnection 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();
    NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
    for (NIOProcessor p : processors) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (fc != null) {
                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 4 with FrontendConnection

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

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);
    MycatServer.getInstance().getConfig().setSocketParams(c, true);
    return c;
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection)

Example 5 with FrontendConnection

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

the class KillConnection method response.

public static void response(String stmt, int offset, ManagerConnection mc) {
    int count = 0;
    List<FrontendConnection> list = getList(stmt, offset, mc);
    if (list != null) {
        for (NIOConnection c : list) {
            StringBuilder s = new StringBuilder();
            logger.warn(s.append(c).append("killed by manager").toString());
            c.close("kill by manager");
            count++;
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(mc);
}
Also used : FrontendConnection(io.mycat.net.FrontendConnection) OkPacket(io.mycat.net.mysql.OkPacket) NIOConnection(io.mycat.net.NIOConnection)

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