Example #1
0
  private boolean shouldMerge(MessageQueue trees) {
    MessageTree tree = trees.peek();

    if (tree != null) {
      long firstTime = tree.getMessage().getTimestamp();
      int maxDuration = 1000 * 30;

      if (System.currentTimeMillis() - firstTime > maxDuration
          || trees.size() >= MAX_CHILD_NUMBER) {
        return true;
      }
    }
    return false;
  }
Example #2
0
  @Override
  public void run() {
    m_active = true;

    while (m_active) {
      ChannelFuture channel = m_manager.channel();

      if (channel != null && checkWritable(channel)) {
        try {
          MessageTree tree = m_queue.poll();

          if (tree != null) {
            sendInternal(tree);
            tree.setMessage(null);
          }

        } catch (Throwable t) {
          m_logger.error("Error when sending message over TCP socket!", t);
        }
      } else {
        try {
          Thread.sleep(5);
        } catch (Exception e) {
          // ignore it
          m_active = false;
        }
      }
    }
  }
Example #3
0
  @Override
  public void send(MessageTree tree) {
    if (isAtomicMessage(tree)) {
      boolean result = m_atomicTrees.offer(tree, m_manager.getSample());

      if (!result) {
        logQueueFullInfo(tree);
      }
    } else {
      boolean result = m_queue.offer(tree, m_manager.getSample());

      if (!result) {
        logQueueFullInfo(tree);
      }
    }
  }
Example #4
0
  private MessageTree mergeTree(MessageQueue trees) {
    int max = MAX_CHILD_NUMBER;
    DefaultTransaction tran = new DefaultTransaction("_CatMergeTree", "_CatMergeTree", null);
    MessageTree first = trees.poll();

    tran.setStatus(Transaction.SUCCESS);
    tran.setCompleted(true);
    tran.setDurationInMicros(0);
    tran.addChild(first.getMessage());

    while (max >= 0) {
      MessageTree tree = trees.poll();

      if (tree == null) {
        break;
      }
      tran.addChild(tree.getMessage());
      m_factory.reuse(tree.getMessageId());
      max--;
    }
    ((DefaultMessageTree) first).setMessage(tran);
    return first;
  }