@Override public Queue updateQueue(String queuePath, Queue queue) { queue.setPath(queuePath); UUID timestampUuid = newTimeUUID(); long timestamp = getTimestampInMicros(timestampUuid); Mutator<ByteBuffer> batch = createMutator(cass.getApplicationKeyspace(applicationId), be); addQueueToMutator(batch, queue, timestamp); try { batchUpdateQueuePropertiesIndexes( batch, queuePath, queue.getUuid(), queue.getProperties(), timestampUuid); } catch (Exception e) { logger.error("Unable to update queue", e); } batch.addInsertion( bytebuffer(queue.getUuid()), QUEUE_PROPERTIES.getColumnFamily(), createColumn(QUEUE_CREATED, timestamp / 1000, Long.MAX_VALUE - timestamp, se, le)); batch.addInsertion( bytebuffer(queue.getUuid()), QUEUE_PROPERTIES.getColumnFamily(), createColumn(QUEUE_MODIFIED, timestamp / 1000, timestamp, se, le)); batchExecute(batch, RETRY_COUNT); return queue; }
public Queue getQueue(String queuePath, UUID queueId) { SliceQuery<UUID, String, ByteBuffer> q = createSliceQuery(cass.getApplicationKeyspace(applicationId), ue, se, be); q.setColumnFamily(QUEUE_PROPERTIES.getColumnFamily()); q.setKey(queueId); q.setRange(null, null, false, ALL_COUNT); QueryResult<ColumnSlice<String, ByteBuffer>> r = q.execute(); ColumnSlice<String, ByteBuffer> slice = r.get(); List<HColumn<String, ByteBuffer>> results = slice.getColumns(); return deserializeQueue(results); }
/** * Get the bounds for the queue * * @param ko * @param queueId * @return */ protected QueueBounds getQueueBounds(UUID queueId) { try { ColumnSlice<String, UUID> result = HFactory.createSliceQuery(ko, ue, se, ue) .setKey(queueId) .setColumnNames(QUEUE_NEWEST, QUEUE_OLDEST) .setColumnFamily(QUEUE_PROPERTIES.getColumnFamily()) .execute() .get(); if (result != null && result.getColumnByName(QUEUE_OLDEST) != null && result.getColumnByName(QUEUE_NEWEST) != null) { return new QueueBounds( result.getColumnByName(QUEUE_OLDEST).getValue(), result.getColumnByName(QUEUE_NEWEST).getValue()); } } catch (Exception e) { logger.error("Error getting oldest queue message ID", e); } return null; }
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; }