dlmarion commented on code in PR #6454: URL: https://github.com/apache/accumulo/pull/6454#discussion_r3551511188
########## server/base/src/main/java/org/apache/accumulo/server/rpc/ThriftServerEventHandler.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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.accumulo.server.rpc; + +import java.net.SocketAddress; + +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.server.ServerContext; +import org.apache.thrift.server.TServerEventHandler; +import org.apache.thrift.transport.TTransport; + +public class ThriftServerEventHandler implements TServerEventHandler { + + public static class ThriftServerContext implements ServerContext { + + @Override + public <T> T unwrap(Class<T> iface) { + return null; Review Comment: I think we should throw an `UnsupportedOperationException` here. According to the ServerContext javadoc, this is the correct action. https://github.com/apache/thrift/blob/master/lib/java/src/main/java/org/apache/thrift/server/ServerContext.java#L35 ########## server/base/src/main/java/org/apache/accumulo/server/rpc/ThriftServerEventHandler.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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.accumulo.server.rpc; + +import java.net.SocketAddress; + +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.server.ServerContext; +import org.apache.thrift.server.TServerEventHandler; +import org.apache.thrift.transport.TTransport; + +public class ThriftServerEventHandler implements TServerEventHandler { + + public static class ThriftServerContext implements ServerContext { + + @Override + public <T> T unwrap(Class<T> iface) { + return null; + } + + @Override + public boolean isWrapperFor(Class<?> iface) { + return false; + } + + @Override + public void setRemoteAddress(SocketAddress remoteAddress) { + TServerUtils.clientAddress.set(remoteAddress.toString()); + } + + } + + @Override + public void preServe() {} + + @Override + public ServerContext createContext(TProtocol input, TProtocol output) { + return new ThriftServerContext(); Review Comment: Based on the TServerEventHandler javadoc, and the fact that we are only manipulating a ThreadLocal, we can probably just return a reference to a static ThriftServerContext object. Suggest adding the following at the top of this class, then just `return context;` here. ``` private static final ThriftServerContext context = new ThriftServerContext(); ``` https://github.com/apache/thrift/blob/master/lib/java/src/main/java/org/apache/thrift/server/TServerEventHandler.java ########## server/base/src/main/java/org/apache/accumulo/server/rpc/ThriftServerEventHandler.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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.accumulo.server.rpc; + +import java.net.SocketAddress; + +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.server.ServerContext; +import org.apache.thrift.server.TServerEventHandler; +import org.apache.thrift.transport.TTransport; + +public class ThriftServerEventHandler implements TServerEventHandler { + + public static class ThriftServerContext implements ServerContext { + + @Override + public <T> T unwrap(Class<T> iface) { + return null; + } + + @Override + public boolean isWrapperFor(Class<?> iface) { + return false; + } + + @Override + public void setRemoteAddress(SocketAddress remoteAddress) { + TServerUtils.clientAddress.set(remoteAddress.toString()); + } + + } + + @Override + public void preServe() {} + + @Override + public ServerContext createContext(TProtocol input, TProtocol output) { + return new ThriftServerContext(); + } + + @Override + public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) { + TServerUtils.clientAddress.set(""); Review Comment: It might make sense to add the following to ThriftServerContext and call it here. That way the calls to TServerUtils.clientAddress are localized to one class. ``` public void clear() { TServerUtils.clientAddress.set(""); } ``` ########## server/base/src/main/java/org/apache/accumulo/server/rpc/TServerUtils.java: ########## @@ -225,7 +228,10 @@ private static ServerAddress createNonBlockingServer(HostAndPort address, TProce address = HostAndPort.fromParts(address.getHost(), transport.getPort()); } - return new ServerAddress(new CustomNonBlockingServer(options), address); + CustomNonBlockingServer server = new CustomNonBlockingServer(options); Review Comment: It appears the CustomNonBlockingServer is also custom solely to get the client address. We might be able to remove this as well. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
