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
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
      Constant logger
    • transactionService

      @Autowired private org.alfresco.service.transaction.TransactionService transactionService
    • applicationEventPublisher

      @Autowired private org.springframework.context.ApplicationEventPublisher applicationEventPublisher
    • beCPGMailService

      @Autowired private BeCPGMailService beCPGMailService
    • threadExecutorMap

      @Autowired @Qualifier("batchThreadPoolExecutorMap") private Map<String,ThreadPoolExecutor> threadExecutorMap
    • tenantAdminService

      @Autowired private org.alfresco.repo.tenant.TenantAdminService tenantAdminService
    • beCPGAuditService

      @Autowired private BeCPGAuditService beCPGAuditService
    • beCPGCacheService

      @Autowired private BeCPGCacheService 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

      private List<BatchQueueServiceImpl.BatchCommand<?>> runningCommands
    • cancelledBatches

      private Set<String> cancelledBatches
    • pausedCommands

      private Deque<BatchQueueServiceImpl.BatchCommand<?>> pausedCommands
    • discardedEntries

      private Map<String,Set<org.alfresco.service.cmr.repository.NodeRef>> discardedEntries
    • batchQueueLock

      private ReentrantLock batchQueueLock
    • batchQueuePlugins

      @Autowired(required=false) private BatchQueuePlugin[] batchQueuePlugins
    • CANCELLED

      private static final String CANCELLED
      Constant CANCELLED="cancelled"
      See Also:
    • PERCENT_COMPLETED

      private static final String PERCENT_COMPLETED
      Constant PERCENT_COMPLETED="percentCompleted"
      See Also:
    • STEPS_MAX

      private static final String STEPS_MAX
      Constant STEPS_MAX="stepsMax"
      See Also:
    • STEP_COUNT

      private static final String STEP_COUNT
      Constant STEP_COUNT="stepCount"
      See Also:
    • MAX_DISCARDED_ENTRIES

      private static final int MAX_DISCARDED_ENTRIES
      Constant MAX_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:
      queueBatch in interface BatchQueueService
      Type Parameters:
      T - a T class
      Parameters:
      batchInfo - a BatchInfo object
      workProvider - a BatchProcessWorkProvider object
      processWorker - a BatchProcessor.BatchProcessWorker object
      errorCallback - a BatchErrorCallback object
      Returns:
      a Boolean object
    • queueBatch

      public <T> Boolean queueBatch(@NonNull BatchInfo batchInfo, @NonNull List<BatchStep<T>> batchSteps)

      queueBatch.

      Specified by:
      queueBatch in interface BatchQueueService
      Type Parameters:
      T - a T class
      Parameters:
      batchInfo - a BatchInfo object
      batchSteps - a List object
      Returns:
      a Boolean object
    • queueBatch

      public <T> Boolean queueBatch(@NonNull BatchInfo batchInfo, @NonNull List<BatchStep<T>> batchSteps, BatchClosingHook closingHook)

      queueBatch.

      Specified by:
      queueBatch in interface BatchQueueService
      Type Parameters:
      T - a T class
      Parameters:
      batchInfo - a BatchInfo object
      batchSteps - a List object
      closingHook - a BatchClosingHook object
      Returns:
      a Boolean object
    • isBatchInQueue

      public boolean isBatchInQueue(BatchInfo batchInfo)

      isBatchInQueue.

      Specified by:
      isBatchInQueue in interface BatchQueueService
      Parameters:
      batchInfo - a BatchInfo object
      Returns:
      a boolean
    • isBatchCompleted

      public boolean isBatchCompleted(BatchInfo batchInfo)

      isBatchCompleted.

      Specified by:
      isBatchCompleted in interface BatchQueueService
      Parameters:
      batchInfo - a BatchInfo object
      Returns:
      true if the batch has completed and is no longer tracked as running
    • getRunningBatchInfo

      public String getRunningBatchInfo()

      getRunningBatchInfo.

      Specified by:
      getRunningBatchInfo in interface BatchQueueService
      Returns:
      a String object
    • buildJsonBatchInfo

      private org.json.JSONObject buildJsonBatchInfo(BatchInfo batchInfo) throws org.json.JSONException

      buildJsonBatchInfo.

      Parameters:
      batchInfo - a BatchInfo object
      Returns:
      a JSONObject object
      Throws:
      org.json.JSONException - if any.
    • getLastRunningBatch

      public org.alfresco.repo.batch.BatchMonitor getLastRunningBatch()

      getLastRunningBatch.

      Specified by:
      getLastRunningBatch in interface BatchQueueService
      Returns:
      a BatchMonitor object
    • getRunningCommand

      private BatchQueueServiceImpl.BatchCommand<?> getRunningCommand()

      getRunningCommand.

      Returns:
      a BatchQueueServiceImpl.BatchCommand object
    • pollNextPausedCommand

      private BatchQueueServiceImpl.BatchCommand<?> 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.BatchCommand object
    • getBatchesInQueue

      public List<String> getBatchesInQueue()

      getBatchesInQueue.

      Specified by:
      getBatchesInQueue in interface BatchQueueService
      Returns:
      a List object
    • removeBatchFromQueue

      public boolean removeBatchFromQueue(String batchId)

      removeBatchFromQueue.

      Specified by:
      removeBatchFromQueue in interface BatchQueueService
      Parameters:
      batchId - a String object
      Returns:
      a boolean
    • findCommandInQueue

      private BatchQueueServiceImpl.BatchCommand<?> findCommandInQueue(String batchId)

      findCommandInQueue.

      Parameters:
      batchId - a String object
      Returns:
      a BatchQueueServiceImpl.BatchCommand object
    • cancelBatch

      public boolean cancelBatch(String batchId)

      cancelBatch.

      Specified by:
      cancelBatch in interface BatchQueueService
      Parameters:
      batchId - a String object
      Returns:
      a boolean
    • getBatchesInError

      public String getBatchesInError()

      getBatchesInError.

      Specified by:
      getBatchesInError in interface BatchQueueService
      Returns:
      a String object
    • getBatchErrorsMap

      private Map<String,Set<org.alfresco.service.cmr.repository.NodeRef>> getBatchErrorsMap()

      getBatchErrorsMap.

      Returns:
      a Map object
    • processBatchErrors

      private void processBatchErrors(List<org.alfresco.service.cmr.repository.NodeRef> nodeRefs, Map<String,Set<org.alfresco.service.cmr.repository.NodeRef>> batchNodesMap)

      processBatchErrors.

      Parameters:
      nodeRefs - a List object
      batchNodesMap - a Map object
    • retryBatchInError

      public BatchInfo retryBatchInError(String batchErrorId)

      retryBatchInError.

      Specified by:
      retryBatchInError in interface BatchQueueService
      Parameters:
      batchErrorId - a String object
      Returns:
      a BatchInfo object
    • 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:
      createBatchStepWithErrorHandling in interface BatchQueueService
      Parameters:
      batchInfo - a BatchInfo object
      list - a List object
      processor - a BatchProcessor.BatchProcessWorker object
      Returns:
      a BatchStep object
    • 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:
      createBatchStepWithErrorHandling in interface BatchQueueService
      Parameters:
      batchInfo - a BatchInfo object
      list - a List object
      processor - a BatchProcessor.BatchProcessWorker object
      errorHandler - a BiConsumer object
      Returns:
      a BatchStep object
    • 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 - a String object
      entry - a NodeRef object
      Returns:
      a boolean
    • discardEntry

      private void discardEntry(String batchFullId, org.alfresco.service.cmr.repository.NodeRef entry)

      discardEntry.

      Parameters:
      batchFullId - a String object
      entry - a NodeRef object
    • 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.
      Parameters:
      batchFullId - a String object
      entry - a NodeRef object
      batchErrorIds - a List object
      Throws:
      Exception - if the flag cannot be written and the transaction has to be retried
    • viewErrors

      public String viewErrors(String batchId)

      viewErrors.

      Specified by:
      viewErrors in interface BatchQueueService
      Parameters:
      batchId - a String object
      Returns:
      a String object
    • onApplicationEvent

      public void onApplicationEvent(org.alfresco.repo.batch.BatchMonitorEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.alfresco.repo.batch.BatchMonitorEvent>