Top Description Inners Fields Constructors Methods
org.springframework.messaging.rsocket

pack-priv final Class DefaultRSocketRequester

extends Object
implements RSocketRequester
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.rsocket.RSocketRequester, reactor.core.Disposable
Imports
java.util.Collections, .Map, java.util.function.Consumer, io.rsocket.Payload, .RSocket, io.rsocket.core.RSocketClient, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.ParameterizedTypeReference, .ReactiveAdapter, .ResolvableType, org.springframework.core.codec.Decoder, .Encoder, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .MimeType

Default implementation of RSocketRequester.
Author
Rossen Stoyanchev
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final MimeType
private static final Map<String, Object>
private final Mono<DataBuffer>
private final MimeType
private final RSocket
private final RSocketClient
private final RSocketStrategies

Constructor Summary

AccessConstructor and Description
pack-priv
DefaultRSocketRequester(RSocketClient rsocketClient, RSocket rsocket, MimeType dataMimeType, MimeType metadataMimeType, RSocketStrategies strategies)

Method Summary

Modifier and TypeMethod and Description
private DataBufferFactory
public MimeType
dataMimeType()

Implements org.springframework.messaging.rsocket.RSocketRequester.dataMimeType.

Return the data MimeType selected for the underlying RSocket at connection time.

private static boolean
isVoid(ResolvableType elementType)

public RSocketRequester.RequestSpec
metadata(Object
the metadata value to encode
metadata
,
MimeType
the mime type that describes the metadata; This is required for connection using composite metadata. Otherwise, the value is encoded according to the mime type for the connection and this argument may be left as null.
mimeType
)

Implements org.springframework.messaging.rsocket.RSocketRequester.metadata.

Begin to specify a new request with the given metadata value, which can be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

public MimeType
metadataMimeType()

Implements org.springframework.messaging.rsocket.RSocketRequester.metadataMimeType.

Return the metadata MimeType selected for the underlying RSocket at connection time.

public RSocketRequester.RequestSpec
route(String
the route expressing a remote handler mapping
route
,
Object...
variables to be expanded into the route template
vars
)

Implements org.springframework.messaging.rsocket.RSocketRequester.route.

Begin to specify a new request with the given route to a remote handler.

public RSocket
rsocket()

Implements org.springframework.messaging.rsocket.RSocketRequester.rsocket.

Return the underlying RSocket if the requester was created with a "live" RSocket via wrap(RSocket, MimeType, MimeType, RSocketStrategies) or via one of the (deprecated) connect methods on the RSocketRequester builder, or otherwise return null.

public RSocketClient
rsocketClient()

Implements org.springframework.messaging.rsocket.RSocketRequester.rsocketClient.

Return the underlying RSocketClient used to make requests with.

public RSocketStrategies
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataMimeTypeback to summary
private final MimeType dataMimeType
EMPTY_HINTSback to summary
private static final Map<String, Object> EMPTY_HINTS
emptyBufferMonoback to summary
private final Mono<DataBuffer> emptyBufferMono
metadataMimeTypeback to summary
private final MimeType metadataMimeType
rsocketback to summary
private final RSocket rsocket
Annotations
@Nullable
rsocketClientback to summary
private final RSocketClient rsocketClient
strategiesback to summary
private final RSocketStrategies strategies

Constructor Detail

DefaultRSocketRequesterback to summary
pack-priv DefaultRSocketRequester(RSocketClient rsocketClient, RSocket rsocket, MimeType dataMimeType, MimeType metadataMimeType, RSocketStrategies strategies)

Method Detail

bufferFactoryback to summary
private DataBufferFactory bufferFactory()
dataMimeTypeback to summary
public MimeType dataMimeType()

Implements org.springframework.messaging.rsocket.RSocketRequester.dataMimeType.

Doc from org.springframework.messaging.rsocket.RSocketRequester.dataMimeType.

Return the data MimeType selected for the underlying RSocket at connection time. On the client side this is configured via RSocketRequester.Builder#dataMimeType(MimeType) while on the server side it's obtained from the ConnectionSetupPayload.

