Top Description Methods
io.netty5.util

public Interface Resource<T extends io.netty5.util.Resource<T>>

extends AutoCloseable

A resource that has a life-time, and can be closed. Resources are initially accessible, but closing them makes them inaccessible.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.lang.AutoCloseable.close.

Close the resource, making it inaccessible.
public static void
dispose(Object
The object to dispose of.
obj
)

Attempt to dispose of whatever the given object is.

public boolean

Returns:

true if this object is still valid and can be accessed, otherwise false if, for instance, this object has been dropped/deallocated, or been sent elsewhere.
isAccessible
()

Check if this object is accessible.

public static boolean

Returns:

If the object is accessible.
isAccessible
(Object
The object to check.
obj
,
boolean
The value to return if the object is neither a resource, nor reference counted.
expectedDefault
)

Check if an object is accessible.

public Send<T>
send()

Send this object instance to another Thread, transferring the ownership to the recipient.

public default T

Returns:

This resource instance.
touch
(Object
An optional hint about this access and its context. May be null.
hint
)

Record the current access location for debugging purposes.

public static void
touch(Object
The object to annotate.
obj
,
Object
An optional hint about this access and its context. May be null.
hint
)

Record the current access location for debugging purposes.

Method Detail

closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Close the resource, making it inaccessible.

Note, this method is not thread-safe unless otherwise specified.

Annotations
@Override
Exceptions
IllegalStateException:
If this Resource has already been closed.
disposeback to summary
public static void dispose(Object obj)

Attempt to dispose of whatever the given object is.

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 left to bubble up, and checked exceptions will be wrapped in a RuntimeException.

Parameters
obj:Object

The object to dispose of.

isAccessibleback to summary
public boolean isAccessible()

Check if this object is accessible.

Returns:boolean

true if this object is still valid and can be accessed, otherwise false if, for instance, this object has been dropped/deallocated, or been sent elsewhere.

isAccessibleback to summary
public static boolean isAccessible(Object obj, boolean expectedDefault)

Check if an object is accessible. This returns true if the object is a resource that is accessible, or if the object is reference counted and has a positive reference count.

If the object is neither of these types, then the expected default value is returned.

Parameters
obj:Object

The object to check.

expectedDefault:boolean

The value to return if the object is neither a resource, nor reference counted.

Returns:boolean

If the object is accessible.

sendback to summary
public Send<T> send()

Send this object instance to another Thread, transferring the ownership to the recipient.

The object must be in a state where it can be sent, which includes at least being accessible.

When sent, this instance will immediately become inaccessible, as if by closing it. All attempts at accessing an object that has been sent, even if that object has not yet been received, should cause an exception to be thrown.

Calling close() on an object that has been sent will have no effect, so this method is safe to call within a try-with-resources statement.

touchback to summary
public default T touch(Object hint)

Record the current access location for debugging purposes. This information may be included if the resource throws a life-cycle related exception, or if it leaks. If this resource has already been closed, then this method has no effect.

Parameters
hint:Object

An optional hint about this access and its context. May be null.

Returns:T

This resource instance.

Annotations
@SuppressWarnings:unchecked
touchback to summary
public static void touch(Object obj, Object hint)

Record the current access location for debugging purposes. This information may be included if the resource throws a life-cycle related exception, or if it leaks. If this resource has already been closed, then this method has no effect.

If the given object is not a resource, or not reference counted, then this method has no effect.

Parameters
obj:Object

The object to annotate.

hint:Object

An optional hint about this access and its context. May be null.