public void Process(string firstLine, NetworkStream stream, ILogger logger)
        {
            var parts = firstLine.Split(new[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);

            switch (parts[0])
            {
            case "FOUND":
                var id    = Convert.ToInt32(parts[1]);
                var bytes = Convert.ToInt32(parts[2]);
                Job descr;
                if (ReserveRequest.TryGetJobFromBuffer(id, stream, bytes, out descr))
                {
                    _tcs.SetResult(descr);
                }
                else
                {
                    _tcs.SetException(new Exception("Unable to parse job description"));
                }
                return;

            case "NOT_FOUND":
                _tcs.SetResult(null);
                return;

            default:
                if (_id == null)
                {
                    var command = _state == JobState.Ready ? "peek-ready" :
                                  _state == JobState.Buried ? "peek-buried" :
                                  _state == JobState.Delayed ? "peek-delayed" :
                                  "unknown peek";
                    Reply.SetGeneralException(_tcs, firstLine, command, logger);
                }
                else
                {
                    Reply.SetGeneralException(_tcs, firstLine, "peek", logger);
                }
                return;
            }
        }
Example #2
0
        Task <Job> IConsumer.ReserveAsync()
        {
            var request = new ReserveRequest();

            return(SendAndGetResult(request));
        }
Example #3
0
        /// <summary>
        /// This is purposefully not part of any interface, it exists for worker loops.
        /// Cancelling the token will end up desynchronizing the reactor
        /// inside the PhysicalConnection so this should only be cancelled
        /// if the connection is being torn down anyway.
        /// </summary>
        Task <Job> ReserveAsync(CancellationToken cancellationToken)
        {
            var request = new ReserveRequest();

            return(SendAndGetResult(request, cancellationToken));
        }
Example #4
0
        Task <Job> IConsumer.ReserveAsync(TimeSpan timeout)
        {
            var request = new ReserveRequest(timeout);

            return(SendAndGetResult(request));
        }