Annotations
@Override
isVoidback to summary
private static boolean isVoid(ResolvableType elementType)
metadataback to summary
public RSocketRequester.RequestSpec metadata(Object metadata, MimeType mimeType)

Implements org.springframework.messaging.rsocket.RSocketRequester.metadata.

Doc from org.springframework.messaging.rsocket.RSocketRequester.metadata.

Begin to specify a new request with the given metadata value, which can be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

Parameters
metadata:Object

the metadata value to encode

mimeType:MimeType

the mime type that describes the metadata; This is required for connection using composite metadata. Otherwise, the value is encoded according to the mime type for the connection and this argument may be left as null.

Annotations
@Override
metadataMimeTypeback to summary
public MimeType metadataMimeType()

Implements org.springframework.messaging.rsocket.RSocketRequester.metadataMimeType.

Doc from org.springframework.messaging.rsocket.RSocketRequester.metadataMimeType.

Return the metadata MimeType selected for the underlying RSocket at connection time. On the client side this is configured via RSocketRequester.Builder#metadataMimeType(MimeType) while on the server side it's obtained from the ConnectionSetupPayload.

Annotations
@Override
routeback to summary
public RSocketRequester.RequestSpec route(String route, Object... vars)

Implements org.springframework.messaging.rsocket.RSocketRequester.route.

Doc from org.springframework.messaging.rsocket.RSocketRequester.route.

Begin to specify a new request with the given route to a remote handler.

The route can be a template with placeholders, e.g. "flight.{code}" in which case the supplied route variables are formatted via toString() and expanded into the template. If a formatted variable contains a "." it is replaced with the escape sequence "%2E" to avoid treating it as separator by the responder.

If the connection is set to use composite metadata, the route is encoded as "message/x.rsocket.routing.v0". Otherwise, the route is encoded according to the mime type for the connection.

Parameters
route:String

the route expressing a remote handler mapping

vars:Object[]

variables to be expanded into the route template

Returns:RSocketRequester.RequestSpec

a spec for further defining and executing the request

Annotations
@Override
rsocketback to summary
public RSocket rsocket()

Implements org.springframework.messaging.rsocket.RSocketRequester.rsocket.

Doc from org.springframework.messaging.rsocket.RSocketRequester.rsocket.

Return the underlying RSocket if the requester was created with a "live" RSocket via wrap(RSocket, MimeType, MimeType, RSocketStrategies) or via one of the (deprecated) connect methods on the RSocketRequester builder, or otherwise return null.

Annotations
@Nullable
@Override
rsocketClientback to summary
public RSocketClient rsocketClient()

Implements org.springframework.messaging.rsocket.RSocketRequester.rsocketClient.

Doc from org.springframework.messaging.rsocket.RSocketRequester.rsocketClient.

Return the underlying RSocketClient used to make requests with.

Annotations
@Override
strategiesback to summary
public RSocketStrategies strategies()

Implements org.springframework.messaging.rsocket.RSocketRequester.strategies.

Doc from org.springframework.messaging.rsocket.RSocketRequester.strategies.

Return the configured RSocketStrategies.

Annotations
@Override
org.springframework.messaging.rsocket back to summary

private Class DefaultRSocketRequester.DefaultRequestSpec

extends Object
implements RequestSpec
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.rsocket.DefaultRSocketRequester.DefaultRequestSpec
All Implemented Interfaces
org.springframework.messaging.rsocket.RSocketRequester.RequestSpec, org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec, org.springframework.messaging.rsocket.RSocketRequester.MetadataSpec

Field Summary

Modifier and TypeField and Description
private final MetadataEncoder
private Flux<Payload>
private Mono<Payload>

Constructor Summary

AccessConstructor and Description
public
public
DefaultRequestSpec(Object metadata, MimeType mimeType)

Method Summary

Modifier and TypeMethod and Description
private void
createPayload(Object input, ResolvableType elementType)

