From 31a77f91cf34bb05e12fdf6e70410923230f68aa Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Tue, 17 May 2011 17:41:14 +0000 Subject: [PATCH] HADOOP-7282. ipc.Server.getRemoteIp() may return null. Contributed by John George git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1104426 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ src/java/org/apache/hadoop/ipc/Server.java | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1619f6c472c..a1d4a9e523e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -226,6 +226,9 @@ Trunk (unreleased changes) HADOOP-7292. Fix racy test case TestSinkQueue. (Luke Lu via todd) + HADOOP-7282. ipc.Server.getRemoteIp() may return null. (John George + via szetszwo) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/ipc/Server.java b/src/java/org/apache/hadoop/ipc/Server.java index e2dd1f099f0..83c5a354eb1 100644 --- a/src/java/org/apache/hadoop/ipc/Server.java +++ b/src/java/org/apache/hadoop/ipc/Server.java @@ -154,7 +154,7 @@ public abstract class Server { public static InetAddress getRemoteIp() { Call call = CurCall.get(); if (call != null) { - return call.connection.socket.getInetAddress(); + return call.connection.getHostInetAddress(); } return null; } @@ -166,6 +166,13 @@ public abstract class Server { return (addr == null) ? null : addr.getHostAddress(); } + + /** Return true if the invocation was through an RPC. + */ + public static boolean isRpcInvocation() { + return CurCall.get() != null; + } + private String bindAddress; private int port; // port we listen on private int handlerCount; // number of handler threads