Search in sources :

Example 1 with SystemConfig

use of com.alibaba.cobar.config.model.SystemConfig in project cobar by alibaba.

the class ServerConnectionFactory method getConnection.

@Override
protected FrontendConnection getConnection(SocketChannel channel) {
    SystemConfig sys = CobarServer.getInstance().getConfig().getSystem();
    ServerConnection c = new ServerConnection(channel);
    c.setPrivileges(new CobarPrivileges());
    c.setQueryHandler(new ServerQueryHandler(c));
    // c.setPrepareHandler(new ServerPrepareHandler(c)); TODO prepare
    c.setTxIsolation(sys.getTxIsolation());
    c.setSession(new BlockingSession(c));
    c.setSession2(new NonBlockingSession(c));
    return c;
}
Also used : SystemConfig(com.alibaba.cobar.config.model.SystemConfig) BlockingSession(com.alibaba.cobar.server.session.BlockingSession) NonBlockingSession(com.alibaba.cobar.server.session.NonBlockingSession) CobarPrivileges(com.alibaba.cobar.CobarPrivileges) NonBlockingSession(com.alibaba.cobar.server.session.NonBlockingSession)

Example 2 with SystemConfig

use of com.alibaba.cobar.config.model.SystemConfig 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 3 with SystemConfig

use of com.alibaba.cobar.config.model.SystemConfig in project cobar by alibaba.

the class CobarDetectorFactory method make.

public CobarDetector make(CobarHeartbeat heartbeat) throws IOException {
    SocketChannel channel = openSocketChannel();
    CobarNodeConfig cnc = heartbeat.getNode().getConfig();
    SystemConfig sys = CobarServer.getInstance().getConfig().getSystem();
    CobarDetector detector = new CobarDetector(channel);
    detector.setHost(cnc.getHost());
    detector.setPort(cnc.getPort());
    detector.setUser(sys.getClusterHeartbeatUser());
    detector.setPassword(sys.getClusterHeartbeatPass());
    detector.setHeartbeatTimeout(sys.getClusterHeartbeatTimeout());
    detector.setHeartbeat(heartbeat);
    postConnect(detector, CobarServer.getInstance().getConnector());
    return detector;
}
Also used : SocketChannel(java.nio.channels.SocketChannel) SystemConfig(com.alibaba.cobar.config.model.SystemConfig) CobarNodeConfig(com.alibaba.cobar.config.model.CobarNodeConfig)

Aggregations

SystemConfig (com.alibaba.cobar.config.model.SystemConfig)3 CobarPrivileges (com.alibaba.cobar.CobarPrivileges)1 CobarNodeConfig (com.alibaba.cobar.config.model.CobarNodeConfig)1 ManagerConnectionFactory (com.alibaba.cobar.manager.ManagerConnectionFactory)1 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)1 NIOAcceptor (com.alibaba.cobar.net.NIOAcceptor)1 NIOConnector (com.alibaba.cobar.net.NIOConnector)1 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)1 ServerConnectionFactory (com.alibaba.cobar.server.ServerConnectionFactory)1 BlockingSession (com.alibaba.cobar.server.session.BlockingSession)1 NonBlockingSession (com.alibaba.cobar.server.session.NonBlockingSession)1 SocketChannel (java.nio.channels.SocketChannel)1