public interface ClientFactory extends AutoCloseable
ClientFactory
Clients or ClientBuilder uses the default ClientFactory returned by
ofDefault(), unless you specified a ClientFactory explicitly. Calling close()
on the default ClientFactory will neither terminate its I/O threads nor release other related
resources unlike other ClientFactory to protect itself from accidental premature termination.
Instead, when the current ClassLoader is the system
class loader, a shutdown hook is registered so that they are
released when the JVM exits.
If you are in a multi-classloader environment or you desire an early/explicit termination of the default
ClientFactory, use closeDefault().
| Modifier and Type | Field and Description |
|---|---|
static ClientFactory |
DEFAULT
Deprecated.
Use
ofDefault(). |
| Modifier and Type | Method and Description |
|---|---|
ReleasableHolder<io.netty.channel.EventLoop> |
acquireEventLoop(Endpoint endpoint,
SessionProtocol sessionProtocol)
Acquires an
EventLoop that is expected to handle a connection to the specified Endpoint. |
static ClientFactoryBuilder |
builder()
Returns a newly created
ClientFactoryBuilder. |
default <T> Optional<ClientBuilderParams> |
clientBuilderParams(T client)
Returns the
ClientBuilderParams held in client. |
void |
close()
Closes all clients managed by this factory and shuts down the
EventLoopGroup
created implicitly by this factory. |
static void |
closeDefault()
Closes the default
ClientFactory. |
static void |
disableShutdownHook()
Disables the shutdown hook which closes
the default
ClientFactory. |
io.netty.channel.EventLoopGroup |
eventLoopGroup()
Returns the
EventLoopGroup being used by this ClientFactory. |
Supplier<io.netty.channel.EventLoop> |
eventLoopSupplier()
|
MeterRegistry |
meterRegistry()
Returns the
MeterRegistry that collects various stats. |
<T> T |
newClient(Scheme scheme,
Endpoint endpoint,
Class<T> clientType,
ClientOptions options)
|
<T> T |
newClient(Scheme scheme,
Endpoint endpoint,
Class<T> clientType,
ClientOptionValue<?>... options)
|
<T> T |
newClient(Scheme scheme,
Endpoint endpoint,
String path,
Class<T> clientType,
ClientOptions options)
|
<T> T |
newClient(Scheme scheme,
Endpoint endpoint,
String path,
Class<T> clientType,
ClientOptionValue<?>... options)
|
<T> T |
newClient(String uri,
Class<T> clientType,
ClientOptions options)
Creates a new client that connects to the specified
uri. |
<T> T |
newClient(String uri,
Class<T> clientType,
ClientOptionValue<?>... options)
Creates a new client that connects to the specified
uri. |
<T> T |
newClient(URI uri,
Class<T> clientType,
ClientOptions options)
Creates a new client that connects to the specified
URI. |
<T> T |
newClient(URI uri,
Class<T> clientType,
ClientOptionValue<?>... options)
Creates a new client that connects to the specified
URI. |
static ClientFactory |
ofDefault()
Returns the default
ClientFactory implementation. |
ClientFactoryOptions |
options()
Returns the
ClientFactoryOptions that has been used to create this ClientFactory. |
void |
setMeterRegistry(MeterRegistry meterRegistry)
Sets the
MeterRegistry that collects various stats. |
Set<Scheme> |
supportedSchemes()
Returns the
Schemes supported by this ClientFactory. |
default <T> Optional<T> |
unwrap(Object client,
Class<T> type)
Unwraps the specified
client object into the object of the specified type. |
@Deprecated static final ClientFactory DEFAULT
ofDefault().ClientFactory implementation.static ClientFactory ofDefault()
ClientFactory implementation.static ClientFactoryBuilder builder()
ClientFactoryBuilder.static void closeDefault()
ClientFactory.static void disableShutdownHook()
ClientFactory. This method is useful when you need
full control over the life cycle of the default ClientFactory.Set<Scheme> supportedSchemes()
Schemes supported by this ClientFactory.io.netty.channel.EventLoopGroup eventLoopGroup()
EventLoopGroup being used by this ClientFactory. Can be used to, e.g.,
schedule a periodic task without creating a separate event loop. Use eventLoopSupplier()
instead if what you need is an EventLoop rather than an EventLoopGroup.Supplier<io.netty.channel.EventLoop> eventLoopSupplier()
ReleasableHolder<io.netty.channel.EventLoop> acquireEventLoop(Endpoint endpoint, SessionProtocol sessionProtocol)
EventLoop that is expected to handle a connection to the specified Endpoint.
The caller must release the returned EventLoop back by calling ReleasableHolder.release()
so that ClientFactory utilizes EventLoops efficiently.MeterRegistry meterRegistry()
MeterRegistry that collects various stats.void setMeterRegistry(MeterRegistry meterRegistry)
MeterRegistry 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 preferred MeterRegistry implementation. Invoking this method after this factory
started to export stats to the old MeterRegistry may result in undocumented behavior.ClientFactoryOptions options()
ClientFactoryOptions that has been used to create this ClientFactory.<T> T newClient(String uri, Class<T> clientType, ClientOptionValue<?>... options)
uri.uri - the URI of the server endpointclientType - the type of the new clientoptions - the ClientOptionValues<T> T newClient(String uri, Class<T> clientType, ClientOptions options)
uri.uri - the URI of the server endpointclientType - the type of the new clientoptions - the ClientOptions<T> T newClient(URI uri, Class<T> clientType, ClientOptionValue<?>... options)
URI.uri - the URI of the server endpointclientType - the type of the new clientoptions - the ClientOptionValues<T> T newClient(URI uri, Class<T> clientType, ClientOptions options)
URI.uri - the URI of the server endpointclientType - the type of the new clientoptions - the ClientOptions<T> T newClient(Scheme scheme, Endpoint endpoint, Class<T> clientType, ClientOptionValue<?>... options)
scheme - the Scheme for the endpointendpoint - the server EndpointclientType - the type of the new clientoptions - the ClientOptionValues<T> T newClient(Scheme scheme, Endpoint endpoint, Class<T> clientType, ClientOptions options)
scheme - the Scheme for the endpointendpoint - the server EndpointclientType - the type of the new clientoptions - the ClientOptions<T> T newClient(Scheme scheme, Endpoint endpoint, @Nullable String path, Class<T> clientType, ClientOptionValue<?>... options)
scheme - the Scheme for the endpointendpoint - the server Endpointpath - the service pathclientType - the type of the new clientoptions - the ClientOptionValues<T> T newClient(Scheme scheme, Endpoint endpoint, @Nullable String path, Class<T> clientType, ClientOptions options)
scheme - the Scheme for the endpointendpoint - the server Endpointpath - the service pathclientType - the type of the new clientoptions - the ClientOptionsdefault <T> Optional<ClientBuilderParams> clientBuilderParams(T client)
ClientBuilderParams held in client. This is used when creating a new derived
Client which inherits ClientBuilderParams from client. If this
ClientFactory does not know how to handle the ClientBuilderParams for the provided
client, it should return Optional.empty().default <T> Optional<T> unwrap(Object client, Class<T> type)
client object into the object of the specified type. For example,
ClientFactory clientFactory = ...;
WebClient client = WebClient.builder(...)
.factory(clientFactory)
.decorator(LoggingClient.newDecorator())
.build();
LoggingClient unwrapped = clientFactory.unwrap(client, LoggingClient.class).get();
// If the client implements Unwrappable, you can just use the 'as()' method.
LoggingClient unwrapped2 = client.as(LoggingClient.class).get();
client - the client objecttype - the type of the object to returntype if found. Optional.empty() if not found.Client.as(Class),
Clients.unwrap(Object, Class),
Unwrappablevoid close()
EventLoopGroup
created implicitly by this factory.close in interface AutoCloseableCopyright © 2020 LeanCloud. All rights reserved.