Search in sources :

Example 11 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ShowCommandCount method getRow.

private static RowDataPacket getRow() {
    long querys = 0;
    for (NIOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
        querys += p.getCommands().queryCount();
    }
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(querys));
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) NIOProcessor(com.actiontech.dble.net.NIOProcessor)

Example 12 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ShowProcessor 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()) {
        RowDataPacket row = getRow(p);
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
        RowDataPacket row = getRow(p);
        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);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 13 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ShowBackend method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    byte packetId = EOF.getPacketId();
    for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if (bc != null) {
                RowDataPacket row = getRow(bc, c.getCharset().getResults());
                if (row != null) {
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                }
            }
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 14 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor 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;
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) ArrayList(java.util.ArrayList) NIOProcessor(com.actiontech.dble.net.NIOProcessor)

Example 15 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor 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;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ServerConnection(com.actiontech.dble.server.ServerConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Aggregations

NIOProcessor (com.actiontech.dble.net.NIOProcessor)16 FrontendConnection (com.actiontech.dble.net.FrontendConnection)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)8 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)6 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ByteBuffer (java.nio.ByteBuffer)6 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)4 ServerConnection (com.actiontech.dble.server.ServerConnection)3 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1 NonBlockingSession (com.actiontech.dble.server.NonBlockingSession)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1