@Override public void channelReleased(final Channel channel) { log.info("channelReleased. Channel ID: {}" + channel.id().asShortText()); }
@Override public void channelReleased(final Channel channel) { log.info("channelReleased. Channel ID: {}" + channel.id().asShortText()); }
@Override @Nullable protected String initId() { return this.request instanceof Connection ? ((Connection) this.request).channel().id().asShortText() : null; }
@Override public void channelCreated(final Channel channel) { log.info("channelCreated. Channel ID: {}" + channel.id().asShortText()); channel.pipeline().addLast(new BackendNettyClientChannelInitializer(dataSourceName, schemaName)); } }
protected void gracefulConnectionShutdown(Channel channel) { if (channel.isActive()) { LOG.debug("gracefullyWithDelay: firing graceful_shutdown event to make netty send a final go_away frame and then close connection. channel=" + channel.id().asShortText()); Http2Exception h2e = new Http2Exception(Http2Error.NO_ERROR, Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN); channel.pipeline().fireExceptionCaught(h2e); } else { LOG.debug("gracefullyWithDelay: connection already closed, so no need to send final go_away frame. channel=" + channel.id().asShortText()); } }
@Override protected final void encode(final ChannelHandlerContext context, final T message, final ByteBuf out) { doEncode(context, message, out); if (log.isDebugEnabled()) { log.debug("Write to client {} : \n {}", context.channel().id().asShortText(), ByteBufUtil.prettyHexDump(out)); } }
@Override protected final void decode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out) { int readableBytes = in.readableBytes(); if (!isValidHeader(readableBytes)) { return; } if (log.isDebugEnabled()) { log.debug("Read from client {} : \n {}", context.channel().id().asShortText(), ByteBufUtil.prettyHexDump(in)); } doDecode(context, in, out, readableBytes); }
private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException { if (!channelMap.containsKey(dataSourceName)) { channelMap.put(dataSourceName, new ArrayList<Channel>()); } SimpleChannelPool pool = CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(dataSourceName); Channel channel = pool.acquire().get(GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS); channelMap.get(dataSourceName).add(channel); ChannelRegistry.getInstance().putConnectionId(channel.id().asShortText(), connectionId); channel.writeAndFlush(new ComQueryPacket(sequenceId, sql)); }
private void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); mysqlQueryResult.setGenericResponse(new OKPacket(payload)); resultMap.put(connectionId, mysqlQueryResult); setResponse(context); } finally { resultMap.remove(connectionId); } }
private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException { if (!channelMap.containsKey(dataSourceName)) { channelMap.put(dataSourceName, new ArrayList<Channel>()); } SimpleChannelPool pool = CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(dataSourceName); Channel channel = pool.acquire().get(GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS); channelMap.get(dataSourceName).add(channel); ChannelRegistry.getInstance().putConnectionId(channel.id().asShortText(), connectionId); channel.writeAndFlush(new ComQueryPacket(sequenceId, sql)); }
private void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); mysqlQueryResult.setGenericResponse(new ErrPacket(payload)); resultMap.put(connectionId, mysqlQueryResult); setResponse(context); } finally { resultMap.remove(connectionId); } }
private void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); mysqlQueryResult.setGenericResponse(new ErrPacket(payload)); resultMap.put(connectionId, mysqlQueryResult); setResponse(context); } finally { resultMap.remove(connectionId); } }
protected void gracefulConnectionShutdown(Channel channel) { if (channel.isActive()) { LOG.debug("gracefullyWithDelay: firing graceful_shutdown event to make netty send a final go_away frame and then close connection. channel=" + channel.id().asShortText()); Http2Exception h2e = new Http2Exception(Http2Error.NO_ERROR, Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN); channel.pipeline().fireExceptionCaught(h2e); } else { LOG.debug("gracefullyWithDelay: connection already closed, so no need to send final go_away frame. channel=" + channel.id().asShortText()); } }
private void setResponse(final ChannelHandlerContext context) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); if (null != FutureRegistry.getInstance().get(connectionId)) { FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); } }
private void setResponse(final ChannelHandlerContext context) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); if (null != FutureRegistry.getInstance().get(connectionId)) { FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); } }
@Override protected void handshake(final ChannelHandlerContext context) { int connectionId = ConnectionIdGenerator.getInstance().nextId(); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), connectionId); getBackendConnection().setConnectionId(connectionId); context.writeAndFlush(new HandshakePacket(connectionId, authenticationHandler.getAuthPluginData())); }
@Override protected void handshake(final ChannelHandlerContext context) { int connectionId = PostgreSQLConnectionIdGenerator.getInstance().nextId(); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), connectionId); getBackendConnection().setConnectionId(connectionId); }
@Override protected void handshake(final ChannelHandlerContext context) { int connectionId = ConnectionIdGenerator.getInstance().nextId(); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), connectionId); getBackendConnection().setConnectionId(connectionId); context.writeAndFlush(new HandshakePacket(connectionId, authenticationHandler.getAuthPluginData())); }
@Override protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) { try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { HandshakePacket handshakePacket = new HandshakePacket(payload); byte[] authResponse = securePasswordAuthentication( (null == dataSourceParameter.getPassword() ? "" : dataSourceParameter.getPassword()).getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet( handshakePacket.getSequenceId() + 1, CapabilityFlag.calculateHandshakeCapabilityFlagsLower(), 16777215, ServerInfo.CHARSET, dataSourceParameter.getUsername(), authResponse, dataSourceMetaData.getSchemaName()); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); } }
@Override protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) { try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { HandshakePacket handshakePacket = new HandshakePacket(payload); byte[] authResponse = securePasswordAuthentication( (null == dataSourceParameter.getPassword() ? "" : dataSourceParameter.getPassword()).getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet( handshakePacket.getSequenceId() + 1, CapabilityFlag.calculateHandshakeCapabilityFlagsLower(), 16777215, ServerInfo.CHARSET, dataSourceParameter.getUsername(), authResponse, dataSourceMetaData.getSchemaName()); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); } }