Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Refactor bopBulkGet API logic. #675

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -3653,9 +3652,10 @@ private <T> CollectionGetBulkFuture<Map<String, BTreeGetResult<Long, T>>> btreeG
final boolean reverse, final Transcoder<T> tc) {

final CountDownLatch latch = new CountDownLatch(getBulkList.size());
final ConcurrentLinkedQueue<Operation> ops = new ConcurrentLinkedQueue<Operation>();
final Map<String, BTreeGetResult<Long, T>> result =
new ConcurrentHashMap<String, BTreeGetResult<Long, T>>();
new HashMap<String, BTreeGetResult<Long, T>>();
final CollectionGetBulkFuture<Map<String, BTreeGetResult<Long, T>>> rv
= new CollectionGetBulkFuture<Map<String, BTreeGetResult<Long, T>>>(latch, result, operationTimeout);

for (BTreeGetBulk<T> getBulk : getBulkList) {
Operation op = opFact.bopGetBulk(getBulk, new BTreeGetBulkOperation.Callback() {
Expand Down Expand Up @@ -3703,12 +3703,10 @@ public void addResult() {
}
}
});
ops.add(op);
rv.addOperation(op);
addOp(getBulk.getMemcachedNode(), op);
}

return new CollectionGetBulkFuture<Map<String, BTreeGetResult<Long, T>>>(
latch, ops, result, operationTimeout);
return rv;
}

/**
Expand All @@ -3726,9 +3724,10 @@ public void addResult() {
final boolean reverse, final Transcoder<T> tc) {

final CountDownLatch latch = new CountDownLatch(getBulkList.size());
final ConcurrentLinkedQueue<Operation> ops = new ConcurrentLinkedQueue<Operation>();
final Map<String, BTreeGetResult<ByteArrayBKey, T>> result =
new ConcurrentHashMap<String, BTreeGetResult<ByteArrayBKey, T>>();
new HashMap<String, BTreeGetResult<ByteArrayBKey, T>>();
final CollectionGetBulkFuture<Map<String, BTreeGetResult<ByteArrayBKey, T>>> rv =
new CollectionGetBulkFuture<Map<String, BTreeGetResult<ByteArrayBKey, T>>>(latch, result, operationTimeout);

for (BTreeGetBulk<T> getBulk : getBulkList) {
Operation op = opFact.bopGetBulk(getBulk, new BTreeGetBulkOperation.Callback() {
Expand Down Expand Up @@ -3777,12 +3776,10 @@ public void addResult() {
}
}
});
ops.add(op);
rv.addOperation(op);
addOp(getBulk.getMemcachedNode(), op);
}

return new CollectionGetBulkFuture<Map<String, BTreeGetResult<ByteArrayBKey, T>>>(
latch, ops, result, operationTimeout);
return rv;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package net.spy.memcached.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.concurrent.CountDownLatch;
Expand All @@ -39,10 +40,9 @@ public class CollectionGetBulkFuture<T> implements Future<T> {
private final CountDownLatch latch;
private final T result;

public CollectionGetBulkFuture(CountDownLatch latch, Collection<Operation> ops, T result,
long timeout) {
public CollectionGetBulkFuture(CountDownLatch latch, T result, long timeout) {
this.ops = new ArrayList<Operation>((int) latch.getCount());
this.latch = latch;
this.ops = ops;
this.result = result;
this.timeout = timeout;
}
Expand Down Expand Up @@ -129,4 +129,8 @@ public CollectionOperationStatus getOperationStatus() {

return new CollectionOperationStatus(new OperationStatus(true, "END"));
}

public void addOperation(Operation operation) {
ops.add(operation);
}
}
Loading