Exemplo n.º 1
0
        private void PullMessages(Endpoint endpoint, int timeout, BasePullMessagesTask task)
        {
            SettableFuture<PullMessageResultCommandV2> future = SettableFuture<PullMessageResultCommandV2>.Create();
            PullMessageCommandV2 cmd = task.CreatePullMessageCommand(timeout);

            cmd.Header.CorrelationId = task.CorrelationId;
            cmd.setFuture(future);

            PullMessageResultCommandV2 ack = null;

            try
            {
                PullMessageResultMonitor.Monitor(cmd);
                EndpointClient.WriteCommand(endpoint, cmd, timeout);

                try
                {
                    ack = future.Get(timeout);
                }
                catch
                {
                }
                finally
                {
                    PullMessageResultMonitor.Remove(cmd);
                }

                if (ack != null)
                {
                    AppendMsgToQueue(ack, task.CorrelationId);
                    task.ResultReceived(ack);
                }
            }
            finally
            {
                if (ack != null)
                {
                    ack.Release();
                }
            }
        }