Search in sources :

Example 6 with TransactionalEventListener

use of org.springframework.transaction.event.TransactionalEventListener in project dhis2-core by dhis2.

the class FileResourceEventListener method save.

@TransactionalEventListener
@Async
public void save(FileSavedEvent fileSavedEvent) {
    DateTime startTime = DateTime.now();
    File file = fileSavedEvent.getFile();
    FileResource fileResource = fileResourceService.getFileResource(fileSavedEvent.getFileResource());
    String storageId = fileResourceContentStore.saveFileResourceContent(fileResource, file);
    Period timeDiff = new Period(startTime, DateTime.now());
    logMessage(storageId, fileResource, timeDiff);
}
Also used : Period(org.joda.time.Period) File(java.io.File) DateTime(org.joda.time.DateTime) Async(org.springframework.scheduling.annotation.Async) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener)

Example 7 with TransactionalEventListener

use of org.springframework.transaction.event.TransactionalEventListener in project dhis2-core by dhis2.

the class FileResourceEventListener method saveBinaryFile.

@TransactionalEventListener
@Async
public void saveBinaryFile(BinaryFileSavedEvent binaryFileSavedEvent) {
    DateTime startTime = DateTime.now();
    byte[] bytes = binaryFileSavedEvent.getBytes();
    FileResource fileResource = fileResourceService.getFileResource(binaryFileSavedEvent.getFileResource());
    String storageId = fileResourceContentStore.saveFileResourceContent(fileResource, bytes);
    Period timeDiff = new Period(startTime, DateTime.now());
    logMessage(storageId, fileResource, timeDiff);
}
Also used : Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) Async(org.springframework.scheduling.annotation.Async) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener)

Example 8 with TransactionalEventListener

use of org.springframework.transaction.event.TransactionalEventListener in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method executeInternal.

/**
 * Executes given initialized task asynchronously.
 * We need to wait to transaction commit, when asynchronous task is executed - data is prepared in previous transaction mainly
 *
 * @param futureTask
 */
@Transactional
@TransactionalEventListener
public synchronized <V> void executeInternal(LongRunningFutureTask<V> futureTask) {
    Assert.notNull(futureTask, "Future task is required.");
    LongRunningTaskExecutor<V> taskExecutor = futureTask.getExecutor();
    Assert.notNull(taskExecutor, "Task executor is required.");
    Assert.notNull(futureTask.getFutureTask(), "Future task wrapper is required.");
    // 
    if (securityService.getUsername().contentEquals(SecurityService.SYSTEM_NAME)) {
        // each LRT executed by system (~scheduler) will have new transaction context
        TransactionContextHolder.setContext(TransactionContextHolder.createEmptyContext());
    }
    // 
    markTaskAsRunning(getValidTask(taskExecutor));
    UUID longRunningTaskId = taskExecutor.getLongRunningTaskId();
    // 
    LOG.debug("Execute task [{}] asynchronously, logged user [{}], transaction: [{}].", longRunningTaskId, securityService.getUsername(), TransactionContextHolder.getContext().getTransactionId());
    try {
        executor.execute(futureTask.getFutureTask());
    } catch (RejectedExecutionException ex) {
        // thread pool queue is full - wait for another try
        UUID taskId = futureTask.getExecutor().getLongRunningTaskId();
        LOG.warn("Execute task [{}] asynchronously will be postponed, all threads are in use.", taskId);
        // 
        IdmLongRunningTaskDto task = service.get(taskId);
        markTaskAsCreated(task);
    // 
    // Throw exception here doesn't make sense - is after transaction listener => exception is not propagated to caller.
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TransactionalEventListener (org.springframework.transaction.event.TransactionalEventListener)8 Async (org.springframework.scheduling.annotation.Async)4 DateTime (org.joda.time.DateTime)3 Period (org.joda.time.Period)3 File (java.io.File)2 UUID (java.util.UUID)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AnnotationStateChangeEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.AnnotationStateChangeEvent)1 DocumentStateChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.DocumentStateChangedEvent)1 ProjectStateChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.ProjectStateChangedEvent)1 AnnotationStateChangeMessage (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.webhooks.json.AnnotationStateChangeMessage)1 DocumentStateChangeMessage (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.webhooks.json.DocumentStateChangeMessage)1 ProjectStateChangeMessage (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.webhooks.json.ProjectStateChangeMessage)1 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)1 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)1 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)1 EventContext (eu.bcvsolutions.idm.core.api.event.EventContext)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1