Performs a slow search of the IP used by the given client. This is needed when we're trying to find the IP of the client before its channel has successfully connected, because Netty's API offers no way of retrieving the IP of the remote peer until we're connected to it. @param client The client
(final RegionClient client)
| 3952 | * @return The IP of the client, or {@code null} if we couldn't find it. |
| 3953 | */ |
| 3954 | private InetSocketAddress slowSearchClientIP(final RegionClient client) { |
| 3955 | String hostport = null; |
| 3956 | synchronized (ip2client) { |
| 3957 | for (final Map.Entry<String, RegionClient> e : ip2client.entrySet()) { |
| 3958 | if (e.getValue() == client) { |
| 3959 | hostport = e.getKey(); |
| 3960 | break; |
| 3961 | } |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | if (hostport == null) { |
| 3966 | HashMap<String, RegionClient> copy; |
| 3967 | synchronized (ip2client) { |
| 3968 | copy = new HashMap<String, RegionClient>(ip2client); |
| 3969 | } |
| 3970 | LOG.error("WTF? Should never happen! Couldn't find " + client |
| 3971 | + " in " + copy); |
| 3972 | return null; |
| 3973 | } |
| 3974 | |
| 3975 | LOG.warn("Couldn't connect to the RegionServer @ " + hostport); |
| 3976 | final int lastColon = hostport.lastIndexOf(':'); |
| 3977 | if (lastColon < 1) { |
| 3978 | LOG.error("WTF? Should never happen! No `:' found in " + hostport); |
| 3979 | return null; |
| 3980 | } |
| 3981 | final String host = getIP(hostport.substring(0, lastColon)); |
| 3982 | int port; |
| 3983 | try { |
| 3984 | port = parsePortNumber(hostport.substring(lastColon + 1, |
| 3985 | hostport.length())); |
| 3986 | } catch (NumberFormatException e) { |
| 3987 | LOG.error("WTF? Should never happen! Bad port in " + hostport, e); |
| 3988 | return null; |
| 3989 | } |
| 3990 | return new InetSocketAddress(host, port); |
| 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * Removes all the cache entries referred to the given client. |
no test coverage detected