Search in sources :

Example 1 with DefaultReactorBufferPool

use of io.mycat.buffer.DefaultReactorBufferPool in project Mycat2 by MyCATApache.

the class NativeMycatServer method startProxy.

private void startProxy(io.mycat.config.ServerConfig serverConfig) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, IOException, InterruptedException {
    String handlerConstructorText = "io.mycat.commands.DefaultCommandHandler";
    DefaultReactorBufferPool defaultReactorBufferPool = new DefaultReactorBufferPool(Optional.ofNullable(serverConfig).map(i -> i.getBufferPool()).map(i -> i.getArgs()).orElse(BufferPoolConfig.defaultValue()));
    Constructor<?> handlerConstructor = getConstructor(handlerConstructorText);
    int reactorNumber = Optional.ofNullable(serverConfig).map(i -> i.getReactorNumber()).orElse(1);
    List<MycatReactorThread> list = new ArrayList<>(reactorNumber);
    for (int i = 0; i < reactorNumber; i++) {
        Function<MycatSession, CommandDispatcher> function = session -> {
            try {
                CommandDispatcher commandDispatcher = (CommandDispatcher) handlerConstructor.newInstance();
                commandDispatcher.initRuntime(session);
                return commandDispatcher;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
        MycatReactorThread thread = new MycatReactorThread(defaultReactorBufferPool, new MycatSessionManager(function));
        thread.start();
        list.add(thread);
    }
    this.reactorManager = new ReactorThreadManager(list);
    NIOAcceptor acceptor = new NIOAcceptor(reactorManager);
    acceptor.startServerChannel(serverConfig.getIp(), serverConfig.getPort());
    LOGGER.info("mycat starts successful");
}
Also used : java.util(java.util) ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) MySQLAutoCommit(io.mycat.beans.mysql.MySQLAutoCommit) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) DefaultReactorBufferPool(io.mycat.buffer.DefaultReactorBufferPool) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) JDBCType(java.sql.JDBCType) RowBaseIterator(io.mycat.api.collector.RowBaseIterator) io.mycat.proxy.reactor(io.mycat.proxy.reactor) Logger(org.slf4j.Logger) io.mycat.config(io.mycat.config) Timestamp(java.sql.Timestamp) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) io.mycat.proxy.session(io.mycat.proxy.session) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) MySQLDatasource(io.mycat.beans.MySQLDatasource) CommandDispatcher(io.mycat.command.CommandDispatcher) MySQLDatasourcePool(io.mycat.proxy.MySQLDatasourcePool) ReplicaSelectorManager(io.mycat.replica.ReplicaSelectorManager) NotNull(org.jetbrains.annotations.NotNull) DefaultReactorBufferPool(io.mycat.buffer.DefaultReactorBufferPool) IOException(java.io.IOException) CommandDispatcher(io.mycat.command.CommandDispatcher)

Aggregations

RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 MySQLDatasource (io.mycat.beans.MySQLDatasource)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 MySQLAutoCommit (io.mycat.beans.mysql.MySQLAutoCommit)1 DefaultReactorBufferPool (io.mycat.buffer.DefaultReactorBufferPool)1 CommandDispatcher (io.mycat.command.CommandDispatcher)1 io.mycat.config (io.mycat.config)1 MySQLDatasourcePool (io.mycat.proxy.MySQLDatasourcePool)1 io.mycat.proxy.reactor (io.mycat.proxy.reactor)1 io.mycat.proxy.session (io.mycat.proxy.session)1 ReplicaSelectorManager (io.mycat.replica.ReplicaSelectorManager)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 JDBCType (java.sql.JDBCType)1 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1