public RSocketRequester.RequestSpec
data(Object
the Object value for the payload data
data
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Provide payload data for the request.

public RSocketRequester.RequestSpec
data(Object
the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry
producer
,
Class<?>
the type of values to be produced
elementClass
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Variant of data(Object) that also accepts a hint for the types of values that will be produced.

public RSocketRequester.RequestSpec
data(Object
the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry
producer
,
ParameterizedTypeReference<?>
the type of values to be produced
elementTypeRef
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Variant of data(Object, Class) for when the type hint has to have a generic type.

private <T> DataBuffer
encodeData(T value, ResolvableType elementType, Encoder<?> encoder)

private Mono<Payload>
firstPayload(Mono<DataBuffer>
the encoded payload data; expected to not be empty!
encodedData
)

Create the 1st request payload with encoded data and metadata.

private ReactiveAdapter
getAdapter(Class<?> aClass)

private Mono<Payload>
public RSocketRequester.RequestSpec
metadata(Object
an Object to be encoded with a suitable Encoder, or a DataBuffer
metadata
,
MimeType
the mime type that describes the metadata
mimeType
)

Implements org.springframework.messaging.rsocket.RSocketRequester.MetadataSpec.metadata.

Use this to append additional metadata entries when using composite metadata.

public RSocketRequester.RequestSpec
metadata(Consumer<RSocketRequester.MetadataSpec<?>>
the configurer to apply
configurer
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.metadata.

Append additional metadata entries through a Consumer.

private DataBuffer
public <T> Flux<T>
retrieveFlux(Class<T>
the expected type for values in the response
dataType
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Perform an requestStream or a requestChannel exchange depending on whether the request input is single or multi-payload.

public <T> Flux<T>
retrieveFlux(ParameterizedTypeReference<T> dataTypeRef)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Variant of retrieveFlux(Class) for when the dataType has to have a generic type.

private <T> Flux<T>
public <T> Mono<T>
retrieveMono(Class<T>
the expected data type for the response
dataType
)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Perform a requestResponse exchange.

public <T> Mono<T>
retrieveMono(ParameterizedTypeReference<T> dataTypeRef)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Variant of retrieveMono(Class) for when the dataType has to have a generic type.

private <T> Mono<T>
public Mono<Void>
send()

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.send.

Perform a fireAndForget sending the provided data and metadata.

public Mono<Void>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

metadataEncoderback to summary
private final MetadataEncoder metadataEncoder
payloadFluxback to summary
private Flux<Payload> payloadFlux
Annotations
@Nullable
payloadMonoback to summary
private Mono<Payload> payloadMono
Annotations
@Nullable

Constructor Detail

DefaultRequestSpecback to summary
public DefaultRequestSpec(String route, Object... vars)
DefaultRequestSpecback to summary
public DefaultRequestSpec(Object metadata, MimeType mimeType)

Method Detail

createPayloadback to summary
private void createPayload(Object input, ResolvableType elementType)
databack to summary
public RSocketRequester.RequestSpec data(Object data)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Provide payload data for the request. This can be one of:

Parameters
data:Object

the Object value for the payload data

Returns:RSocketRequester.RequestSpec

spec to declare the expected response

Annotations
@Override
databack to summary
public RSocketRequester.RequestSpec data(Object producer, Class<?> elementClass)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Variant of data(Object) that also accepts a hint for the types of values that will be produced. The class hint is used to find a compatible Encoder once, up front vs per value.

Parameters
producer:Object

the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry

elementClass:Class<?>

the type of values to be produced

Returns:RSocketRequester.RequestSpec

spec to declare the expected response

Annotations
@Override
databack to summary
public RSocketRequester.RequestSpec data(Object producer, ParameterizedTypeReference<?> elementTypeRef)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.data.

Variant of data(Object, Class) for when the type hint has to have a generic type. See ParameterizedTypeReference.

Parameters
producer:Object

the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry

elementTypeRef:ParameterizedTypeReference<?>

the type of values to be produced

Returns:RSocketRequester.RequestSpec

spec to declare the expected response

Annotations
@Override
encodeDataback to summary
private <T> DataBuffer encodeData(T value, ResolvableType elementType, Encoder<?> encoder)
Annotations
@SuppressWarnings:unchecked
firstPayloadback to summary
private Mono<Payload> firstPayload(Mono<DataBuffer> encodedData)

Create the 1st request payload with encoded data and metadata.

Parameters
encodedData:Mono<DataBuffer>

the encoded payload data; expected to not be empty!

getAdapterback to summary
private ReactiveAdapter getAdapter(Class<?> aClass)
Annotations
@Nullable
getPayloadMonoback to summary
private Mono<Payload> getPayloadMono()
metadataback to summary
public RSocketRequester.RequestSpec metadata(Object metadata, MimeType mimeType)

Implements org.springframework.messaging.rsocket.RSocketRequester.MetadataSpec.metadata.

Doc from org.springframework.messaging.rsocket.RSocketRequester.MetadataSpec.metadata.

Use this to append additional metadata entries when using composite metadata. An IllegalArgumentException is raised if this method is used when not using composite metadata. The metadata value be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

Parameters
metadata:Object

an Object to be encoded with a suitable Encoder, or a DataBuffer

mimeType:MimeType

the mime type that describes the metadata

Annotations
@Override
metadataback to summary
public RSocketRequester.RequestSpec metadata(Consumer<RSocketRequester.MetadataSpec<?>> configurer)

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.metadata.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.metadata.

Append additional metadata entries through a Consumer. This enables libraries such as Spring Security to provide shortcuts for applying a set of customizations.

Parameters
configurer:Consumer<RSocketRequester.MetadataSpec<?>>

the configurer to apply

Annotations
@Override
retainDataAndReleasePayloadback to summary
private DataBuffer retainDataAndReleasePayload(Payload payload)
retrieveFluxback to summary
public <T> Flux<T> retrieveFlux(Class<T> dataType)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Perform an requestStream or a requestChannel exchange depending on whether the request input is single or multi-payload.

If the return type is Flux<Void>, the Flux will complete after all data is consumed.

Parameters
<T>
parameterize the expected type of values
dataType:Class<T>

the expected type for values in the response

Returns:Flux<T>

the decoded response

Annotations
@Override
retrieveFluxback to summary
public <T> Flux<T> retrieveFlux(ParameterizedTypeReference<T> dataTypeRef)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveFlux.

Variant of retrieveFlux(Class) for when the dataType has to have a generic type. See ParameterizedTypeReference.

Annotations
@Override
retrieveFluxback to summary
private <T> Flux<T> retrieveFlux(ResolvableType elementType)
Annotations
@SuppressWarnings:unchecked
retrieveMonoback to summary
public <T> Mono<T> retrieveMono(Class<T> dataType)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Perform a requestResponse exchange.

If the return type is Mono<Void>, the Mono will complete after all data is consumed.

Note

This method will raise an error if the request payload is a multivalued Publisher as there is no many-to-one RSocket interaction.

Parameters
<T>
parameter for the expected data type
dataType:Class<T>

the expected data type for the response

Returns:Mono<T>

the decoded response

Annotations
@Override
retrieveMonoback to summary
public <T> Mono<T> retrieveMono(ParameterizedTypeReference<T> dataTypeRef)

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.retrieveMono.

Variant of retrieveMono(Class) for when the dataType has to have a generic type. See ParameterizedTypeReference.

Annotations
@Override
retrieveMonoback to summary
private <T> Mono<T> retrieveMono(ResolvableType elementType)
Annotations
@SuppressWarnings:unchecked
sendback to summary
public Mono<Void> send()

Implements org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.send.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec.send.

Perform a fireAndForget sending the provided data and metadata.

Returns:Mono<Void>

a completion that indicates if the payload was sent successfully or not. Note, however that is a one-way send and there is no indication of whether or how the even was handled on the remote end.

Annotations
@Override
sendMetadataback to summary
public Mono<Void> sendMetadata()

Implements org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.sendMetadata.

Doc from org.springframework.messaging.rsocket.RSocketRequester.RequestSpec.sendMetadata.

Perform a metadataPush.

Annotations
@Override