Class PortManager.PortRef
java.lang.Object
org.terracotta.utilities.test.net.PortManager.PortRef
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
- PortManager
Represents a reserved TCP port. When use of the port is no longer needed, this
reference should be closed to release the reservation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final AtomicReference<IntConsumer>private final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes thisPortRef.private AtomicReference<IntConsumer>closers()Gets the "closers"AtomicReferencefor use during weak-reference release.booleanisClosed()Returns whether or not thisPortRefis closed.(package private) voidonClose(IntConsumer action) Prepends a close action to thisPortRef.intport()Gets the reserved port number.
-
Field Details
-
port
private final int port -
closers
-
closed
-
-
Constructor Details
-
PortRef
private PortRef(int port)
-
-
Method Details
-
onClose
Prepends a close action to thisPortRef. Actions are executed in reverse order of their addition. Each action is passed the port number being closed.- Parameters:
action- the action to take to close thisPortRefinstance
-
closers
Gets the "closers"AtomicReferencefor use during weak-reference release.- Returns:
- the
AtomicReferenceinstance to call for closing thisPortRef
-
port
public int port()Gets the reserved port number.- Returns:
- the port number
-
isClosed
public boolean isClosed()Returns whether or not thisPortRefis closed.- Returns:
trueif thisPortRefhas been closed;falseotherwise
-
close
public void close()Closes thisPortRef.- Specified by:
closein interfaceAutoCloseable
-