Ejemplo 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();
                }
            }
        }
Ejemplo n.º 2
0
        private void PullMessagesTaskRun(BasePullMessagesTask task)
        {
            try
            {
                if (IsClosed() || msgs.Count > 0)
                {
                    return;
                }

                Endpoint endpoint = EndpointManager.GetEndpoint(Context.Topic.Name, PartitionId);

                if (endpoint == null)
                {
                    log.Warn(string.Format("No endpoint found for topic {0} partition {1}, will retry later",
                            Context.Topic.Name, PartitionId));
                    task.NoEndpointSchedulePolicy.Fail(true);
                    return;
                }
                else
                {
                    task.NoEndpointSchedulePolicy.Succeess();
                }


                ILease lease = leaseRef.ReadFullFence();
                if (lease != null)
                {
                    int timeout = (int)lease.RemainingTime;

                    if (timeout > 0)
                    {
                        PullMessages(endpoint, timeout, task);
                    }
                }
            }
            catch (Exception e)
            {
                ITransaction t = Cat.NewTransaction("Message.Pull.Internal", Context.Topic.Name);
                t.Status = CatConstants.SUCCESS;
                t.AddData("msg", e.Message);
                t.Complete();
            }
            finally
            {
                pullTaskRunning.WriteFullFence(false);
            }
        }