*/
protected ConcurrentLinkedQueue<NetworkMessage> _sendMessageQueue = new ConcurrentLinkedQueue<>();
+ /**
+ * Encapsulates a unique network host and the last time it was seen.
+ */
protected class LastSeenHost {
- long timeInMillis;
- InetSocketAddress address;
+ final long timeInMillis;
+ final InetSocketAddress address;
LastSeenHost(InetSocketAddress address, long timeInMillis) {
this.address = address;
this(host, System.currentTimeMillis());
}
+ /**
+ * Formatted string representation of IneAddress and timestamp.
+ * @return the representation
+ */
+ @Override
+ public String toString() {
+ return MessageFormat.format("{0}:{1,number,integer}@{2}", this.address.getHostString(), this.address.getPort(), this.timeInMillis);
+ }
};
/**
* Maps service _title to its parent network host.
protected static void log(Level level, String title, String message) {
if (LOGGER == null)
return;
- LOGGER.logp(level, title, null, MessageFormat.format("{1}", message));
+ LOGGER.logp(level, title, null, message);
}
/**
return result;
}
+ /**
+ * Get the current InetAddress of a target from the services map.
+ *
+ * @param target name of the service
+ * @return IP address and port of the service
+ */
+ public InetSocketAddress getTargetAddress(String target) {
+ InetSocketAddress result = null;
+
+ if (target != null && target.length() > 0) {
+ LastSeenHost host = this._serviceToHostMap.get(target);
+ if (host != null)
+ result = host.address;
+ }
+
+ return result;
+ }
+
/**
* Add a NetworkMessageEvent listener.
*