Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhanhui committed Jan 4, 2017
1 parent 9cb0a0c commit b421d48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.rocketmq.client.QueryResult;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
Expand Down Expand Up @@ -285,6 +288,7 @@ protected QueryResult queryMessage(String topic, String key, int maxNum, long be
if (!brokerAddrs.isEmpty()) {
final CountDownLatch countDownLatch = new CountDownLatch(brokerAddrs.size());
final List<QueryResult> queryResultList = new LinkedList<QueryResult>();
final ReadWriteLock lock = new ReentrantReadWriteLock(false);

for (String addr : brokerAddrs) {
try {
Expand Down Expand Up @@ -318,7 +322,12 @@ public void operationComplete(ResponseFuture responseFuture) {
MessageDecoder.decodes(ByteBuffer.wrap(response.getBody()), true);

QueryResult qr = new QueryResult(responseHeader.getIndexLastUpdateTimestamp(), wrappers);
queryResultList.add(qr);
try {
lock.writeLock().lock();
queryResultList.add(qr);
} finally {
lock.writeLock().unlock();
}
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
}
}

void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key)
private void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key)
throws MQClientException, InterruptedException {
admin.start();

Expand Down

0 comments on commit b421d48

Please sign in to comment.