Package discord4j.common
Class ReactorResources
- java.lang.Object
-
- discord4j.common.ReactorResources
-
public class ReactorResources extends Object
Provides Reactor Netty resources like anHttpClient
andScheduler
instances that can be customized and reused across the application.Allow a user to externally manage the connection pool through a custom
ConnectionProvider
, and custom event loop threads using aLoopResources
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReactorResources.Builder
-
Field Summary
Fields Modifier and Type Field Description static Supplier<Scheduler>
DEFAULT_BLOCKING_TASK_SCHEDULER
static Supplier<HttpClient>
DEFAULT_HTTP_CLIENT
static Supplier<Scheduler>
DEFAULT_TIMER_TASK_SCHEDULER
-
Constructor Summary
Constructors Modifier Constructor Description ReactorResources()
Create with a defaultHttpClient
andScheduler
s for timed and blocking tasks.protected
ReactorResources(ReactorResources.Builder builder)
ReactorResources(HttpClient httpClient, Scheduler timerTaskScheduler, Scheduler blockingTaskScheduler)
Create with a pre-configuredHttpClient
andScheduler
s for timed and blocking tasks.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ReactorResources.Builder
builder()
static ReactorResources
create()
Scheduler
getBlockingTaskScheduler()
Get theScheduler
configured by this provider to be used in blocking tasks.HttpClient
getHttpClient()
Get theHttpClient
configured by this provider.Scheduler
getTimerTaskScheduler()
Get theScheduler
configured by this provider to be used in timed tasks.static HttpClient
newHttpClient(ConnectionProvider provider)
Create a Reactor NettyHttpClient
using the given connection pool.static HttpClient
newHttpClient(ConnectionProvider provider, LoopResources resources)
Create a Reactor NettyHttpClient
using the given connection pool and event loop threads.
-
-
-
Constructor Detail
-
ReactorResources
public ReactorResources()
Create with a defaultHttpClient
andScheduler
s for timed and blocking tasks.
-
ReactorResources
public ReactorResources(HttpClient httpClient, Scheduler timerTaskScheduler, Scheduler blockingTaskScheduler)
Create with a pre-configuredHttpClient
andScheduler
s for timed and blocking tasks.- Parameters:
httpClient
- the underlyingHttpClient
to usetimerTaskScheduler
- the time-capableScheduler
to useblockingTaskScheduler
- theScheduler
to use for potentially blocking tasks
-
ReactorResources
protected ReactorResources(ReactorResources.Builder builder)
-
-
Method Detail
-
create
public static ReactorResources create()
-
builder
public static ReactorResources.Builder builder()
-
getHttpClient
public HttpClient getHttpClient()
Get theHttpClient
configured by this provider.- Returns:
- a Reactor Netty HTTP client ready to perform requests
-
getTimerTaskScheduler
public Scheduler getTimerTaskScheduler()
Get theScheduler
configured by this provider to be used in timed tasks.- Returns:
- a time-capable
Scheduler
-
getBlockingTaskScheduler
public Scheduler getBlockingTaskScheduler()
Get theScheduler
configured by this provider to be used in blocking tasks.- Returns:
- a blocking-capable
Scheduler
-
newHttpClient
public static HttpClient newHttpClient(ConnectionProvider provider)
Create a Reactor NettyHttpClient
using the given connection pool.Use this in case you want dedicated resources for a particular client or clients instead of the global default.
- Parameters:
provider
- the connection pool provider to use- Returns:
- an
HttpClient
configured with custom resources
-
newHttpClient
public static HttpClient newHttpClient(ConnectionProvider provider, LoopResources resources)
Create a Reactor NettyHttpClient
using the given connection pool and event loop threads.Use this in case you want dedicated resources for a particular client or clients instead of the global default.
- Parameters:
provider
- the connection pool provider to useresources
- the set of event loop threads to use- Returns:
- an
HttpClient
configured with custom resources
-
-