Package fr.becpg.repo.batch
Class BatchQueueServiceImpl
java.lang.Object
fr.becpg.repo.batch.BatchQueueServiceImpl
- All Implemented Interfaces:
BatchQueueService,EventListener,org.springframework.context.ApplicationListener<org.alfresco.repo.batch.BatchMonitorEvent>
@Service("batchQueueService")
public class BatchQueueServiceImpl
extends Object
implements BatchQueueService, org.springframework.context.ApplicationListener<org.alfresco.repo.batch.BatchMonitorEvent>
BatchQueueServiceImpl class.
- Version:
- $Id: $Id
- Author:
- matthieu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.springframework.context.ApplicationEventPublisherprivate ReentrantLockprivate BatchQueuePlugin[]private BeCPGAuditServiceprivate BeCPGCacheServiceprivate BeCPGMailServiceprivate static final StringConstantCANCELLED="cancelled"private org.alfresco.repo.batch.BatchMonitorprivate static final org.apache.commons.logging.LogConstantloggerprivate static final intConstantMAX_DISCARDED_ENTRIES=1000private org.alfresco.service.cmr.repository.NodeServiceprivate Deque<BatchQueueServiceImpl.BatchCommand<?>> private static final StringConstantPERCENT_COMPLETED="percentCompleted"private org.alfresco.repo.policy.BehaviourFilterprivate List<BatchQueueServiceImpl.BatchCommand<?>> private static final StringConstantSTEP_COUNT="stepCount"private static final StringConstantSTEPS_MAX="stepsMax"private org.alfresco.repo.tenant.TenantAdminServiceprivate Map<String, ThreadPoolExecutor> private org.alfresco.service.transaction.TransactionService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.json.JSONObjectbuildJsonBatchInfo(BatchInfo batchInfo) buildJsonBatchInfo.booleancancelBatch(String batchId) cancelBatch.BatchStep<org.alfresco.service.cmr.repository.NodeRef> createBatchStepWithErrorHandling(BatchInfo batchInfo, List<org.alfresco.service.cmr.repository.NodeRef> list, org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<org.alfresco.service.cmr.repository.NodeRef> processor) createBatchStepWithErrorHandling.BatchStep<org.alfresco.service.cmr.repository.NodeRef> createBatchStepWithErrorHandling(BatchInfo batchInfo, List<org.alfresco.service.cmr.repository.NodeRef> list, org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<org.alfresco.service.cmr.repository.NodeRef> processor, BiConsumer<org.alfresco.service.cmr.repository.NodeRef, Throwable> errorHandler) createBatchStepWithErrorHandling.private voiddiscardEntry(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry) discardEntry.private BatchQueueServiceImpl.BatchCommand<?> findCommandInQueue(String batchId) findCommandInQueue.getBatchErrorsMap.getBatchesInError.getBatchesInQueue.org.alfresco.repo.batch.BatchMonitorgetLastRunningBatch.getRunningBatchInfo.private BatchQueueServiceImpl.BatchCommand<?> getRunningCommand.booleanisBatchCompleted(BatchInfo batchInfo) isBatchCompleted.booleanisBatchInQueue(BatchInfo batchInfo) isBatchInQueue.private booleanisDiscardedEntry(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry) isDiscardedEntry.private voidmarkEntryInError(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry, List<String> batchErrorIds) markEntryInError.voidonApplicationEvent(org.alfresco.repo.batch.BatchMonitorEvent event) private BatchQueueServiceImpl.BatchCommand<?> pollNextPausedCommand.private voidprocessBatchErrors(List<org.alfresco.service.cmr.repository.NodeRef> nodeRefs, Map<String, Set<org.alfresco.service.cmr.repository.NodeRef>> batchNodesMap) processBatchErrors.<T> BooleanqueueBatch(BatchInfo batchInfo, List<BatchStep<T>> batchSteps) queueBatch.<T> BooleanqueueBatch(BatchInfo batchInfo, List<BatchStep<T>> batchSteps, BatchClosingHook closingHook) queueBatch.<T> BooleanqueueBatch(BatchInfo batchInfo, org.alfresco.repo.batch.BatchProcessWorkProvider<T> workProvider, org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<T> processWorker, BatchErrorCallback errorCallback) queueBatch.booleanremoveBatchFromQueue(String batchId) removeBatchFromQueue.retryBatchInError(String batchErrorId) retryBatchInError.viewErrors(String batchId) viewErrors.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
logger
private static final org.apache.commons.logging.Log loggerConstantlogger -
transactionService
@Autowired private org.alfresco.service.transaction.TransactionService transactionService -
applicationEventPublisher
@Autowired private org.springframework.context.ApplicationEventPublisher applicationEventPublisher -
beCPGMailService
-
threadExecutorMap
@Autowired @Qualifier("batchThreadPoolExecutorMap") private Map<String,ThreadPoolExecutor> threadExecutorMap -
tenantAdminService
@Autowired private org.alfresco.repo.tenant.TenantAdminService tenantAdminService -
beCPGAuditService
-
beCPGCacheService
-
nodeService
@Autowired private org.alfresco.service.cmr.repository.NodeService nodeService -
policyBehaviourFilter
@Autowired private org.alfresco.repo.policy.BehaviourFilter policyBehaviourFilter -
lastRunningBatch
private org.alfresco.repo.batch.BatchMonitor lastRunningBatch -
runningCommands
-
cancelledBatches
-
pausedCommands
-
discardedEntries
-
batchQueueLock
-
batchQueuePlugins
-
CANCELLED
ConstantCANCELLED="cancelled"- See Also:
-
PERCENT_COMPLETED
ConstantPERCENT_COMPLETED="percentCompleted"- See Also:
-
STEPS_MAX
ConstantSTEPS_MAX="stepsMax"- See Also:
-
STEP_COUNT
ConstantSTEP_COUNT="stepCount"- See Also:
-
MAX_DISCARDED_ENTRIES
private static final int MAX_DISCARDED_ENTRIESConstantMAX_DISCARDED_ENTRIES=1000- See Also:
-
-
Constructor Details
-
BatchQueueServiceImpl
public BatchQueueServiceImpl()
-
-
Method Details
-
queueBatch
public <T> Boolean queueBatch(@NonNull BatchInfo batchInfo, @NonNull org.alfresco.repo.batch.BatchProcessWorkProvider<T> workProvider, @NonNull org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<T> processWorker, @Nullable BatchErrorCallback errorCallback) queueBatch.
- Specified by:
queueBatchin interfaceBatchQueueService- Type Parameters:
T- a T class- Parameters:
batchInfo- aBatchInfoobjectworkProvider- aBatchProcessWorkProviderobjectprocessWorker- aBatchProcessor.BatchProcessWorkerobjecterrorCallback- aBatchErrorCallbackobject- Returns:
- a
Booleanobject
-
queueBatch
queueBatch.
- Specified by:
queueBatchin interfaceBatchQueueService- Type Parameters:
T- a T class- Parameters:
batchInfo- aBatchInfoobjectbatchSteps- aListobject- Returns:
- a
Booleanobject
-
queueBatch
public <T> Boolean queueBatch(@NonNull BatchInfo batchInfo, @NonNull List<BatchStep<T>> batchSteps, BatchClosingHook closingHook) queueBatch.
- Specified by:
queueBatchin interfaceBatchQueueService- Type Parameters:
T- a T class- Parameters:
batchInfo- aBatchInfoobjectbatchSteps- aListobjectclosingHook- aBatchClosingHookobject- Returns:
- a
Booleanobject
-
isBatchInQueue
isBatchInQueue.
- Specified by:
isBatchInQueuein interfaceBatchQueueService- Parameters:
batchInfo- aBatchInfoobject- Returns:
- a boolean
-
isBatchCompleted
isBatchCompleted.
- Specified by:
isBatchCompletedin interfaceBatchQueueService- Parameters:
batchInfo- aBatchInfoobject- Returns:
- true if the batch has completed and is no longer tracked as running
-
getRunningBatchInfo
getRunningBatchInfo.
- Specified by:
getRunningBatchInfoin interfaceBatchQueueService- Returns:
- a
Stringobject
-
buildJsonBatchInfo
buildJsonBatchInfo.
- Parameters:
batchInfo- aBatchInfoobject- Returns:
- a
JSONObjectobject - Throws:
org.json.JSONException- if any.
-
getLastRunningBatch
public org.alfresco.repo.batch.BatchMonitor getLastRunningBatch()getLastRunningBatch.
- Specified by:
getLastRunningBatchin interfaceBatchQueueService- Returns:
- a
BatchMonitorobject
-
getRunningCommand
getRunningCommand.
- Returns:
- a
BatchQueueServiceImpl.BatchCommandobject
-
pollNextPausedCommand
pollNextPausedCommand.
Removes and returns the paused batch that must run next: the most prioritary one, and among batches of equal priority the one paused first, so that a repeatedly preempted batch cannot be starved by more recently paused ones.- Returns:
- a
BatchQueueServiceImpl.BatchCommandobject
-
getBatchesInQueue
getBatchesInQueue.
- Specified by:
getBatchesInQueuein interfaceBatchQueueService- Returns:
- a
Listobject
-
removeBatchFromQueue
removeBatchFromQueue.
- Specified by:
removeBatchFromQueuein interfaceBatchQueueService- Parameters:
batchId- aStringobject- Returns:
- a boolean
-
findCommandInQueue
findCommandInQueue.
- Parameters:
batchId- aStringobject- Returns:
- a
BatchQueueServiceImpl.BatchCommandobject
-
cancelBatch
cancelBatch.
- Specified by:
cancelBatchin interfaceBatchQueueService- Parameters:
batchId- aStringobject- Returns:
- a boolean
-
getBatchesInError
getBatchesInError.
- Specified by:
getBatchesInErrorin interfaceBatchQueueService- Returns:
- a
Stringobject
-
getBatchErrorsMap
getBatchErrorsMap.
- Returns:
- a
Mapobject
-
processBatchErrors
private void processBatchErrors(List<org.alfresco.service.cmr.repository.NodeRef> nodeRefs, Map<String, Set<org.alfresco.service.cmr.repository.NodeRef>> batchNodesMap) processBatchErrors.
-
retryBatchInError
retryBatchInError.
- Specified by:
retryBatchInErrorin interfaceBatchQueueService- Parameters:
batchErrorId- aStringobject- Returns:
- a
BatchInfoobject
-
createBatchStepWithErrorHandling
public BatchStep<org.alfresco.service.cmr.repository.NodeRef> createBatchStepWithErrorHandling(BatchInfo batchInfo, List<org.alfresco.service.cmr.repository.NodeRef> list, org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<org.alfresco.service.cmr.repository.NodeRef> processor) createBatchStepWithErrorHandling.
- Specified by:
createBatchStepWithErrorHandlingin interfaceBatchQueueService- Parameters:
batchInfo- aBatchInfoobjectlist- aListobjectprocessor- aBatchProcessor.BatchProcessWorkerobject- Returns:
- a
BatchStepobject
-
createBatchStepWithErrorHandling
public BatchStep<org.alfresco.service.cmr.repository.NodeRef> createBatchStepWithErrorHandling(BatchInfo batchInfo, List<org.alfresco.service.cmr.repository.NodeRef> list, org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker<org.alfresco.service.cmr.repository.NodeRef> processor, BiConsumer<org.alfresco.service.cmr.repository.NodeRef, Throwable> errorHandler) createBatchStepWithErrorHandling.
- Specified by:
createBatchStepWithErrorHandlingin interfaceBatchQueueService- Parameters:
batchInfo- aBatchInfoobjectlist- aListobjectprocessor- aBatchProcessor.BatchProcessWorkerobjecterrorHandler- aBiConsumerobject- Returns:
- a
BatchStepobject
-
isDiscardedEntry
private boolean isDiscardedEntry(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry) isDiscardedEntry.
An entry that cannot be flagged in error on the node itself has to be excluded by the queue, otherwise it would fail again on every run of the batch and reschedule it endlessly.- Parameters:
batchFullId- aStringobjectentry- aNodeRefobject- Returns:
- a boolean
-
discardEntry
discardEntry.
- Parameters:
batchFullId- aStringobjectentry- aNodeRefobject
-
markEntryInError
private void markEntryInError(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry, List<String> batchErrorIds) throws Exception markEntryInError.
Flags the entry as failed so that it is skipped on the next runs of the batch. When the flag cannot be written, the entry is discarded in memory instead, otherwise the batch would be rescheduled endlessly on it. -
viewErrors
viewErrors.
- Specified by:
viewErrorsin interfaceBatchQueueService- Parameters:
batchId- aStringobject- Returns:
- a
Stringobject
-
onApplicationEvent
public void onApplicationEvent(org.alfresco.repo.batch.BatchMonitorEvent event) - Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.alfresco.repo.batch.BatchMonitorEvent>
-