Top Description Methods
io.netty5.util

public Interface Send<T extends Resource<T>>

extends SafeCloseable
Known Direct Implementers
io.netty5.util.internal.SendFromSupplier
Imports
io.netty5.util.internal.SendFromSupplier, java.util.function.Function, .Supplier

A temporary holder of a Resource, used for transferring the ownership of the resource from one thread to another.

Prior to the Send being created, the originating resource is invalidated, to prevent access while it is being sent. This means it cannot be accessed, closed, or disposed of, while it is in-flight. Once the resource is received, the new ownership is established.

Care must be taken to ensure that the resource is always received by some thread. Failure to do so can result in a resource leak.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares io.netty5.util.SafeCloseable.close.

Discard this Send and the object it contains.
public static boolean

Returns:

true if the candidate object is a Send that would deliver an object of the given type, otherwise false.
isSendOf
(Class<?>
The type of object we wish to receive.
type
,
Object
The candidate object that might be a Send of an object of the given type.
candidate
)

Determine if the given candidate object is an instance of a Send from which an object of the given type can be received.

public default <
The result type of the mapping function.
R extends Resource<R>
>
Send<R>

Returns:

A new Send instance that will deliver an object that is the result of the mapping.
map
(Class<R>
The result type of the mapping function.
type
,
Function<T, R>
The mapping function to apply to the object being sent.
mapper
)

Apply a mapping function to the object being sent.

public T

Returns:

The sent resource instance, never null.
receive
()

Receive the Resource instance being sent, and bind its ownership to the calling thread.

public boolean

Returns:

true if the object received from this Send can be assigned fields or variables of the given type, otherwise false.
referentIsInstanceOf
(Class<?>
The type to check.
cls
)

Determine if the object received from this Send is an instance of the given class.

public static <
The type of object being sent.
T extends Resource<T>
>
Send<T>

Returns:

A Send which will deliver an object of the given type, from the supplier.
sending
(Class<T>
The concrete type of the object being sent. Specifically, the object returned from the Supplier#get() method must be an instance of this class.
concreteObjectType
,
Supplier<? extends T>
The supplier of the object being sent, which will be called when the object is ready to be received.
supplier
)

Construct a Send based on the given Supplier.

Method Detail

closeback to summary
public void close()

Redeclares io.netty5.util.SafeCloseable.close.

Discard this Send and the object it contains. This has no effect if the send-object has already been received.

Annotations
@Override
isSendOfback to summary
public static boolean isSendOf(Class<?> type, Object candidate)

Determine if the given candidate object is an instance of a Send from which an object of the given type can be received.

Parameters
type:Class<?>

The type of object we wish to receive.

candidate:Object

The candidate object that might be a Send of an object of the given type.

Returns:boolean

true if the candidate object is a Send that would deliver an object of the given type, otherwise false.

mapback to summary
public default <R extends Resource<R>> Send<R> map(Class<R> type, Function<T, R> mapper)

Apply a mapping function to the object being sent. The mapping will occur when the object is received.

Parameters
<R>
The result type of the mapping function.
type:Class<R>

The result type of the mapping function.

mapper:Function<T, R>

The mapping function to apply to the object being sent.

Returns:Send<R>

A new Send instance that will deliver an object that is the result of the mapping.

receiveback to summary
public T receive()

Receive the Resource instance being sent, and bind its ownership to the calling thread. The invalidation of the sent resource in the sending thread happens-before the return of this method.

This method can only be called once, and will throw otherwise.

Returns:T

The sent resource instance, never null.

Exceptions
IllegalStateException:
If this method is called more than once.
referentIsInstanceOfback to summary
public boolean referentIsInstanceOf(Class<?> cls)

Determine if the object received from this Send is an instance of the given class.

Parameters
cls:Class<?>

The type to check.

Returns:boolean

true if the object received from this Send can be assigned fields or variables of the given type, otherwise false.

sendingback to summary
public static <T extends Resource<T>> Send<T> sending(Class<T> concreteObjectType, Supplier<? extends T> supplier)

Construct a Send based on the given Supplier. The supplier will be called only once, in the receiving thread.

Parameters
<T>
The type of object being sent.
concreteObjectType:Class<T>

The concrete type of the object being sent. Specifically, the object returned from the Supplier#get() method must be an instance of this class.

supplier:Supplier<? extends T>

The supplier of the object being sent, which will be called when the object is ready to be received.

Returns:Send<T>

A Send which will deliver an object of the given type, from the supplier.