Esempio n. 1
0
 protected internal virtual void rejectPendingRequests()
 {
     foreach (FetchAndLockRequest pendingRequest in pendingRequests)
     {
         AsyncResponse asyncResponse = pendingRequest.AsyncResponse;
         asyncResponse.resume(new RestException(Status.INTERNAL_SERVER_ERROR, "Request rejected due to shutdown of application server."));
     }
 }
Esempio n. 2
0
        public virtual void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine)
        {
            long?asyncResponseTimeout = dto.AsyncResponseTimeout;

            if (asyncResponseTimeout != null && asyncResponseTimeout.Value > MAX_REQUEST_TIMEOUT)
            {
                asyncResponse.resume(new InvalidRequestException(Status.BAD_REQUEST, "The asynchronous response timeout cannot be set to a value greater than " + MAX_REQUEST_TIMEOUT + " milliseconds"));
                return;
            }

            IdentityService identityService   = processEngine.IdentityService;
            Authentication  authentication    = identityService.CurrentAuthentication;
            string          processEngineName = processEngine.Name;

            FetchAndLockRequest incomingRequest = (new FetchAndLockRequest()).setProcessEngineName(processEngineName).setAsyncResponse(asyncResponse).setAuthentication(authentication).setDto(dto);

            LOG.log(Level.FINEST, "New request: {0}", incomingRequest);

            FetchAndLockResult result = tryFetchAndLock(incomingRequest);

            LOG.log(Level.FINEST, "Fetch and lock result: {0}", result);

            if (result.wasSuccessful())
            {
                IList <LockedExternalTaskDto> lockedTasks = result.Tasks;
                if (lockedTasks.Count > 0 || dto.AsyncResponseTimeout == null)
                {   // response immediately if tasks available
                    asyncResponse.resume(lockedTasks);

                    LOG.log(Level.FINEST, "Resuming request with {0}", lockedTasks);
                }
                else
                {
                    addRequest(incomingRequest);

                    LOG.log(Level.FINEST, "Deferred request");
                }
            }
            else
            {
                Exception processEngineException = result.Throwable;
                asyncResponse.resume(processEngineException);

                LOG.log(Level.FINEST, "Resuming request with error {0}", processEngineException);
            }
        }
Esempio n. 3
0
        protected internal virtual void acquire()
        {
            LOG.log(Level.FINEST, "Acquire start");

            queue.drainTo(newRequests);

            if (newRequests.Count > 0)
            {
                if (isUniqueWorkerRequest)
                {
                    removeDuplicates();
                }

                ((IList <FetchAndLockRequest>)pendingRequests).AddRange(newRequests);
                newRequests.Clear();
            }

            LOG.log(Level.FINEST, "Number of pending requests {0}", pendingRequests.Count);

            long backoffTime = MAX_BACK_OFF_TIME;     //timestamp

            IEnumerator <FetchAndLockRequest> iterator = pendingRequests.GetEnumerator();

            while (iterator.MoveNext())
            {
                FetchAndLockRequest pendingRequest = iterator.Current;

                LOG.log(Level.FINEST, "Fetching tasks for request {0}", pendingRequest);

                FetchAndLockResult result = tryFetchAndLock(pendingRequest);

                LOG.log(Level.FINEST, "Fetch and lock result: {0}", result);

                if (result.wasSuccessful())
                {
                    IList <LockedExternalTaskDto> lockedTasks = result.Tasks;

                    if (lockedTasks.Count > 0 || isExpired(pendingRequest))
                    {
                        AsyncResponse asyncResponse = pendingRequest.AsyncResponse;
                        asyncResponse.resume(lockedTasks);

                        LOG.log(Level.FINEST, "resume and remove request with {0}", lockedTasks);

//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        iterator.remove();
                    }
                    else
                    {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long msUntilTimeout = pendingRequest.getTimeoutTimestamp() - org.camunda.bpm.engine.impl.util.ClockUtil.getCurrentTime().getTime();
                        long msUntilTimeout = pendingRequest.TimeoutTimestamp - ClockUtil.CurrentTime.Ticks;
                        backoffTime = Math.Min(backoffTime, msUntilTimeout);
                    }
                }
                else
                {
                    AsyncResponse asyncResponse          = pendingRequest.AsyncResponse;
                    Exception     processEngineException = result.Throwable;
                    asyncResponse.resume(processEngineException);

                    LOG.log(Level.FINEST, "Resume and remove request with error {0}", processEngineException);

//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                    iterator.remove();
                }
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long waitTime = Math.max(0, backoffTime);
            long waitTime = Math.Max(0, backoffTime);

            if (pendingRequests.Count == 0)
            {
                suspend(waitTime);
            }
            else
            {
                // if there are pending requests, try fetch periodically to ensure tasks created on other
                // cluster nodes and tasks with expired timeouts can be fetched in a timely manner
                suspend(Math.Min(PENDING_REQUEST_FETCH_INTERVAL, waitTime));
            }
        }
Esempio n. 4
0
        protected internal virtual void errorTooManyRequests(AsyncResponse asyncResponse)
        {
            string errorMessage = "At the moment the server has to handle too many requests at the same time. Please try again later.";

            asyncResponse.resume(new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, errorMessage));
        }