/** * Creates callbacks to handle a single-put and adds them to the request. * @param edit The edit for which we must handle the response. */ private void addSingleEditCallbacks(final BatchableRpc edit) { // There's no callback to add on a single put request, because // the remote method returns `void', so we only need an errback. final class SingleEditErrback implements Callback<Object, Exception> { public Object call(final Exception e) { if (!(e instanceof RecoverableException)) { return e; // Can't recover from this error, let it propagate. } return retryEdit(edit, (RecoverableException) e); } public String toString() { return "single-edit errback"; } }; edit.getDeferred().addErrback(new SingleEditErrback()); }
/** * Transforms the given single-edit multi-put into a regular single-put. * @param multiput The single-edit multi-put to transform. */ private BatchableRpc multiActionToSingleAction(final MultiAction batch) { final BatchableRpc rpc = batch.batch().get(0); addSingleEditCallbacks(rpc); // Once the single-edit is done, we still need to make sure we're // going to run the callback chain of the MultiAction. final class Multi2SingleCB implements Callback<Object, Object> { public Object call(final Object arg) { // If there was a problem, let the MultiAction know. // Otherwise, give the HBaseRpc in argument to the MultiAction // callback. This is kind of a kludge: the MultiAction callback // will understand that this means that this single-RPC was already // successfully executed on its own. batch.callback(arg instanceof Exception ? arg : rpc); return arg; } } rpc.getDeferred().addBoth(new Multi2SingleCB()); return rpc; }