- 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 Summary
Modifier and TypeMethodDescriptionvoidaddCloseListener(CloseListener closeListener) Add theCloseListener, which will be notified once the stream will be closed.voidChecks if this Closeable is open and ready to be used.close()Gracefully (if supported by the implementation) closes this stream and releases any system resources associated with it.voidclose(CompletionHandler<Closeable> completionHandler) Deprecated.voidGracefully (if supported by the implementation) closes this stream and releases any system resources associated with it.voidcloseWithReason(IOException cause) Gracefully closes the Closeable and provides the reason description.booleanisOpen()Is Closeable open and ready.booleanremoveCloseListener(CloseListener closeListener) Remove theCloseListener.Closes this stream and releases any system resources associated with it.voidCloses this stream and releases any system resources associated with it.voidterminateWithReason(IOException cause) Closes the Closeable and provides the reason description.
-
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
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
Closes the Closeable and provides the reason description. This method is similar toterminateSilently(), but additionally provides the reason why the Closeable will be closed.- Parameters:
cause- reason why terminated. This will be thrown isisOpen()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
GrizzlyFuture<Closeable> 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.please useclose()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)callGracefully 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-CompletionHandlerto be called, when the stream is closed
-
closeWithReason
Gracefully closes the Closeable and provides the reason description. This method is similar tocloseSilently(), but additionally provides the reason why the Closeable will be closed.- Parameters:
cause- reason why closed, this will be thrown byisOpen()if called subsequently
-
addCloseListener
Add theCloseListener, which will be notified once the stream will be closed.- Parameters:
closeListener-CloseListener.
-
removeCloseListener
Remove theCloseListener.- 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
-
close()with the followingGrizzlyFuture.addCompletionHandler(org.glassfish.grizzly.CompletionHandler)call