Top Description Constructors Methods
io.netty5.util.internal

public final Class SilentDispose

extends Object
Class Inheritance
Imports
io.netty5.util.ReferenceCounted, .Resource, io.netty5.util.internal.logging.InternalLogger

Utility class for disposing of resources without propagating any exception that Resource#close() might throw.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AutoCloseable

Returns:

An AutoCloseable that will dispose of the given object when closed.
autoClosing
(Object
The object to dispose of.
obj
)

Return an AutoCloseable for the given object, which can be used to dispose of it using a try-with-resources clause.

public static void
dispose(Object
The object to dispose of.
obj
,
InternalLogger
The logger to use for recording any exceptions thrown by the disposal.
logger
)

Attempt to dispose of whatever the given object is.

public static void
tryPropagatingDispose(Object
The object to dispose of.
obj
)

Attempt to dispose of whatever the given object is, but only if it is disposable.

public static void
trySilentDispose(Object
The object to dispose of.
obj
,
InternalLogger
The logger to use for recording any exceptions thrown by the disposal.
logger
)

Attempt to dispose of whatever the given object is, but only if it is disposable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SilentDisposeback to summary
private SilentDispose()

Method Detail

autoClosingback to summary
public static AutoCloseable autoClosing(Object obj)

Return an AutoCloseable for the given object, which can be used to dispose of it using a try-with-resources clause.

The benefit of this approach is that exceptions are correctly handled if both the try-body, and the resource disposal, throws.

This is not a silent operation, in that exceptions from resource disposal will propagate. However, the try-with-resources clause will guarantee that resource disposal exceptions won't shadow any exceptions from the try-body

Parameters
obj:Object

The object to dispose of.

Returns:AutoCloseable

An AutoCloseable that will dispose of the given object when closed.

disposeback to summary
public static void dispose(Object obj, InternalLogger logger)

Attempt to dispose of whatever the given object is.

This method works similarly to Resource#dispose(Object), except any exception thrown will be logged instead of propagated.

If the object is AutoCloseable, such as anything that implements Resource, then it will be closed. If the object is ReferenceCounted, then it will be released once.

Any exceptions caused by this will be logged using the given logger. The exception will be logged at log-level WARN.

Parameters
obj:Object

The object to dispose of.

logger:InternalLogger

The logger to use for recording any exceptions thrown by the disposal.

tryPropagatingDisposeback to summary
public static void tryPropagatingDispose(Object obj)

Attempt to dispose of whatever the given object is, but only if it is disposable.

This method works similarly to Resource#dispose(Object), except the object is only disposed of if it is accessible.

Any exceptions caused the disposal will be allowed to propagate from this method, which is in contrast to how dispose(Object, InternalLogger) and trySilentDispose(Object, InternalLogger) works.

Parameters
obj:Object

The object to dispose of.

trySilentDisposeback to summary
public static void trySilentDispose(Object obj, InternalLogger logger)

Attempt to dispose of whatever the given object is, but only if it is disposable.

This method works similarly to dispose(Object, InternalLogger), except the object is only disposed of if it is accessible.

Any exceptions caused by the disposal of the object will be logged using the given logger. The exception will be logged at log-level WARN.

Parameters
obj:Object

The object to dispose of.

logger:InternalLogger

The logger to use for recording any exceptions thrown by the disposal.