Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Asynchronous hostname lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Nov 6, 2014
1 parent 7832b11 commit 4c3968f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -1204,22 +1204,27 @@ public String getPlayerHost(Player player) {
if (hostCache.containsKey(playerIP)) {
return hostCache.get(playerIP);
} else {
getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
@Override
public void run() {
logDebug("Asynchronously looking up hostname for " + playerIP);
long a = System.currentTimeMillis();
InetAddress addr = null;
try {
addr = InetAddress.getByName(playerIP);
} catch (UnknownHostException ex) {
logError(ex.getMessage());
}
String host;
if (addr != null) {
hostCache.put(playerIP, addr.getHostName());
host = addr.getHostName();
} else {
host = playerIP;
}
hostCache.put(playerIP, host);
logDebug("getPlayerHost[" + (System.currentTimeMillis() - a) + "ms] " + playerIP + " = " + host);
}
}, 5);
return "";
}, 0);
return playerIP;
}
}

Expand Down

0 comments on commit 4c3968f

Please sign in to comment.