/** * Scan all cells in a row. * * @param row * the row to scan. * @param family * if not null, the family to filter and return. * @return iterator for the cells. Cells may appear in any order, including * random. Never null. */ public Iterable<Cell> scanFamily(byte[] row, ColumnMatcher family) { synchronized (lock) { Map<Key, Cell> r = map.get(new Key(row)); if (r == null) return Collections.emptyList(); if (family == null) return new ArrayList<Cell>(r.values()); ArrayList<Cell> out = new ArrayList<Cell>(4); for (Cell cell : r.values()) { if (family.sameFamily(cell.getName())) out.add(cell); } return out; } }
/** * Scan all cells in a row. * * @param row * the row to scan. * @param family * if not null, the family to filter and return. * @return iterator for the cells. Cells may appear in any order, including * random. Never null. */ public Iterable<Cell> scanFamily(byte[] row, ColumnMatcher family) { synchronized (lock) { Map<Key, Cell> r = map.get(new Key(row)); if (r == null) return Collections.emptyList(); if (family == null) return new ArrayList<Cell>(r.values()); ArrayList<Cell> out = new ArrayList<Cell>(4); for (Cell cell : r.values()) { if (family.sameFamily(cell.getName())) out.add(cell); } return out; } }
public Collection<CachedPackInfo> getCachedPacks(RepositoryKey repo) throws DhtException, TimeoutException { List<CachedPackInfo> out = new ArrayList<CachedPackInfo>(4); for (MemTable.Cell cell : table.scanFamily(repo.asBytes(), colCachedPack)) { try { out.add(CachedPackInfo.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException e) { throw new DhtException(MessageFormat.format( DhtText.get().invalidCachedPackInfo, repo, CachedPackKey.fromBytes(cell.getName())), e); } } return out; }
public void get(Context options, Set<ObjectIndexKey> objects, AsyncCallback<Map<ObjectIndexKey, Collection<ObjectInfo>>> callback) { Map<ObjectIndexKey, Collection<ObjectInfo>> out = new HashMap<ObjectIndexKey, Collection<ObjectInfo>>(); for (ObjectIndexKey objId : objects) { for (MemTable.Cell cell : table.scanFamily(objId.asBytes(), colInfo)) { Collection<ObjectInfo> chunks = out.get(objId); ChunkKey chunkKey; if (chunks == null) { chunks = new ArrayList<ObjectInfo>(4); out.put(objId, chunks); } chunkKey = ChunkKey.fromBytes(colInfo.suffix(cell.getName())); try { chunks.add(new ObjectInfo( chunkKey, cell.getTimestamp(), GitStore.ObjectInfo.parseFrom(cell.getValue()))); } catch (InvalidProtocolBufferException badCell) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidObjectInfo, objId, chunkKey), badCell)); return; } } } callback.onSuccess(out); }
public void get(Context options, Set<ObjectIndexKey> objects, AsyncCallback<Map<ObjectIndexKey, Collection<ObjectInfo>>> callback) { Map<ObjectIndexKey, Collection<ObjectInfo>> out = new HashMap<ObjectIndexKey, Collection<ObjectInfo>>(); for (ObjectIndexKey objId : objects) { for (MemTable.Cell cell : table.scanFamily(objId.asBytes(), colInfo)) { Collection<ObjectInfo> chunks = out.get(objId); ChunkKey chunkKey; if (chunks == null) { chunks = new ArrayList<ObjectInfo>(4); out.put(objId, chunks); } chunkKey = ChunkKey.fromBytes(colInfo.suffix(cell.getName())); try { chunks.add(new ObjectInfo( chunkKey, cell.getTimestamp(), GitStore.ObjectInfo.parseFrom(cell.getValue()))); } catch (InvalidProtocolBufferException badCell) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidObjectInfo, objId, chunkKey), badCell)); return; } } } callback.onSuccess(out); }
public Collection<CachedPackInfo> getCachedPacks(RepositoryKey repo) throws DhtException, TimeoutException { List<CachedPackInfo> out = new ArrayList<CachedPackInfo>(4); for (MemTable.Cell cell : table.scanFamily(repo.asBytes(), colCachedPack)) { try { out.add(CachedPackInfo.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException e) { throw new DhtException(MessageFormat.format( DhtText.get().invalidCachedPackInfo, repo, CachedPackKey.fromBytes(cell.getName())), e); } } return out; }
public Map<RefKey, RefData> getAll(Context options, RepositoryKey repository) throws DhtException, TimeoutException { Map<RefKey, RefData> out = new HashMap<RefKey, RefData>(); for (MemTable.Cell cell : table.scanFamily(repository.asBytes(), colRef)) { RefKey ref = RefKey.fromBytes(colRef.suffix(cell.getName())); try { out.put(ref, RefData.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException badCell) { throw new DhtException(MessageFormat.format( DhtText.get().invalidRefData, ref), badCell); } } return out; }
public Map<RefKey, RefData> getAll(Context options, RepositoryKey repository) throws DhtException, TimeoutException { Map<RefKey, RefData> out = new HashMap<RefKey, RefData>(); for (MemTable.Cell cell : table.scanFamily(repository.asBytes(), colRef)) { RefKey ref = RefKey.fromBytes(colRef.suffix(cell.getName())); try { out.put(ref, RefData.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException badCell) { throw new DhtException(MessageFormat.format( DhtText.get().invalidRefData, ref), badCell); } } return out; }