Search in sources :

Example 6 with NIOProcessor

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

the class ShowRouter 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)

Example 7 with NIOProcessor

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

the class SampleServer method startup.

public void startup() throws IOException {
    String name = config.getServerName();
    LOGGER.info("===============================================");
    LOGGER.info(name + " is ready to startup ...");
    // schedule timer task
    timer = new Timer(name + "Timer", true);
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            TimeUtil.update();
        }
    }, 0L, TIME_UPDATE_PERIOD);
    LOGGER.info("Task Timer is started ...");
    // startup processors
    processors = new NIOProcessor[Runtime.getRuntime().availableProcessors()];
    for (int i = 0; i < processors.length; i++) {
        processors[i] = new NIOProcessor(name + "Processor" + i);
        processors[i].startup();
    }
    // startup server
    SampleConnectionFactory factory = new SampleConnectionFactory();
    server = new NIOAcceptor(name + "Server", SERVER_PORT, factory);
    server.setProcessors(processors);
    server.start();
    LOGGER.info(server.getName() + " is started and listening on " + server.getPort());
    // end
    LOGGER.info("===============================================");
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) NIOAcceptor(com.alibaba.cobar.net.NIOAcceptor) NIOProcessor(com.alibaba.cobar.net.NIOProcessor)

Example 8 with NIOProcessor

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

the class CobarServer method startup.

public void startup() throws IOException {
    // server startup
    LOGGER.info("===============================================");
    LOGGER.info(NAME + " is ready to startup ...");
    SystemConfig system = config.getSystem();
    timer.schedule(updateTime(), 0L, TIME_UPDATE_PERIOD);
    // startup processors
    LOGGER.info("Startup processors ...");
    int handler = system.getProcessorHandler();
    int executor = system.getProcessorExecutor();
    int committer = system.getProcessorCommitter();
    processors = new NIOProcessor[system.getProcessors()];
    for (int i = 0; i < processors.length; i++) {
        processors[i] = new NIOProcessor("Processor" + i, handler, executor, committer);
        processors[i].startup();
    }
    timer.schedule(processorCheck(), 0L, system.getProcessorCheckPeriod());
    // startup connector
    LOGGER.info("Startup connector ...");
    connector = new NIOConnector(NAME + "Connector");
    connector.setProcessors(processors);
    connector.start();
    // init dataNodes
    Map<String, MySQLDataNode> dataNodes = config.getDataNodes();
    LOGGER.info("Initialize dataNodes ...");
    for (MySQLDataNode node : dataNodes.values()) {
        node.init(1, 0);
    }
    timer.schedule(dataNodeIdleCheck(), 0L, system.getDataNodeIdleCheckPeriod());
    timer.schedule(dataNodeHeartbeat(), 0L, system.getDataNodeHeartbeatPeriod());
    // startup manager
    ManagerConnectionFactory mf = new ManagerConnectionFactory();
    mf.setCharset(system.getCharset());
    mf.setIdleTimeout(system.getIdleTimeout());
    manager = new NIOAcceptor(NAME + "Manager", system.getManagerPort(), mf);
    manager.setProcessors(processors);
    manager.start();
    LOGGER.info(manager.getName() + " is started and listening on " + manager.getPort());
    // startup server
    ServerConnectionFactory sf = new ServerConnectionFactory();
    sf.setCharset(system.getCharset());
    sf.setIdleTimeout(system.getIdleTimeout());
    server = new NIOAcceptor(NAME + "Server", system.getServerPort(), sf);
    server.setProcessors(processors);
    server.start();
    timer.schedule(clusterHeartbeat(), 0L, system.getClusterHeartbeatPeriod());
    // server started
    LOGGER.info(server.getName() + " is started and listening on " + server.getPort());
    LOGGER.info("===============================================");
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) SystemConfig(com.alibaba.cobar.config.model.SystemConfig) ServerConnectionFactory(com.alibaba.cobar.server.ServerConnectionFactory) NIOConnector(com.alibaba.cobar.net.NIOConnector) ManagerConnectionFactory(com.alibaba.cobar.manager.ManagerConnectionFactory) NIOAcceptor(com.alibaba.cobar.net.NIOAcceptor) NIOProcessor(com.alibaba.cobar.net.NIOProcessor)

Example 9 with NIOProcessor

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

the class ShowCommand 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)

Example 10 with NIOProcessor

use of com.alibaba.cobar.net.NIOProcessor 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)

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