Class PortManager.PortRef

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Enclosing class:
    PortManager

    public static class PortManager.PortRef
    extends java.lang.Object
    implements java.lang.AutoCloseable
    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

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicBoolean closed  
      private java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,​java.util.Set<PortManager.PortRef.CloseOption>>> closers  
      private int port  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PortRef​(int port)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this PortRef.
      void close​(java.util.Set<PortManager.PortRef.CloseOption> options)
      Closes this PortRef using 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" AtomicReference for use during weak-reference release.
      boolean isClosed()
      Returns whether or not this PortRef is closed.
      (package private) void onClose​(java.util.function.BiConsumer<java.lang.Integer,​java.util.Set<PortManager.PortRef.CloseOption>> action)
      Prepends a close action to this PortRef.
      int port()
      Gets the reserved port number.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • PortRef

        private PortRef​(int port)
    • Method Detail

      • onClose

        void onClose​(java.util.function.BiConsumer<java.lang.Integer,​java.util.Set<PortManager.PortRef.CloseOption>> action)
        Prepends a close action to this PortRef. 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 this PortRef instance
      • closers

        private java.util.concurrent.atomic.AtomicReference<java.util.function.BiConsumer<java.lang.Integer,​java.util.Set<PortManager.PortRef.CloseOption>>> closers()
        Gets the "closers" AtomicReference for use during weak-reference release.
        Returns:
        the AtomicReference instance to call for closing this PortRef
      • port

        public int port()
        Gets the reserved port number.
        Returns:
        the port number
      • isClosed

        public boolean isClosed()
        Returns whether or not this PortRef is closed.
        Returns:
        true if this PortRef has been closed; false otherwise
      • close

        public void close()
        Closes this PortRef.
        Specified by:
        close in interface java.lang.AutoCloseable