package alluxio.master.file;

import alluxio.thrift.FileSystemMasterClientService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSaslServerTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class FileSystemMasterClientServiceProcessor extends FileSystemMasterClientService.Processor {
  private static ThreadLocal<String> mClientIpThreadLocal;

  public FileSystemMasterClientServiceProcessor(FileSystemMasterClientService.Iface handler) {
    super(handler);
    mClientIpThreadLocal = new ThreadLocal<>();
  }

  public static String getClientIpThreadLocal() { return mClientIpThreadLocal.get(); }

  @Override
  public boolean process(TProtocol in, TProtocol out) throws TException {
    TTransport transport = in.getTransport();
    if (transport instanceof TSaslServerTransport) {
      transport = ((TSaslServerTransport) transport).getUnderlyingTransport();
    }
    if (transport instanceof TSocket) {
      String ip = ((TSocket) transport).getSocket().getInetAddress().toString();
      mClientIpThreadLocal.set(ip);
    } else {
      mClientIpThreadLocal.set(null);
    }
    return super.process(in, out);
  }
}

@@ -307,16 +307,1059 @@
 sport;%0A%0A
+/**%0A * Alluxio customized Thrift processor to handle RPC and track client IP.%0A *%0A * Original Thrift framework does not expose client IP because:%0A * a) there is no such interface to query IP.%0A * b) IP is not stored by Thrift.%0A * c) The last stop from Thrift framework into Alluxio land is the%0A *    %7B@link org.apache.thrift.ProcessFunction#process%7D method of%0A *    %7B@link org.apache.thrift.ProcessFunction%7D class. This method has the information of in%0A *    protocol from which we can derive IP. However, this method is made final deliberately.%0A *    Consequently, it is very hard to subclass %7B@link org.apache.thrift.ProcessFunction%7D%0A *    and override process method to pass IP informaton to Alluxio via arguments.%0A * Based on a), b) and c), we decide to subclass the auto-generated%0A * %7B@link FileSystemMasterClientService.Processor%7D class and%0A * override its %7B@link org.apache.thrift.ProcessFunction#process%7D method. In this method, we store%0A * the client IP as a thread-local variable for future use by %7B@link DefaultFileSystemMaster%7D.%0A */%0A
 public c

Add java doc to a class.