コード例 #1
0
        protected internal virtual bool isExpired(FetchAndLockRequest request)
        {
            long currentTime = ClockUtil.CurrentTime.Ticks;
            long timeout     = request.TimeoutTimestamp;

            return(timeout <= currentTime);
        }
コード例 #2
0
        protected internal virtual FetchAndLockResult tryFetchAndLock(FetchAndLockRequest request)
        {
            ProcessEngine      processEngine   = null;
            IdentityService    identityService = null;
            FetchAndLockResult result          = null;

            try
            {
                processEngine = getProcessEngine(request);

                identityService = processEngine.IdentityService;
                identityService.Authentication = request.Authentication;

                FetchExternalTasksExtendedDto fetchingDto = request.Dto;
                IList <LockedExternalTaskDto> lockedTasks = executeFetchAndLock(fetchingDto, processEngine);
                result = FetchAndLockResult.successful(lockedTasks);
            }
            catch (Exception e)
            {
                result = FetchAndLockResult.failed(e);
            }
            finally
            {
                if (identityService != null)
                {
                    identityService.clearAuthentication();
                }
            }

            return(result);
        }
コード例 #3
0
        protected internal virtual void addRequest(FetchAndLockRequest request)
        {
            if (!queue.offer(request))
            {
                AsyncResponse asyncResponse = request.AsyncResponse;
                errorTooManyRequests(asyncResponse);
            }

            condition.signal();
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        protected internal virtual void removeDuplicates()
        {
            foreach (FetchAndLockRequest newRequest in newRequests)
            {
                // remove any request from pendingRequests with the same worker id
                IEnumerator <FetchAndLockRequest> iterator = pendingRequests.GetEnumerator();
                while (iterator.MoveNext())
                {
                    FetchAndLockRequest pendingRequest = iterator.Current;
                    if (pendingRequest.Dto.WorkerId.Equals(newRequest.Dto.WorkerId))
                    {
                        AsyncResponse asyncResponse = pendingRequest.AsyncResponse;
                        asyncResponse.cancel();

//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        iterator.remove();
                    }
                }
            }
        }
コード例 #6
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));
            }
        }
コード例 #7
0
        protected internal virtual ProcessEngine getProcessEngine(FetchAndLockRequest request)
        {
            string processEngineName = request.ProcessEngineName;

            return(EngineUtil.lookupProcessEngine(processEngineName));
        }