@Override public List<Subscription> listAllSubscriptions() { LOG.debug("Retrieving existing subscriptions"); List<Subscription> results = new ArrayList<>(); Cursor<String, Subscription> mapCursor = subscriptions.cursor(null); while (mapCursor.hasNext()) { String subscriptionStr = mapCursor.next(); results.add(mapCursor.getValue()); } LOG.debug("Loaded {} subscriptions", results.size()); return results; }
/** * Iterate over a number of keys. * * @param from the first key to return * @return the iterator */ public Iterator<K> keyIterator(K from) { return new Cursor<K, V>(this, root, from); }
/** * Skip over that many entries. This method is relatively fast (for this map * implementation) even if many entries need to be skipped. * * @param n the number of entries to skip */ public void skip(long n) { if (!hasNext()) { return; } if (n < 10) { while (n-- > 0) { fetchNext(); } return; } long index = map.getKeyIndex(current); K k = map.getKey(index + n); pos = null; min(root, k); fetchNext(); }
/** * Fetch the next entry if there is one. */ @SuppressWarnings("unchecked") private void fetchNext() { while (pos != null) { if (pos.index < pos.page.getKeyCount()) { int index = pos.index++; current = (K) pos.page.getKey(index); currentValue = (V) pos.page.getValue(index); return; } pos = pos.parent; if (pos == null) { break; } if (pos.index < map.getChildPageCount(pos.page)) { min(pos.page.getChildPage(pos.index++), null); } } current = null; }
/** * Fetch the next entry if there is one. */ @SuppressWarnings("unchecked") private void fetchNext() { while (pos != null) { if (pos.index < pos.page.getKeyCount()) { int index = pos.index++; current = (K) pos.page.getKey(index); currentValue = (V) pos.page.getValue(index); return; } pos = pos.parent; if (pos == null) { break; } if (pos.index < map.getChildPageCount(pos.page)) { min(pos.page.getChildPage(pos.index++), null); } } current = null; }
private Set<Integer> collectReferencedChunks() { long testVersion = lastChunk.version; DataUtils.checkArgument(testVersion > 0, "Collect references on version 0"); long readCount = getFileStore().readCount.get(); Set<Integer> referenced = new HashSet<>(); for (Cursor<String, String> c = meta.cursor("root."); c.hasNext();) { String key = c.next(); if (!key.startsWith("root.")) { break; } long pos = DataUtils.parseHexLong(c.getValue()); if (pos == 0) { continue; } int mapId = DataUtils.parseHexInt(key.substring("root.".length())); collectReferencedChunks(referenced, mapId, pos, 0); } long pos = lastChunk.metaRootPos; collectReferencedChunks(referenced, 0, pos, 0); readCount = fileStore.readCount.get() - readCount; return referenced; }
/** * Skip over that many entries. This method is relatively fast (for this map * implementation) even if many entries need to be skipped. * * @param n the number of entries to skip */ public void skip(long n) { if (!hasNext()) { return; } if (n < 10) { while (n-- > 0) { fetchNext(); } return; } long index = map.getKeyIndex(current); K k = map.getKey(index + n); pos = null; min(root, k); fetchNext(); }
/** * Get a cursor to iterate over a number of keys and values. * * @param from the first key to return * @return the cursor */ public Cursor<K, V> cursor(K from) { return new Cursor<>(this, root, from); }