use of io.mycat.command.CommandDispatcher 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");
}
Aggregations