@GET @Produces(MIMETYPE_BINARY) public Response getBinary(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath() + " as " + MIMETYPE_BINARY); } servlet.getMetrics().incrementRequests(1); try { KeyValue value = generator.next(); if (value == null) { LOG.info("generator exhausted"); return Response.noContent().build(); } ResponseBuilder response = Response.ok(value.getValue()); response.cacheControl(cacheControl); response.header("X-Row", Base64.encodeBytes(value.getRow())); response.header( "X-Column", Base64.encodeBytes(KeyValue.makeColumn(value.getFamily(), value.getQualifier()))); response.header("X-Timestamp", value.getTimestamp()); return response.build(); } catch (IllegalStateException e) { ScannerResource.delete(id); throw new WebApplicationException(Response.Status.GONE); } }
@DELETE public Response delete(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("DELETE " + uriInfo.getAbsolutePath()); } servlet.getMetrics().incrementRequests(1); if (servlet.isReadOnly()) { throw new WebApplicationException(Response.Status.FORBIDDEN); } ScannerResource.delete(id); return Response.ok().build(); }
@GET @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) public Response get( final @Context UriInfo uriInfo, @QueryParam("n") int maxRows, final @QueryParam("c") int maxValues) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); } servlet.getMetrics().incrementRequests(1); CellSetModel model = new CellSetModel(); RowModel rowModel = null; byte[] rowKey = null; int limit = batch; if (maxValues > 0) { limit = maxValues; } int count = limit; do { KeyValue value = null; try { value = generator.next(); } catch (IllegalStateException e) { ScannerResource.delete(id); throw new WebApplicationException(Response.Status.GONE); } if (value == null) { LOG.info("generator exhausted"); // respond with 204 (No Content) if an empty cell set would be // returned if (count == limit) { return Response.noContent().build(); } break; } if (rowKey == null) { rowKey = value.getRow(); rowModel = new RowModel(rowKey); } if (!Bytes.equals(value.getRow(), rowKey)) { // if maxRows was given as a query param, stop if we would exceed the // specified number of rows if (maxRows > 0) { if (--maxRows == 0) { generator.putBack(value); break; } } model.addRow(rowModel); rowKey = value.getRow(); rowModel = new RowModel(rowKey); } rowModel.addCell( new CellModel( value.getFamily(), value.getQualifier(), value.getTimestamp(), value.getValue())); } while (--count > 0); model.addRow(rowModel); ResponseBuilder response = Response.ok(model); response.cacheControl(cacheControl); return response.build(); }