Package io.lettuce.core.resource
Class DefaultEventLoopGroupProvider
- java.lang.Object
-
- io.lettuce.core.resource.DefaultEventLoopGroupProvider
-
- All Implemented Interfaces:
EventLoopGroupProvider
public class DefaultEventLoopGroupProvider extends Object implements EventLoopGroupProvider
Default implementation which manages one event loop group instance per type.- Since:
- 3.4
- Author:
- Mark Paluch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DefaultEventLoopGroupProvider.ThreadFactoryProvider
Interface to provide a customThreadFactory
.
-
Field Summary
Fields Modifier and Type Field Description protected static InternalLogger
logger
-
Constructor Summary
Constructors Constructor Description DefaultEventLoopGroupProvider(int numberOfThreads)
Creates a new instance ofDefaultEventLoopGroupProvider
.DefaultEventLoopGroupProvider(int numberOfThreads, DefaultEventLoopGroupProvider.ThreadFactoryProvider threadFactoryProvider)
Creates a new instance ofDefaultEventLoopGroupProvider
.DefaultEventLoopGroupProvider(int numberOfThreads, ThreadFactoryProvider threadFactoryProvider)
Creates a new instance ofDefaultEventLoopGroupProvider
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends EventLoopGroup>
Tallocate(Class<T> type)
static <T extends EventExecutorGroup>
EventExecutorGroupcreateEventLoopGroup(Class<T> type, int numberOfThreads)
Create an instance of aEventExecutorGroup
using the defaultDefaultEventLoopGroupProvider.ThreadFactoryProvider
.protected <T extends EventLoopGroup>
EventExecutorGroupdoCreateEventLoopGroup(Class<T> type, int numberOfThreads, ThreadFactoryProvider threadFactoryProvider)
Customization hook forEventLoopGroup
creation.Promise<Boolean>
release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit)
Release aeventLoopGroup
instance.Future<Boolean>
shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
Shutdown the provider and release all instances.int
threadPoolSize()
Returns the pool size (number of threads) for IO threads.
-
-
-
Field Detail
-
logger
protected static final InternalLogger logger
-
-
Constructor Detail
-
DefaultEventLoopGroupProvider
public DefaultEventLoopGroupProvider(int numberOfThreads)
Creates a new instance ofDefaultEventLoopGroupProvider
.- Parameters:
numberOfThreads
- number of threads (pool size)
-
DefaultEventLoopGroupProvider
public DefaultEventLoopGroupProvider(int numberOfThreads, DefaultEventLoopGroupProvider.ThreadFactoryProvider threadFactoryProvider)
Creates a new instance ofDefaultEventLoopGroupProvider
.- Parameters:
numberOfThreads
- number of threads (pool size)threadFactoryProvider
- provides access toThreadFactory
.- Since:
- 6.0
-
DefaultEventLoopGroupProvider
public DefaultEventLoopGroupProvider(int numberOfThreads, ThreadFactoryProvider threadFactoryProvider)
Creates a new instance ofDefaultEventLoopGroupProvider
.- Parameters:
numberOfThreads
- number of threads (pool size)threadFactoryProvider
- provides access toThreadFactoryProvider
.- Since:
- 6.1.1
-
-
Method Detail
-
allocate
public <T extends EventLoopGroup> T allocate(Class<T> type)
Description copied from interface:EventLoopGroupProvider
Retrieve aEventLoopGroup
for thechannel
type
. Do not terminate or shutdown the instance. Call theEventLoopGroupProvider.release(EventExecutorGroup, long, long, TimeUnit)
to release an individual instance orEventLoopGroupProvider.shutdown(long, long, TimeUnit)
method to free the all resources.- Specified by:
allocate
in interfaceEventLoopGroupProvider
- Type Parameters:
T
- type of theEventLoopGroup
- Parameters:
type
- class of theEventLoopGroup
, must not benull
- Returns:
- the
EventLoopGroup
.
-
doCreateEventLoopGroup
protected <T extends EventLoopGroup> EventExecutorGroup doCreateEventLoopGroup(Class<T> type, int numberOfThreads, ThreadFactoryProvider threadFactoryProvider)
Customization hook forEventLoopGroup
creation.- Type Parameters:
T
-- Parameters:
type
- requested event loop group type.numberOfThreads
- number of threads to create.threadFactoryProvider
- provider forThreadFactory
.- Returns:
- Since:
- 6.0
-
createEventLoopGroup
public static <T extends EventExecutorGroup> EventExecutorGroup createEventLoopGroup(Class<T> type, int numberOfThreads)
Create an instance of aEventExecutorGroup
using the defaultDefaultEventLoopGroupProvider.ThreadFactoryProvider
. Supported types are:- DefaultEventExecutorGroup
- NioEventLoopGroup
- EpollEventLoopGroup
- KqueueEventLoopGroup
- Type Parameters:
T
- type parameter- Parameters:
type
- the typenumberOfThreads
- the number of threads to use for theEventExecutorGroup
- Returns:
- a new instance of a
EventExecutorGroup
- Throws:
IllegalArgumentException
- if thetype
is not supported.
-
release
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit)
Description copied from interface:EventLoopGroupProvider
Release aeventLoopGroup
instance. The method will shutdown/terminate theEventExecutorGroup
if it is no longer needed.- Specified by:
release
in interfaceEventLoopGroupProvider
- Parameters:
eventLoopGroup
- the eventLoopGroup instance, must not benull
quietPeriod
- the quiet periodtimeout
- the timeoutunit
- time unit for the quiet period/the timeout- Returns:
- a close future to synchronize the called for shutting down.
-
threadPoolSize
public int threadPoolSize()
Description copied from interface:EventLoopGroupProvider
Returns the pool size (number of threads) for IO threads. The indicated size does not reflect the number for all IO threads, it is the number of threads that are used to create a particular thread pool.- Specified by:
threadPoolSize
in interfaceEventLoopGroupProvider
- Returns:
- the pool size (number of threads) for all IO tasks.
-
shutdown
public Future<Boolean> shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
Description copied from interface:EventLoopGroupProvider
Shutdown the provider and release all instances.- Specified by:
shutdown
in interfaceEventLoopGroupProvider
- Parameters:
quietPeriod
- the quiet periodtimeout
- the timeouttimeUnit
- the unit ofquietPeriod
andtimeout
- Returns:
- a close future to synchronize the called for shutting down.
-
-