Пример #1
0
    /*
     * (non-Javadoc)
     *
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Message o1, Message o2) {
      int o1Idx = indexCache.get(o1.getUuid());

      int o2Idx = indexCache.get(o2.getUuid());

      return o1Idx - o2Idx;
    }
Пример #2
0
  public Message batchPostToQueue(
      Mutator<ByteBuffer> batch,
      String queuePath,
      Message message,
      MessageIndexUpdate indexUpdate,
      long timestamp) {

    queuePath = normalizeQueuePath(queuePath);
    UUID queueId = getQueueId(queuePath);

    message.sync();

    addMessageToMutator(batch, message, timestamp);

    long shard_ts = roundLong(message.getTimestamp(), QUEUE_SHARD_INTERVAL);

    logger.debug("Adding message with id '{}' to queue '{}'", message.getUuid(), queueId);

    batch.addInsertion(
        getQueueShardRowKey(queueId, shard_ts),
        QUEUE_INBOX.getColumnFamily(),
        createColumn(message.getUuid(), ByteBuffer.allocate(0), timestamp, ue, be));

    long oldest_ts = Long.MAX_VALUE - getTimestampInMicros(message.getUuid());
    batch.addInsertion(
        bytebuffer(queueId),
        QUEUE_PROPERTIES.getColumnFamily(),
        createColumn(QUEUE_OLDEST, message.getUuid(), oldest_ts, se, ue));

    long newest_ts = getTimestampInMicros(message.getUuid());
    batch.addInsertion(
        bytebuffer(queueId),
        QUEUE_PROPERTIES.getColumnFamily(),
        createColumn(QUEUE_NEWEST, message.getUuid(), newest_ts, se, ue));

    batch.addInsertion(
        bytebuffer(getQueueId("/")),
        QUEUE_SUBSCRIBERS.getColumnFamily(),
        createColumn(queuePath, queueId, timestamp, se, ue));

    counterUtils.batchIncrementQueueCounter(
        batch, getQueueId("/"), queuePath, 1L, timestamp, applicationId);

    if (indexUpdate == null) {
      indexUpdate = new MessageIndexUpdate(message);
    }
    indexUpdate.addToMutation(batch, queueId, shard_ts, timestamp);

    counterUtils.addMessageCounterMutations(batch, applicationId, queueId, message, timestamp);

    batch.addInsertion(
        bytebuffer(queueId),
        QUEUE_PROPERTIES.getColumnFamily(),
        createColumn(QUEUE_CREATED, timestamp / 1000, Long.MAX_VALUE - timestamp, se, le));

    batch.addInsertion(
        bytebuffer(queueId),
        QUEUE_PROPERTIES.getColumnFamily(),
        createColumn(QUEUE_MODIFIED, timestamp / 1000, timestamp, se, le));

    return message;
  }