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);
}
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);
}
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.
}
}
Aggregations