@Override public QueueSet searchSubscribers(String publisherQueuePath, Query query) { if (query == null) { query = new Query(); } publisherQueuePath = normalizeQueuePath(publisherQueuePath); UUID publisherQueueId = getQueueId(publisherQueuePath); if (!query.hasFilterPredicates() && !query.hasSortPredicates()) { return getSubscribers(publisherQueuePath, null, query.getLimit()); } QueueSet results = null; String composite_cursor = null; QueryProcessor qp = new QueryProcessor(query); List<QuerySlice> slices = qp.getSlices(); int search_count = query.getLimit() + 1; if (slices.size() > 1) { search_count = DEFAULT_SEARCH_COUNT; } for (QuerySlice slice : slices) { QueueSet r = null; try { r = searchQueueIndex(publisherQueueId, slice, search_count); } catch (Exception e) { logger.error("Error during search", e); } if (r == null) { continue; } if (r.size() > query.getLimit()) { r.setCursorToLastResult(); } if (r.getCursor() != null) { if (composite_cursor != null) { composite_cursor += "|"; } else { composite_cursor = ""; } int hashCode = slice.hashCode(); logger.info("Cursor hash code: {} ", hashCode); composite_cursor += hashCode + ":" + r.getCursor(); } if (results != null) { results.and(r); } else { results = r; } } return results; }
public QueueSet searchQueueIndex(UUID publisherQueueId, QuerySlice slice, int count) throws Exception { ByteBuffer start = null; if (slice.getCursor() != null) { start = slice.getCursor(); } else if (slice.getStart() != null) { DynamicComposite s = new DynamicComposite(slice.getStart().getCode(), slice.getStart().getValue()); if (!slice.getStart().isInclusive()) { setEqualityFlag(s, ComponentEquality.GREATER_THAN_EQUAL); } start = s.serialize(); } ByteBuffer finish = null; if (slice.getFinish() != null) { DynamicComposite f = new DynamicComposite(slice.getFinish().getCode(), slice.getFinish().getValue()); if (slice.getFinish().isInclusive()) { setEqualityFlag(f, ComponentEquality.GREATER_THAN_EQUAL); } finish = f.serialize(); } if (slice.isReversed() && (start != null) && (finish != null)) { ByteBuffer temp = start; start = finish; finish = temp; } List<HColumn<ByteBuffer, ByteBuffer>> results = createSliceQuery(cass.getApplicationKeyspace(applicationId), be, be, be) .setColumnFamily(PROPERTY_INDEX.getColumnFamily()) .setKey(bytebuffer(key(publisherQueueId, slice.getPropertyName()))) .setRange(start, finish, slice.isReversed(), count) .execute() .get() .getColumns(); QueueSet queues = new QueueSet(); for (HColumn<ByteBuffer, ByteBuffer> column : results) { DynamicComposite c = DynamicComposite.fromByteBuffer(column.getName()); queues.addQueue(c.get(3, se), c.get(2, ue)); } return queues; }