sabbey37 commented on a change in pull request #6346: URL: https://github.com/apache/geode/pull/6346#discussion_r616792137
########## File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/RedisProxyInboundHandler.java ########## @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.redis.internal.proxy; + +import java.util.Map; + +import io.netty.bootstrap.Bootstrap; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.redis.ArrayRedisMessage; +import io.netty.handler.codec.redis.FullBulkStringRedisMessage; +import io.netty.handler.codec.redis.RedisArrayAggregator; +import io.netty.handler.codec.redis.RedisBulkStringAggregator; +import io.netty.handler.codec.redis.RedisDecoder; +import io.netty.handler.codec.redis.RedisEncoder; +import io.netty.util.CharsetUtil; +import org.apache.logging.log4j.Logger; + +import org.apache.geode.logging.internal.log4j.api.LogService; + +public class RedisProxyInboundHandler extends ChannelInboundHandlerAdapter { + + private static final Logger logger = LogService.getLogger(); + private final String remoteHost; + private final int remotePort; + private final Map<HostPort, HostPort> mappings; + private Channel outboundChannel; + private RedisProxyOutboundHandler outboundHandler; + private final ClusterSlotsResponseProcessor slotsResponseProcessor; + private final ClusterNodesResponseProcessor nodesResponseProcessor; + private MovedResponseHandler movedResponseHandler; + + public RedisProxyInboundHandler(String remoteHost, int remotePort, + Map<HostPort, HostPort> mappings) { + this.remoteHost = remoteHost; + this.remotePort = remotePort; + this.mappings = mappings; + this.slotsResponseProcessor = new ClusterSlotsResponseProcessor(mappings); + this.nodesResponseProcessor = new ClusterNodesResponseProcessor(mappings); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) { + Channel inboundChannel = ctx.channel(); + outboundHandler = new RedisProxyOutboundHandler(inboundChannel); + movedResponseHandler = new MovedResponseHandler(inboundChannel, mappings); + + // Start the connection attempt. + Bootstrap b = new Bootstrap(); + b.group(inboundChannel.eventLoop()) + .channel(ctx.channel().getClass()) + .handler(new ChannelInitializer<SocketChannel>() { + @Override + protected void initChannel(SocketChannel ch) throws Exception { Review comment: I don't think we need the `throws Exception` here any longer. ########## File path: geode-apis-compatible-with-redis/src/commonTest/java/org/apache/geode/redis/internal/proxy/MovedResponseHandler.java ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.redis.internal.proxy; + +import java.util.Map; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.redis.ErrorRedisMessage; + +public class MovedResponseHandler extends ChannelInboundHandlerAdapter { + + private final Map<HostPort, HostPort> mappings; + private final Channel inboundChannel; + + public MovedResponseHandler(Channel inboundChannel, Map<HostPort, HostPort> mappings) { + this.inboundChannel = inboundChannel; + this.mappings = mappings; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Review comment: I don't think we need the `throws Exception` here any longer. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
