Class PortManager.PortRef
- java.lang.Object
-
- org.terracotta.utilities.test.net.PortManager.PortRef
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Enclosing class:
- PortManager
public static class PortManager.PortRef extends java.lang.Object implements java.lang.AutoCloseableRepresents a reserved TCP port. When use of the port is no longer needed, this reference should be closed to release the reservation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPortManager.PortRef.CloseOptionOptions that may be used withclose(Set).
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleanclosedprivate java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>>>closersprivate intport
-
Constructor Summary
Constructors Modifier Constructor Description privatePortRef(int port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes thisPortRef.voidclose(java.util.Set<PortManager.PortRef.CloseOption> options)Closes thisPortRefusing the options provided.private java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>>>closers()Gets the "closers"AtomicReferencefor use during weak-reference release.booleanisClosed()Returns whether or not thisPortRefis closed.(package private) voidonClose(java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>> action)Prepends a close action to thisPortRef.intport()Gets the reserved port number.
-
-
-
Field Detail
-
port
private final int port
-
closers
private final java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>>> closers
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
-
Method Detail
-
onClose
void onClose(java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>> action)
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
private java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,java.util.Set<PortManager.PortRef.CloseOption>>> 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 interfacejava.lang.AutoCloseable
-
close
public void close(java.util.Set<PortManager.PortRef.CloseOption> options)
Closes thisPortRefusing the options provided.- Parameters:
options- the set ofPortManager.PortRef.CloseOptions to apply to this close call; may be empty but notnull
-
-