Skip to content

Commit

Permalink
Revert Object->Result replacement.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgarolera committed Oct 29, 2014
1 parent f6f9728 commit 936e299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
10 changes: 3 additions & 7 deletions src/main/java/com/google/cloud/anviltop/hbase/AnvilTopTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ public Boolean[] exists(List<Get> gets) throws IOException {
@Override
public void batch(List<? extends Row> actions, Object[] results)
throws IOException, InterruptedException {
Result[] tempResults = new Result[results.length];
batchExecutor.batch(actions, tempResults);
System.arraycopy(tempResults, 0, results, 0, results.length);
batchExecutor.batch(actions, results);
}

@Override
Expand All @@ -176,9 +174,7 @@ public Object[] batch(List<? extends Row> actions) throws IOException, Interrupt
@Override
public <R> void batchCallback(List<? extends Row> actions, Object[] results,
Batch.Callback<R> callback) throws IOException, InterruptedException {
Result[] tempResults = new Result[results.length];
batchExecutor.batchCallback(actions, tempResults, callback);
System.arraycopy(tempResults, 0, results, 0, results.length);
batchExecutor.batchCallback(actions, results, callback);
}

@Override
Expand Down Expand Up @@ -211,7 +207,7 @@ public Result get(Get get) throws IOException {

@Override
public Result[] get(List<Get> gets) throws IOException {
return batchExecutor.batch(gets);
return (Result[]) batchExecutor.batch(gets);
}

@Override
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/google/cloud/anviltop/hbase/BatchExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ static abstract class RpcResultFutureCallback<R, T extends GeneratedMessage>
private final Row row;
private final Batch.Callback<R> callback;
private final int index;
private final Result[] resultsArray;
private final Object[] resultsArray;
private final SettableFuture<Object> resultFuture;

public RpcResultFutureCallback(
Row row,
Batch.Callback<R> callback,
int index,
Result[] resultsArray,
Object[] resultsArray,
SettableFuture<Object> resultFuture) {
this.row = row;
this.callback = callback;
Expand All @@ -84,7 +84,7 @@ public RpcResultFutureCallback(
/**
* Adapt a proto result into a client result
*/
abstract Result adaptResponse(T response);
abstract Object adaptResponse(T response);

@SuppressWarnings("unchecked")
R unchecked(Object o) {
Expand All @@ -94,7 +94,7 @@ R unchecked(Object o) {
@Override
public void onSuccess(T t) {
try {
Result result = adaptResponse(t);
Object result = adaptResponse(t);
resultsArray[index] = result;
if (callback != null) {
callback.update(NO_REGION, row.getRow(), unchecked(result));
Expand Down Expand Up @@ -321,7 +321,7 @@ ListenableFuture<AnviltopServices.MutateRowResponse> issueRowMutationsRequest(
* @return A ListenableFuture that will have the result when the RPC completes.
*/
<R extends Row,T> ListenableFuture<Object> issueRowRequest(
final Row row, final Batch.Callback<T> callback, final Result[] results, final int index) {
final Row row, final Batch.Callback<T> callback, final Object[] results, final int index) {
final SettableFuture<Object> resultFuture = SettableFuture.create();
results[index] = null;
if (row instanceof Delete) {
Expand All @@ -331,7 +331,7 @@ <R extends Row,T> ListenableFuture<Object> issueRowRequest(
new RpcResultFutureCallback<T, AnviltopServices.MutateRowResponse>(
row, callback, index, results, resultFuture) {
@Override
Result adaptResponse(AnviltopServices.MutateRowResponse response) {
Object adaptResponse(AnviltopServices.MutateRowResponse response) {
return new Result();
}
},
Expand All @@ -343,7 +343,7 @@ Result adaptResponse(AnviltopServices.MutateRowResponse response) {
new RpcResultFutureCallback<T, AnviltopServices.GetRowResponse>(
row, callback, index, results, resultFuture) {
@Override
Result adaptResponse(AnviltopServices.GetRowResponse response) {
Object adaptResponse(AnviltopServices.GetRowResponse response) {
return getRowResponseAdapter.adaptResponse(response);
}
},
Expand All @@ -355,7 +355,7 @@ Result adaptResponse(AnviltopServices.GetRowResponse response) {
new RpcResultFutureCallback<T, AnviltopServices.IncrementRowResponse>(
row, callback, index, results, resultFuture) {
@Override
Result adaptResponse(AnviltopServices.IncrementRowResponse response) {
Object adaptResponse(AnviltopServices.IncrementRowResponse response) {
return incrRespAdapter.adaptResponse(response);
}
},
Expand All @@ -367,7 +367,7 @@ Result adaptResponse(AnviltopServices.IncrementRowResponse response) {
new RpcResultFutureCallback<T, AnviltopServices.MutateRowResponse>(
row, callback, index, results, resultFuture) {
@Override
Result adaptResponse(AnviltopServices.MutateRowResponse response) {
Object adaptResponse(AnviltopServices.MutateRowResponse response) {
return new Result();
}
},
Expand All @@ -379,7 +379,7 @@ Result adaptResponse(AnviltopServices.MutateRowResponse response) {
new RpcResultFutureCallback<T, AnviltopServices.MutateRowResponse>(
row, callback, index, results, resultFuture) {
@Override
Result adaptResponse(AnviltopServices.MutateRowResponse response) {
Object adaptResponse(AnviltopServices.MutateRowResponse response) {
return new Result();
}
},
Expand All @@ -396,10 +396,10 @@ Result adaptResponse(AnviltopServices.MutateRowResponse response) {
/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#batch(List, Object[])}
*/
public void batch(List<? extends Row> actions, @Nullable Result[] results)
public void batch(List<? extends Row> actions, @Nullable Object[] results)
throws IOException, InterruptedException {
if (results == null) {
results = new Result[actions.size()];
results = new Object[actions.size()];
}
Preconditions.checkArgument(results.length == actions.size(),
"Result array must have same dimensions as actions list.");
Expand Down Expand Up @@ -436,7 +436,7 @@ public void batch(List<? extends Row> actions, @Nullable Result[] results)
/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#batch(List)}
*/
public Result[] batch(List<? extends Row> actions) throws IOException {
public Object[] batch(List<? extends Row> actions) throws IOException {
Result[] results = new Result[actions.size()];
try {
batch(actions, results);
Expand Down Expand Up @@ -472,7 +472,7 @@ public <R> Result[] batchCallback(
* {@link org.apache.hadoop.hbase.client.HTable#batchCallback(List, Object[], Batch.Callback)}
*/
public <R> void batchCallback(List<? extends Row> actions,
Result[] results, Batch.Callback<R> callback) throws IOException, InterruptedException {
Object[] results, Batch.Callback<R> callback) throws IOException, InterruptedException {
Preconditions.checkArgument(results.length == actions.size(),
"Result array must be the same length as actions.");
int index = 0;
Expand All @@ -494,7 +494,7 @@ public <R> void batchCallback(List<? extends Row> actions,
*/
public Boolean[] exists(List<Get> gets) throws IOException {
// get(gets) will throw if there are any errors:
Result[] getResults = batch(gets);
Result[] getResults = (Result[]) batch(gets);

Boolean[] exists = new Boolean[getResults.length];
for (int index = 0; index < getResults.length; index++) {
Expand Down

0 comments on commit 936e299

Please sign in to comment.