PortMapper: Add convenience methods

This commit is contained in:
zzz
2018-03-19 17:00:44 +00:00
parent bdff474d94
commit 129188f3cc

View File

@ -114,6 +114,15 @@ public class PortMapper {
return _dir.putIfAbsent(service, InetSocketAddress.createUnresolved(host, port)) == null;
}
/**
* Is the service registered?
*
* @since 0.9.34
*/
public boolean isRegistered(String service) {
return _dir.containsKey(service);
}
/**
* Remove the service
*/
@ -121,6 +130,18 @@ public class PortMapper {
_dir.remove(service);
}
/**
* Remove the service,
* only if it is registered with the supplied port.
*
* @since 0.9.34
*/
public void unregister(String service, int port) {
// not synched
if (getPort(service) == port)
_dir.remove(service);
}
/**
* Get the registered port for a service
* @return -1 if not registered