r.put(colKey, new Cell(row, col, newVal)); return true;
/** * 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; } }
r.put(colKey, new Cell(row, col, newVal)); return true;
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<ChunkKey> keys, AsyncCallback<Collection<PackChunk.Members>> callback) { int cnt = keys.size(); List<PackChunk.Members> out = new ArrayList<PackChunk.Members>(cnt); for (ChunkKey chunk : keys) { byte[] row = chunk.asBytes(); MemTable.Cell cell; cell = table.get(row, colData.name()); if (cell == null) continue; PackChunk.Members m = new PackChunk.Members(); m.setChunkKey(chunk); m.setChunkData(cell.getValue()); cell = table.get(row, colIndex.name()); if (cell != null) m.setChunkIndex(cell.getValue()); cell = table.get(row, colMeta.name()); if (cell != null) { try { m.setMeta(ChunkMeta.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException err) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidChunkMeta, chunk), err)); return; } } out.add(m); } 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 void get(Context options, Set<ChunkKey> keys, AsyncCallback<Collection<PackChunk.Members>> callback) { int cnt = keys.size(); List<PackChunk.Members> out = new ArrayList<PackChunk.Members>(cnt); for (ChunkKey chunk : keys) { byte[] row = chunk.asBytes(); MemTable.Cell cell; cell = table.get(row, colData.name()); if (cell == null) continue; PackChunk.Members m = new PackChunk.Members(); m.setChunkKey(chunk); m.setChunkData(cell.getValue()); cell = table.get(row, colIndex.name()); if (cell != null) m.setChunkIndex(cell.getValue()); cell = table.get(row, colMeta.name()); if (cell != null) { try { m.setMeta(ChunkMeta.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException err) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidChunkMeta, chunk), err)); return; } } out.add(m); } callback.onSuccess(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 void getMeta(Context options, Set<ChunkKey> keys, AsyncCallback<Map<ChunkKey, ChunkMeta>> callback) { Map<ChunkKey, ChunkMeta> out = new HashMap<ChunkKey, ChunkMeta>(); for (ChunkKey chunk : keys) { byte[] row = chunk.asBytes(); MemTable.Cell cell = table.get(row, colMeta.name()); if (cell != null) { try { out.put(chunk, ChunkMeta.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException err) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidChunkMeta, chunk), err)); return; } } } callback.onSuccess(out); }
/** * Put a value into a cell. * * @param row * @param col * @param val */ public void put(byte[] row, byte[] col, byte[] val) { synchronized (lock) { Key rowKey = new Key(row); Map<Key, Cell> r = map.get(rowKey); if (r == null) { r = new HashMap<Key, Cell>(4); map.put(rowKey, r); } r.put(new Key(col), new Cell(row, col, val)); } }
/** * Put a value into a cell. * * @param row * @param col * @param val */ public void put(byte[] row, byte[] col, byte[] val) { synchronized (lock) { Key rowKey = new Key(row); Map<Key, Cell> r = map.get(rowKey); if (r == null) { r = new HashMap<Key, Cell>(4); map.put(rowKey, r); } r.put(new Key(col), new Cell(row, col, val)); } }
public void getMeta(Context options, Set<ChunkKey> keys, AsyncCallback<Map<ChunkKey, ChunkMeta>> callback) { Map<ChunkKey, ChunkMeta> out = new HashMap<ChunkKey, ChunkMeta>(); for (ChunkKey chunk : keys) { byte[] row = chunk.asBytes(); MemTable.Cell cell = table.get(row, colMeta.name()); if (cell != null) { try { out.put(chunk, ChunkMeta.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException err) { callback.onFailure(new DhtException(MessageFormat.format( DhtText.get().invalidChunkMeta, chunk), err)); 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 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 RepositoryKey get(RepositoryName name) throws DhtException, TimeoutException { Cell cell = table.get(name.asBytes(), colId.name()); if (cell == null) return null; return RepositoryKey.fromBytes(cell.getValue()); }
public RepositoryKey get(RepositoryName name) throws DhtException, TimeoutException { Cell cell = table.get(name.asBytes(), colId.name()); if (cell == null) return null; return RepositoryKey.fromBytes(cell.getValue()); }
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; }