@Override public void incrementQueueCounter(String queuePath, String name, long value) { long timestamp = cass.createTimestamp(); Mutator<ByteBuffer> m = createMutator(cass.getApplicationKeyspace(applicationId), be); counterUtils.batchIncrementQueueCounter( m, getQueueId(queuePath), name, value, timestamp, applicationId); batchExecute(m, CassandraService.RETRY_COUNT); }
public AggregateCounterSet getAggregateCounters( UUID queueId, String category, String counterName, CounterResolution resolution, long start, long finish, boolean pad) { start = resolution.round(start); finish = resolution.round(finish); long expected_time = start; Keyspace ko = cass.getApplicationKeyspace(applicationId); SliceCounterQuery<String, Long> q = createCounterSliceQuery(ko, se, le); q.setColumnFamily(APPLICATION_AGGREGATE_COUNTERS.getColumnFamily()); q.setRange(start, finish, false, ALL_COUNT); QueryResult<CounterSlice<Long>> r = q.setKey( counterUtils.getAggregateCounterRow( counterName, null, null, queueId, category, resolution)) .execute(); List<AggregateCounter> counters = new ArrayList<AggregateCounter>(); for (HCounterColumn<Long> column : r.get().getColumns()) { AggregateCounter count = new AggregateCounter(column.getName(), column.getValue()); if (pad && !(resolution == CounterResolution.ALL)) { while (count.getTimestamp() != expected_time) { counters.add(new AggregateCounter(expected_time, 0)); expected_time = resolution.next(expected_time); } expected_time = resolution.next(expected_time); } counters.add(count); } if (pad && !(resolution == CounterResolution.ALL)) { while (expected_time <= finish) { counters.add(new AggregateCounter(expected_time, 0)); expected_time = resolution.next(expected_time); } } return new AggregateCounterSet(counterName, queueId, category, counters); }
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; }