private void writeToStream(CellSetModel model, String contentType, OutputStream outStream) throws IOException { byte[] objectBytes = model.createProtobufOutput(); outStream.write(Bytes.toBytes((short)objectBytes.length)); outStream.write(objectBytes); outStream.flush(); if (LOG.isTraceEnabled()) { LOG.trace("Wrote " + model.getRows().size() + " rows to stream successfully."); } }
@Override public void put(Put put) throws IOException { CellSetModel model = buildModelFromPut(put); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(Bytes.toString(name)); sb.append('/'); sb.append(toURLEncodedBytes(put.getRow())); for (int i = 0; i < maxRetries; i++) { Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) { case 200: return; case 509: try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } break; default: throw new IOException("put request failed with " + code); } } throw new IOException("put request timed out"); }
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) {
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) {
for (int i = 0; i < maxRetries; i++) { Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) {
static Response putValuePB(String url, String table, String row, String column, String value) throws IOException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
protected static Response checkAndDeleteValuePB(String url, String table, String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete) throws IOException { RowModel rowModel = new RowModel(row); if(cellsToDelete != null) { for (Map.Entry<String,String> entry :cellsToDelete.entrySet()) { rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); } } // Add this at the end rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes .toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
protected static Response checkAndPutValuePB(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells) throws IOException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut))); if(otherCells != null) { for (Map.Entry<String,String> entry :otherCells.entrySet()) { rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); } } // This Cell need to be added as last cell. rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
cellSetModel.addRow(rowModel); Response response = client.put(path, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield();
private void writeToStream(CellSetModel model, String contentType, OutputStream outStream) throws IOException { byte[] objectBytes = model.createProtobufOutput(); outStream.write(Bytes.toBytes((short)objectBytes.length)); outStream.write(objectBytes); outStream.flush(); if (LOG.isTraceEnabled()) { LOG.trace("Wrote " + model.getRows().size() + " rows to stream successfully."); } }
private void writeToStream(CellSetModel model, String contentType, OutputStream outStream) throws IOException { byte[] objectBytes = model.createProtobufOutput(); outStream.write(Bytes.toBytes((short)objectBytes.length)); outStream.write(objectBytes); outStream.flush(); if (LOG.isTraceEnabled()) { LOG.trace("Wrote " + model.getRows().size() + " rows to stream successfully."); } }
@Override public Buffer serialise(String tableName, String recordId, JsonObject result) { final CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(buildRow(result, recordId)); LOGGER.info("Returning single row with ID: {} for table: {}", recordId, tableName); final byte[] protobufOutput = cellSetModel.createProtobufOutput(); return Buffer.buffer(protobufOutput); }
@Override public void put(Put put) throws IOException { CellSetModel model = buildModelFromPut(put); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(Bytes.toString(name)); sb.append('/'); sb.append(toURLEncodedBytes(put.getRow())); for (int i = 0; i < maxRetries; i++) { Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) { case 200: return; case 509: try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } break; default: throw new IOException("put request failed with " + code); } } throw new IOException("put request timed out"); }
@Override public void put(Put put) throws IOException { CellSetModel model = buildModelFromPut(put); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(Bytes.toString(name)); sb.append('/'); sb.append(toURLEncodedBytes(put.getRow())); for (int i = 0; i < maxRetries; i++) { Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) { case 200: return; case 509: try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } break; default: throw new IOException("put request failed with " + code); } } throw new IOException("put request timed out"); }
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) {
public void put(Put put) throws IOException { CellSetModel model = buildModelFromPut(put); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(Bytes.toStringBinary(name)); sb.append('/'); sb.append(Bytes.toStringBinary(put.getRow())); for (int i = 0; i < maxRetries; i++) { Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) { case 200: return; case 509: try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } break; default: throw new IOException("put request failed with " + code); } } throw new IOException("put request timed out"); }
@Override public Buffer serialise(String tableName, String scannerId, JsonArray results, InMemoryScanner scanner, int rows) { final CellSetModel cellSetModel = new CellSetModel(); // start the row counter from the last position in the scanner final int lastPosition = scanner.getRowCounter().get(); for (int i = lastPosition; i < (lastPosition + rows) && i < results.size(); i++) { final JsonObject result = results.getJsonObject(i); cellSetModel.addRow(buildRow(result, buildRowKey(scanner))); } // scanner exhausted? checkExhausted(tableName, scannerId, results, scanner); LOGGER.info("Returning {} rows from scanner {} for table: {}", cellSetModel.getRows().size(), scannerId, tableName); final byte[] protobufOutput = cellSetModel.createProtobufOutput(); return Buffer.buffer(protobufOutput); }
static Response putValuePB(String url, String table, String row, String column, String value) throws IOException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
protected static Response checkAndDeleteValuePB(String url, String table, String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete) throws IOException { RowModel rowModel = new RowModel(row); if(cellsToDelete != null) { for (Map.Entry<String,String> entry :cellsToDelete.entrySet()) { rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); } } // Add this at the end rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes .toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
protected static Response checkAndPutValuePB(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells) throws IOException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut))); if(otherCells != null) { for (Map.Entry<String,String> entry :otherCells.entrySet()) { rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); } } // This Cell need to be added as last cell. rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }