use of org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerImpl method addPendingRequest.
@Override
public void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine) {
Long asyncResponseTimeout = dto.getAsyncResponseTimeout();
if (asyncResponseTimeout != null && asyncResponseTimeout > MAX_TIMEOUT) {
invalidRequest(asyncResponse, "The asynchronous response timeout cannot be set to a value greater than " + MAX_TIMEOUT + " milliseconds");
return;
}
IdentityService identityService = processEngine.getIdentityService();
Authentication authentication = identityService.getCurrentAuthentication();
FetchAndLockRequest incomingRequest = new FetchAndLockRequest().setProcessEngine(processEngine).setAsyncResponse(asyncResponse).setAuthentication(authentication).setDto(dto);
FetchAndLockResult result = tryFetchAndLock(incomingRequest);
if (result.wasSuccessful()) {
List<LockedExternalTaskDto> lockedTasks = result.getTasks();
if (!lockedTasks.isEmpty() || dto.getAsyncResponseTimeout() == null) {
// response immediately if tasks available
asyncResponse.resume(lockedTasks);
} else {
addRequest(incomingRequest);
}
} else {
ProcessEngineException processEngineException = result.getProcessEngineException();
asyncResponse.resume(processEngineException);
}
}
use of org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerImpl method acquire.
protected void acquire() {
queue.drainTo(pendingRequests);
// timestamp
long backoffTime = MAX_BACK_OFF_TIME;
Iterator<FetchAndLockRequest> iterator = pendingRequests.iterator();
while (iterator.hasNext()) {
FetchAndLockRequest pendingRequest = iterator.next();
long currentTime = ClockUtil.getCurrentTime().getTime();
FetchAndLockResult result = tryFetchAndLock(pendingRequest);
if (result.wasSuccessful()) {
List<LockedExternalTaskDto> lockedTasks = result.getTasks();
long timeout = pendingRequest.getTimeoutTimestamp();
if (!lockedTasks.isEmpty() || timeout <= currentTime) {
AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
iterator.remove();
asyncResponse.resume(lockedTasks);
} else {
if (timeout < backoffTime) {
backoffTime = timeout;
}
}
} else {
AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
iterator.remove();
ProcessEngineException processEngineException = result.getProcessEngineException();
asyncResponse.resume(processEngineException);
}
}
suspend(Math.max(0, backoffTime - ClockUtil.getCurrentTime().getTime()));
}
use of org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerImpl method tryFetchAndLock.
protected FetchAndLockResult tryFetchAndLock(FetchAndLockRequest request) {
ProcessEngine processEngine = request.getProcessEngine();
IdentityService identityService = processEngine.getIdentityService();
FetchAndLockResult result;
try {
identityService.setAuthentication(request.getAuthentication());
FetchExternalTasksExtendedDto fetchingDto = request.getDto();
List<LockedExternalTaskDto> lockedTasks = executeFetchAndLock(fetchingDto, processEngine);
result = FetchAndLockResult.successful(lockedTasks);
} catch (ProcessEngineException e) {
result = FetchAndLockResult.failed(e);
} finally {
identityService.clearAuthentication();
}
return result;
}
Aggregations