예제 #1
0
  @Override
  public void schedulePush(final PullMessageTask task) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Schedule push(correlation id: {}) for client: {}",
          task.getCorrelationId(),
          task.getTpg());
    }

    if (m_stopped.get() || (task.isWithOffset() && task.getStartOffset() == null)) {
      response(task, null, null);
    } else {
      m_scheduledThreadPool.submit(
          new Runnable() {
            @Override
            public void run() {
              executeTask(
                  task,
                  new ExponentialSchedulePolicy( //
                      m_config.getLongPollingCheckIntervalBaseMillis(), //
                      m_config.getLongPollingCheckIntervalMaxMillis()));
            }
          });
    }
  }
예제 #2
0
  private boolean queryAndResponseData(PullMessageTask pullTask) {
    Tpg tpg = pullTask.getTpg();

    MessageQueueCursor cursor =
        m_queueManager.getCursor(tpg, pullTask.getBrokerLease(), pullTask.getStartOffset());

    if (cursor == null) {
      return false;
    }

    Pair<Offset, List<TppConsumerMessageBatch>> p = null;

    try {
      p = cursor.next(pullTask.getBatchSize());
    } finally {
      cursor.stop();
    }

    if (p != null) {
      Offset currentOffset = p.getKey();
      List<TppConsumerMessageBatch> batches = p.getValue();

      if (batches != null && !batches.isEmpty()) {

        String ip = NettyUtils.parseChannelRemoteAddr(pullTask.getChannel(), false);
        for (TppConsumerMessageBatch batch : batches) {
          // TODO remove legacy code
          boolean needServerSideAckHolder =
              pullTask.getPullMessageCommandVersion() < 3 ? true : false;
          m_queueManager.delivered(
              batch, tpg.getGroupId(), pullTask.isWithOffset(), needServerSideAckHolder);

          bizLogDelivered(ip, batch.getMessageMetas(), tpg);
        }

        response(pullTask, batches, currentOffset);
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }