public class PortManagerImpl extends Object implements PortManager
Constructor and Description |
---|
PortManagerImpl() |
Modifier and Type | Method and Description |
---|---|
Integer |
bindAnyPort()
Any free port in the range of
#MIN_DYNAMIC_PORT_NUMBER and
#MAX_AUTO_PORT_NUMBER is bound (reserved) and returned. |
Integer |
bindNextPort(int aBeginPortIndex,
int aEndPortIndex)
The first free port in the range of the given begin Port-Number index and
the given end Port-Number index is bound (reserved) and returned.
|
Integer |
bindPort(int aPortNumber)
The port is bound and returned.
|
boolean |
isPortAvaialble(int aPortNumber)
This implementation blocks any port being tested which is already bound.
|
boolean |
isPortBound(int aPortNumber)
Determines whether the given Port-Number is already in use.
|
boolean |
unbindPort(Integer aPortNumber)
Unbinds a port for the given Port-Number using the
Integer as
handle for unbinding. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
bindNextPort, bindNextPort
public boolean isPortBound(int aPortNumber)
PortManager
PortManager.bindPort(int)
, PortManager.bindAnyPort()
or
PortManager.bindNextPort(int)
) or if the port is already in use and cannot
be bound, e.g. there is already some Server-Socket technically bound to
the given port.isPortBound
in interface PortManager
aPortNumber
- The port number to be tested if it is already bound.public Integer bindAnyPort() throws PortNotFoundRuntimeException
PortManager
#MIN_DYNAMIC_PORT_NUMBER
and
#MAX_AUTO_PORT_NUMBER
is bound (reserved) and returned. A port is
aught to be free when PortManager.isPortBound(int)
returns false.bindAnyPort
in interface PortManager
Integer
instance is the
handle for unbinding a port via PortManager.unbindPort(Integer)
.PortNotFoundRuntimeException
- thrown in case no port can be
determined.public Integer bindPort(int aPortNumber) throws PortAlreadyBoundException
PortManager
PortManager.isPortBound(int)
returns false.bindPort
in interface PortManager
aPortNumber
- The Port-Number which to bind (reserve).Integer
instance is the
handle for unbinding a port via PortManager.unbindPort(Integer)
.PortAlreadyBoundException
public boolean unbindPort(Integer aPortNumber) throws IllegalArgumentException
PortManager
Integer
as
handle for unbinding. This means that another Integer
instance
with another identity fails to unbind the given port.unbindPort
in interface PortManager
aPortNumber
- The Port-Number for the port to be unbound.IllegalArgumentException
- thrown in case the ginven
Integer
identity is not allowed to unbind the given port.public Integer bindNextPort(int aBeginPortIndex, int aEndPortIndex) throws PortNotFoundRuntimeException
PortManager
PortManager.isPortBound(int)
returns false.bindNextPort
in interface PortManager
aBeginPortIndex
- The begin index (included) of the Port-Number
which to bind (reserve).aEndPortIndex
- The end index (included) of the Port-Number which to
bind (reserve).Integer
instance
is the handle for unbinding a port via
PortManager.unbindPort(Integer)
.PortNotFoundRuntimeException
- thrown in case no port can be
determined.public boolean isPortAvaialble(int aPortNumber)
isPortAvaialble
in interface PortManager
aPortNumber
- The Port-Number to be technically tested if a
Server-Socket could still bind to it.Copyright © 2017. All rights reserved.