代理分为前端和后端。
类 MetaDataContextsBuilder会根据配置文件构建数据的上下文,其中包括 前端和后端数据库类型。
调用流程 FrontendChannelInboundHandler
@Override public void channelRead(final ChannelHandlerContext context, final Object message) { if (!authenticated) { authenticated = authenticate(context, (ByteBuf) message); return; } ProxyStateContext.execute(context, message, databaseProtocolFrontendEngine, connectionSession); } 然后采用JDBC代理 JDBCOKProxyState,这里使用了一个异步线程去处理。
@Override public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final ConnectionSession connectionSession) { CommandExecutorTask commandExecutorTask = new CommandExecutorTask(databaseProtocolFrontendEngine, connectionSession, context, message); ExecutorService executorService = determineSuitableExecutorService(context, databaseProtocolFrontendEngine, connectionSession); executorService.execute(commandExecutorTask); } CommandExecutorTask
private boolean executeCommand(final ChannelHandlerContext context, final PacketPayload payload) throws SQLException { CommandExecuteEngine commandExecuteEngine = databaseProtocolFrontendEngine.
继续阅读