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 interfaceDefaultEventLoopGroupProvider.ThreadFactoryProviderInterface to provide a customThreadFactory. -
Field Summary
Fields Modifier and Type Field Description protected static io.netty.util.internal.logging.InternalLoggerlogger -
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
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 aEventExecutorGroupusing the defaultDefaultEventLoopGroupProvider.ThreadFactoryProvider.protected <T extends EventLoopGroup>
EventExecutorGroupdoCreateEventLoopGroup(Class<T> type, int numberOfThreads, ThreadFactoryProvider threadFactoryProvider)Customization hook forEventLoopGroupcreation.Promise<Boolean>release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit)Release aeventLoopGroupinstance.Future<Boolean>shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)Shutdown the provider and release all instances.intthreadPoolSize()Returns the pool size (number of threads) for IO threads.
-
Field Details
-
logger
protected static final io.netty.util.internal.logging.InternalLogger logger
-
-
Constructor Details
-
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 Details
-
allocate
Description copied from interface:EventLoopGroupProviderRetrieve aEventLoopGroupfor thechanneltype. 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:
allocatein 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 forEventLoopGroupcreation.- 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 aEventExecutorGroupusing 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 thetypeis not supported.
-
release
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit)Description copied from interface:EventLoopGroupProviderRelease aeventLoopGroupinstance. The method will shutdown/terminate theEventExecutorGroupif it is no longer needed.- Specified by:
releasein interfaceEventLoopGroupProvider- Parameters:
eventLoopGroup- the eventLoopGroup instance, must not benullquietPeriod- 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:EventLoopGroupProviderReturns 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:
threadPoolSizein interfaceEventLoopGroupProvider- Returns:
- the pool size (number of threads) for all IO tasks.
-
shutdown
Description copied from interface:EventLoopGroupProviderShutdown the provider and release all instances.- Specified by:
shutdownin interfaceEventLoopGroupProvider- Parameters:
quietPeriod- the quiet periodtimeout- the timeouttimeUnit- the unit ofquietPeriodandtimeout- Returns:
- a close future to synchronize the called for shutting down.
-