Package com.linecorp.armeria.client
Class DecoratingClientFactory
java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<ClientFactory>
com.linecorp.armeria.client.DecoratingClientFactory
- All Implemented Interfaces:
ClientFactory
,AsyncCloseable
,ListenableAsyncCloseable
,Unwrappable
,AutoCloseable
public class DecoratingClientFactory extends AbstractUnwrappable<ClientFactory> implements ClientFactory
-
Constructor Summary
Constructors Modifier Constructor Description protected
DecoratingClientFactory(ClientFactory delegate)
Creates a new instance. -
Method Summary
Modifier and Type Method Description ReleasableHolder<EventLoop>
acquireEventLoop(SessionProtocol sessionProtocol, EndpointGroup endpointGroup, Endpoint endpoint)
<T> ClientBuilderParams
clientBuilderParams(T client)
Returns theClientBuilderParams
held inclient
.void
close()
Releases any underlying resources held by this object synchronously.CompletableFuture<?>
closeAsync()
Releases any underlying resources held by this object asynchronously.EventLoopGroup
eventLoopGroup()
Returns theEventLoopGroup
being used by thisClientFactory
.Supplier<EventLoop>
eventLoopSupplier()
boolean
isClosed()
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation has been completed.boolean
isClosing()
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
has been called.MeterRegistry
meterRegistry()
Returns theMeterRegistry
that collects various stats.Object
newClient(ClientBuilderParams params)
Creates a new client with the specifiedClientBuilderParams
.protected HttpClient
newHttpClient(ClientBuilderParams params)
Creates a newHttpClient
which uses the sameSessionProtocol
,EndpointGroup
andClientOptions
with the specifiedClientBuilderParams
.ClientFactoryOptions
options()
Returns theClientFactoryOptions
that has been used to create thisClientFactory
.void
setMeterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
that collects various stats.Set<Scheme>
supportedSchemes()
Returns theScheme
s supported by thisClientFactory
.<T> T
unwrap(Object client, Class<T> type)
Unwraps the specifiedclient
object into the object of the specifiedtype
.CompletableFuture<?>
whenClosed()
Returns theCompletableFuture
which is completed after theAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation is completed.Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, toString, unwrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.ClientFactory
unwrap, validateParams, validateScheme, validateUri
-
Constructor Details
-
DecoratingClientFactory
Creates a new instance.
-
-
Method Details
-
newHttpClient
Creates a newHttpClient
which uses the sameSessionProtocol
,EndpointGroup
andClientOptions
with the specifiedClientBuilderParams
. Note thatpath
andSerializationFormat
are always"/"
andSerializationFormat.NONE
. -
supportedSchemes
Description copied from interface:ClientFactory
Returns theScheme
s supported by thisClientFactory
.- Specified by:
supportedSchemes
in interfaceClientFactory
-
eventLoopGroup
Description copied from interface:ClientFactory
Returns theEventLoopGroup
being used by thisClientFactory
. Can be used to, e.g., schedule a periodic task without creating a separate event loop. UseClientFactory.eventLoopSupplier()
instead if what you need is anEventLoop
rather than anEventLoopGroup
.- Specified by:
eventLoopGroup
in interfaceClientFactory
-
eventLoopSupplier
Description copied from interface:ClientFactory
- Specified by:
eventLoopSupplier
in interfaceClientFactory
-
acquireEventLoop
public ReleasableHolder<EventLoop> acquireEventLoop(SessionProtocol sessionProtocol, EndpointGroup endpointGroup, @Nullable Endpoint endpoint)Description copied from interface:ClientFactory
Acquires anEventLoop
that is expected to handle a connection to the specifiedEndpoint
. The caller must release the returnedEventLoop
back by callingReleasableHolder.release()
so thatClientFactory
utilizesEventLoop
s efficiently.- Specified by:
acquireEventLoop
in interfaceClientFactory
- Parameters:
sessionProtocol
- theSessionProtocol
of the connectionendpointGroup
- theEndpointGroup
whereendpoint
belongs to.endpoint
- theEndpoint
where a request is being sent.null
if theEndpoint
is not known yet.
-
meterRegistry
Description copied from interface:ClientFactory
Returns theMeterRegistry
that collects various stats.- Specified by:
meterRegistry
in interfaceClientFactory
-
setMeterRegistry
Description copied from interface:ClientFactory
Sets theMeterRegistry
that collects various stats. Note that this method is intended to be used during the initialization phase of an application, so that the application gets a chance to switch to the preferredMeterRegistry
implementation. Invoking this method after this factory started to export stats to the oldMeterRegistry
may result in undocumented behavior.- Specified by:
setMeterRegistry
in interfaceClientFactory
-
options
Description copied from interface:ClientFactory
Returns theClientFactoryOptions
that has been used to create thisClientFactory
.- Specified by:
options
in interfaceClientFactory
-
newClient
Description copied from interface:ClientFactory
Creates a new client with the specifiedClientBuilderParams
. The client instance returned by this method must be an instance ofClientBuilderParams.clientType()
.- Specified by:
newClient
in interfaceClientFactory
-
clientBuilderParams
Description copied from interface:ClientFactory
Returns theClientBuilderParams
held inclient
. This is used when creating a new derivedClient
which inheritsClientBuilderParams
fromclient
. If thisClientFactory
does not know how to handle theClientBuilderParams
for the providedclient
, it should returnnull
.- Specified by:
clientBuilderParams
in interfaceClientFactory
-
unwrap
Description copied from interface:ClientFactory
Unwraps the specifiedclient
object into the object of the specifiedtype
. For example,ClientFactory clientFactory = ...; WebClient client = WebClient.builder(...) .factory(clientFactory) .decorator(LoggingClient.newDecorator()) .build(); LoggingClient unwrapped = clientFactory.unwrap(client, LoggingClient.class); // If the client implements Unwrappable, you can just use the 'as()' method. LoggingClient unwrapped2 = client.as(LoggingClient.class);
- Specified by:
unwrap
in interfaceClientFactory
- Parameters:
client
- the client objecttype
- the type of the object to return- Returns:
- the object of the specified
type
if found, ornull
if not found. - See Also:
Client.as(Class)
,Clients.unwrap(Object, Class)
,Unwrappable
-
isClosing
public boolean isClosing()Description copied from interface:ListenableAsyncCloseable
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
has been called.- Specified by:
isClosing
in interfaceListenableAsyncCloseable
- See Also:
ListenableAsyncCloseable.isClosed()
-
isClosed
public boolean isClosed()Description copied from interface:ListenableAsyncCloseable
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation has been completed.- Specified by:
isClosed
in interfaceListenableAsyncCloseable
- See Also:
ListenableAsyncCloseable.isClosing()
-
whenClosed
Description copied from interface:ListenableAsyncCloseable
Returns theCompletableFuture
which is completed after theAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation is completed.- Specified by:
whenClosed
in interfaceListenableAsyncCloseable
-
closeAsync
Description copied from interface:AsyncCloseable
Releases any underlying resources held by this object asynchronously.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- the
CompletableFuture
which is completed after the resources are released
-
close
public void close()Description copied from interface:AsyncCloseable
Releases any underlying resources held by this object synchronously.- Specified by:
close
in interfaceAsyncCloseable
- Specified by:
close
in interfaceAutoCloseable
-