Fixed some subscription functionality of the CachedClient
parent
fe209f6b5a
commit
229cbfd48f
|
@ -5,6 +5,7 @@ import com.google.protobuf.ByteString;
|
||||||
import meerkat.comm.CommunicationException;
|
import meerkat.comm.CommunicationException;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.*;
|
import meerkat.protobuf.BulletinBoardAPI.*;
|
||||||
import meerkat.protobuf.Voting.*;
|
import meerkat.protobuf.Voting.*;
|
||||||
|
import meerkat.util.BulletinBoardUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -30,13 +31,13 @@ public class CachedBulletinBoardClient implements SubscriptionBulletinBoardClien
|
||||||
|
|
||||||
private class SubscriptionStoreCallback implements FutureCallback<List<BulletinBoardMessage>> {
|
private class SubscriptionStoreCallback implements FutureCallback<List<BulletinBoardMessage>> {
|
||||||
|
|
||||||
private final FutureCallback<?> callback;
|
private final FutureCallback<List<BulletinBoardMessage>> callback;
|
||||||
|
|
||||||
public SubscriptionStoreCallback(){
|
public SubscriptionStoreCallback(){
|
||||||
callback = null;
|
callback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionStoreCallback(FutureCallback<?> callback){
|
public SubscriptionStoreCallback(FutureCallback<List<BulletinBoardMessage>> callback){
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +45,30 @@ public class CachedBulletinBoardClient implements SubscriptionBulletinBoardClien
|
||||||
public void onSuccess(List<BulletinBoardMessage> result) {
|
public void onSuccess(List<BulletinBoardMessage> result) {
|
||||||
for (BulletinBoardMessage msg : result) {
|
for (BulletinBoardMessage msg : result) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (msg.getMsg().getTagList().contains(BulletinBoardConstants.BATCH_TAG)) {
|
||||||
|
|
||||||
|
// This is a batch message: need to upload batch data as well as the message itself
|
||||||
|
ByteString signerID = msg.getSig(0).getSignerId();
|
||||||
|
int batchID = Integer.parseInt(BulletinBoardUtils.findTagWithPrefix(msg, BulletinBoardConstants.BATCH_ID_TAG_PREFIX));
|
||||||
|
|
||||||
|
BatchSpecificationMessage batchSpecificationMessage = BatchSpecificationMessage.newBuilder()
|
||||||
|
.setSignerId(signerID)
|
||||||
|
.setBatchId(batchID)
|
||||||
|
.setStartPosition(0)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CompleteBatch completeBatch = localClient.readBatch(batchSpecificationMessage);
|
||||||
|
|
||||||
|
localClient.postBatch(completeBatch);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// This is a regular message: post it
|
||||||
localClient.postMessage(msg);
|
localClient.postMessage(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} catch (CommunicationException ignored) {
|
} catch (CommunicationException ignored) {
|
||||||
// TODO: log
|
// TODO: log
|
||||||
}
|
}
|
||||||
|
@ -346,16 +370,21 @@ public class CachedBulletinBoardClient implements SubscriptionBulletinBoardClien
|
||||||
localClient.close();
|
localClient.close();
|
||||||
remoteClient.close();
|
remoteClient.close();
|
||||||
synchronizer.stop();
|
synchronizer.stop();
|
||||||
|
try {
|
||||||
|
syncThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
//TODO: log interruption
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void subscribe(MessageFilterList filterList, FutureCallback<List<BulletinBoardMessage>> callback) {
|
public void subscribe(MessageFilterList filterList, FutureCallback<List<BulletinBoardMessage>> callback) {
|
||||||
subscriber.subscribe(filterList, callback);
|
subscriber.subscribe(filterList, new SubscriptionStoreCallback(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void subscribe(MessageFilterList filterList, long startEntry, FutureCallback<List<BulletinBoardMessage>> callback) {
|
public void subscribe(MessageFilterList filterList, long startEntry, FutureCallback<List<BulletinBoardMessage>> callback) {
|
||||||
subscriber.subscribe(filterList, startEntry, callback);
|
subscriber.subscribe(filterList, startEntry, new SubscriptionStoreCallback(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue