Interface Closeable

All Known Subinterfaces:
Connection<L>
All Known Implementing Classes:
NIOConnection, TCPNIOConnection, TCPNIOServerConnection, UDPNIOConnection, UDPNIOServerConnection

public interface Closeable
General asynchronous closable interface. Closeable interface contains two sets of methods: close* and terminate*, so interface implementations can provide graceful and abrupt releasing of resources.
Author:
Alexey Stashok
See Also:
  • Method Details

    • isOpen

      boolean isOpen()
      Is Closeable open and ready. Returns true, if the Closeable is open and ready, or false otherwise.
      Returns:
      true, if Closeable is open and ready, or false otherwise.
    • assertOpen

      void assertOpen() throws IOException
      Checks if this Closeable is open and ready to be used. If this Closeable is closed then an IOException will be thrown
      Throws:
      IOException - giving the reason why this Closeable was closed.
    • terminateSilently

      void terminateSilently()
      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. Use this method, when no completion notification is needed.
    • terminate

      GrizzlyFuture<Closeable> terminate()
      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Returns:
      Future, which could be checked in case, if close operation will be run asynchronously
    • terminateWithReason

      void terminateWithReason(IOException cause)
      Closes the Closeable and provides the reason description. This method is similar to terminateSilently(), but additionally provides the reason why the Closeable will be closed.
      Parameters:
      cause - reason why terminated. This will be thrown is isOpen() is called subsequently
    • closeSilently

      void closeSilently()
      Gracefully (if supported by the implementation) closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. Use this method, when no completion notification is needed.
    • close

      Gracefully (if supported by the implementation) closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Returns:
      Future, which could be checked in case, if close operation will be run asynchronously
      See Also:
    • close

      @Deprecated void close(CompletionHandler<Closeable> completionHandler)
      Gracefully closes this stream and releases any system resources associated with it. This operation waits for all pending output data to be flushed before closing the stream. If the stream is already closed then invoking this method has no effect.
      Parameters:
      completionHandler - CompletionHandler to be called, when the stream is closed
    • closeWithReason

      void closeWithReason(IOException cause)
      Gracefully closes the Closeable and provides the reason description. This method is similar to closeSilently(), but additionally provides the reason why the Closeable will be closed.
      Parameters:
      cause - reason why closed, this will be thrown by isOpen() if called subsequently
    • addCloseListener

      void addCloseListener(CloseListener closeListener)
      Add the CloseListener, which will be notified once the stream will be closed.
      Parameters:
      closeListener - CloseListener.
    • removeCloseListener

      boolean removeCloseListener(CloseListener closeListener)
      Remove the CloseListener.
      Parameters:
      closeListener - CloseListener.
      Returns:
      true if the listener was successfully removed, or false otherwise.
    • closeFuture

      GrizzlyFuture<CloseReason> closeFuture()
      Returns:
      the Future, that will be notified once this Closeable is closed
      Since:
      2.3.24