Package ru.yoomoney.tech.dbqueue.config
Class QueueService
- java.lang.Object
-
- ru.yoomoney.tech.dbqueue.config.QueueService
-
@ThreadSafe public class QueueService extends java.lang.ObjectA service for managing start, pause and shutdown of task processors.- Since:
- 14.07.2017
-
-
Constructor Summary
Constructors Constructor Description QueueService(java.util.List<QueueShard<?>> queueShards, ThreadLifecycleListener threadLifecycleListener, TaskLifecycleListener taskLifecycleListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<QueueId>awaitTermination(java.time.Duration timeout)Wait for tasks (and threads) termination in all queues within given timeout.java.util.List<QueueShardId>awaitTermination(QueueId queueId, java.time.Duration timeout)Wait for tasks (and threads) termination in specified queue within given timeout.booleanisPaused()Get attribute that all queues were paused withpause()method.booleanisPaused(QueueId queueId)Get attribute that the specified queue were paused withpause(QueueId)method.booleanisShutdown()Get attribute that the tasks processing was stopped in all registered queues withshutdown().booleanisShutdown(QueueId queueId)Get attribute that the tasks processing was stopped in one specific queue withshutdown()method.booleanisTerminated()Get attribute that all queues finished their execution and all task threads were terminated.booleanisTerminated(QueueId queueId)Get attribute that all the processing task threads were successfully terminated in the specified queue.voidpause()Pause task processing in all queues.voidpause(QueueId queueId)Pause task processing in specified queue.<PayloadT> booleanregisterQueue(QueueConsumer<PayloadT> consumer)Register new task processor of given payload type.voidshutdown()Stop tasks processing in all queues registered in the service, semantic is the same as forExecutorService.shutdownNow().voidshutdown(QueueId queueId)Stop tasks processing in one given queue, semantic is the same as forExecutorService.shutdownNow().voidstart()Start tasks processing in all queues registered in the service.voidstart(QueueId queueId)Start tasks processing in one given queue.voidunpause()Continue task processing in all queues.voidunpause(QueueId queueId)Continue task processing in specified queue.java.util.Map<QueueId,java.lang.String>updateQueueConfigs(java.util.Collection<QueueConfig> configs)Update queue configurations.voidwakeup(QueueId queueId, QueueShardId queueShardId)Force continue task processing in specified queue by given shard identifier.
-
-
-
Constructor Detail
-
QueueService
public QueueService(@Nonnull java.util.List<QueueShard<?>> queueShards, @Nonnull ThreadLifecycleListener threadLifecycleListener, @Nonnull TaskLifecycleListener taskLifecycleListener)
-
-
Method Detail
-
registerQueue
public <PayloadT> boolean registerQueue(@Nonnull QueueConsumer<PayloadT> consumer)Register new task processor of given payload type.- Type Parameters:
PayloadT- Type of the processor (type of the payload in the task).- Parameters:
consumer- Task processor.- Returns:
- Attribute of successful task processor registration.
-
updateQueueConfigs
public java.util.Map<QueueId,java.lang.String> updateQueueConfigs(@Nonnull java.util.Collection<QueueConfig> configs)
Update queue configurations. Applies update to these type of settings:ProcessingSettings- supports update only forProcessingSettings.getThreadCount()settingPollSettings,FailureSettings,ReenqueueSettings- supports update of all settings- Parameters:
configs- new configuration- Returns:
- settings diff per queue
- Throws:
java.lang.IllegalArgumentException- when queue configuration is not found
-
start
public void start()
Start tasks processing in all queues registered in the service.
-
start
public void start(@Nonnull QueueId queueId)Start tasks processing in one given queue.- Parameters:
queueId- Queue identifier.
-
shutdown
public void shutdown()
Stop tasks processing in all queues registered in the service, semantic is the same as forExecutorService.shutdownNow().
-
shutdown
public void shutdown(@Nonnull QueueId queueId)Stop tasks processing in one given queue, semantic is the same as forExecutorService.shutdownNow().- Parameters:
queueId- Queue identifier.
-
isShutdown
public boolean isShutdown(@Nonnull QueueId queueId)Get attribute that the tasks processing was stopped in one specific queue withshutdown()method. Semantic is the same as forExecutorService.isShutdown().- Parameters:
queueId- Queue identifier.- Returns:
- true if the tasks processing was stopped.
-
isShutdown
public boolean isShutdown()
Get attribute that the tasks processing was stopped in all registered queues withshutdown(). Semantic is the same as forExecutorService.isShutdown().- Returns:
- true if the tasks processing was stopped.
-
isTerminated
public boolean isTerminated(@Nonnull QueueId queueId)Get attribute that all the processing task threads were successfully terminated in the specified queue. Semantic is the same as forExecutorService.isTerminated().- Parameters:
queueId- Queue identifier.- Returns:
- true if all the task threads were terminated in specified queue.
-
isTerminated
public boolean isTerminated()
Get attribute that all queues finished their execution and all task threads were terminated. Semantic is the same as forExecutorService.isTerminated().- Returns:
- true if all task threads in all queues were terminated.
-
pause
public void pause(@Nonnull QueueId queueId)Pause task processing in specified queue. To start the processing again, use {unpause(QueueId)method.- Parameters:
queueId- Queue identifier.
-
pause
public void pause()
Pause task processing in all queues. To start processing, useunpause()method.
-
unpause
public void unpause(@Nonnull QueueId queueId)Continue task processing in specified queue. To pause processing, use {pause(QueueId)method.- Parameters:
queueId- Queue identifier.
-
unpause
public void unpause()
Continue task processing in all queues. To pause processing, usepause()method.
-
isPaused
public boolean isPaused()
Get attribute that all queues were paused withpause()method.- Returns:
- true if queues were paused.
-
isPaused
public boolean isPaused(@Nonnull QueueId queueId)Get attribute that the specified queue were paused withpause(QueueId)method.- Parameters:
queueId- Queue identifier.- Returns:
- true if specified queue were paused.
-
awaitTermination
public java.util.List<QueueId> awaitTermination(@Nonnull java.time.Duration timeout)
Wait for tasks (and threads) termination in all queues within given timeout. Semantic is the same as forExecutorService.awaitTermination(long, TimeUnit).- Parameters:
timeout- Wait timeout.- Returns:
- List of queues, which didn't stop their work (didn't terminate).
-
awaitTermination
public java.util.List<QueueShardId> awaitTermination(@Nonnull QueueId queueId, @Nonnull java.time.Duration timeout)
Wait for tasks (and threads) termination in specified queue within given timeout. Semantic is the same as forExecutorService.awaitTermination(long, TimeUnit).- Parameters:
queueId- Queue identifier.timeout- Wait timeout.- Returns:
- List of shards, where the work didn't stop (working threads on which were not terminated).
-
wakeup
public void wakeup(@Nonnull QueueId queueId, @Nonnull QueueShardId queueShardId)Force continue task processing in specified queue by given shard identifier.Processing continues only if the queue were paused with
QueueConfigsReader.SETTING_NO_TASK_TIMEOUTevent.It might be useful for queues which interact with the end user, whereas the end users might often expect possibly the quickest response on their actions. Applies right after a task enqueue, therefore should be called only after successful task insertion transaction. Applies also to tests to improve the speed of test execution.
- Parameters:
queueId- Queue identifier.queueShardId- Shard identifier.
-
-