First working version of Threaded Bulletin Board Client.
Tests do not report well.Bulletin-Board-Client-phase_1
parent
13733e6610
commit
4f2d0e7738
|
@ -37,6 +37,10 @@ public class BulletinClientJob {
|
||||||
this.maxRetry = maxRetry;
|
this.maxRetry = maxRetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateServerAddresses(List<String> newServerAdresses) {
|
||||||
|
this.serverAddresses = newServerAdresses;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getServerAddresses() {
|
public List<String> getServerAddresses() {
|
||||||
return serverAddresses;
|
return serverAddresses;
|
||||||
}
|
}
|
||||||
|
@ -57,10 +61,6 @@ public class BulletinClientJob {
|
||||||
return maxRetry;
|
return maxRetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<String> getAddressIterator() {
|
|
||||||
return serverAddresses.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shuffleAddresses() {
|
public void shuffleAddresses() {
|
||||||
Collections.shuffle(serverAddresses);
|
Collections.shuffle(serverAddresses);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import javax.ws.rs.client.Entity;
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,6 +82,8 @@ public class BulletinClientWorker implements Callable<BulletinClientJobResult> {
|
||||||
String requestPath;
|
String requestPath;
|
||||||
Message msg;
|
Message msg;
|
||||||
|
|
||||||
|
List<String> serverAddresses = new LinkedList<String>(job.getServerAddresses());
|
||||||
|
|
||||||
Message payload = job.getPayload();
|
Message payload = job.getPayload();
|
||||||
|
|
||||||
BulletinBoardMessageList msgList;
|
BulletinBoardMessageList msgList;
|
||||||
|
@ -114,7 +118,7 @@ public class BulletinClientWorker implements Callable<BulletinClientJobResult> {
|
||||||
case GET_REDUNDANCY:
|
case GET_REDUNDANCY:
|
||||||
// Make sure the payload is a MessageId
|
// Make sure the payload is a MessageId
|
||||||
if (!(payload instanceof MessageID)) {
|
if (!(payload instanceof MessageID)) {
|
||||||
throw new IllegalArgumentException("Cannot search for an object that is not an instance of BulletinBoardMessage");
|
throw new IllegalArgumentException("Cannot search for an object that is not an instance of MessageID");
|
||||||
}
|
}
|
||||||
|
|
||||||
requestPath = Constants.READ_MESSAGES_PATH;
|
requestPath = Constants.READ_MESSAGES_PATH;
|
||||||
|
@ -135,7 +139,7 @@ public class BulletinClientWorker implements Callable<BulletinClientJobResult> {
|
||||||
|
|
||||||
// Iterate through servers
|
// Iterate through servers
|
||||||
|
|
||||||
Iterator<String> addressIterator = job.getAddressIterator();
|
Iterator<String> addressIterator = serverAddresses.iterator();
|
||||||
|
|
||||||
while (addressIterator.hasNext()) {
|
while (addressIterator.hasNext()) {
|
||||||
|
|
||||||
|
@ -192,7 +196,8 @@ public class BulletinClientWorker implements Callable<BulletinClientJobResult> {
|
||||||
|
|
||||||
case POST_MESSAGE:
|
case POST_MESSAGE:
|
||||||
// The job now contains the information required to ascertain whether enough server posts have succeeded
|
// The job now contains the information required to ascertain whether enough server posts have succeeded
|
||||||
// It also contains the list of servers in which the post was not successful
|
// It will also contain the list of servers in which the post was not successful
|
||||||
|
job.updateServerAddresses(serverAddresses);
|
||||||
return new BulletinClientJobResult(job, null);
|
return new BulletinClientJobResult(job, null);
|
||||||
|
|
||||||
case GET_REDUNDANCY:
|
case GET_REDUNDANCY:
|
||||||
|
|
|
@ -13,6 +13,7 @@ import meerkat.protobuf.Voting;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Arbel Deutsch Peled on 05-Dec-15.
|
* Created by Arbel Deutsch Peled on 05-Dec-15.
|
||||||
|
@ -107,7 +108,7 @@ public class ThreadedBulletinBoardClient implements BulletinBoardClient {
|
||||||
public void readMessages(MessageFilterList filterList, ClientCallback<List<BulletinBoardMessage>> callback) {
|
public void readMessages(MessageFilterList filterList, ClientCallback<List<BulletinBoardMessage>> callback) {
|
||||||
|
|
||||||
// Create job
|
// Create job
|
||||||
BulletinClientJob job = new BulletinClientJob(meerkatDBs, minAbsoluteRedundancy, BulletinClientJob.JobType.GET_REDUNDANCY,
|
BulletinClientJob job = new BulletinClientJob(meerkatDBs, minAbsoluteRedundancy, BulletinClientJob.JobType.READ_MESSAGES,
|
||||||
filterList, READ_MESSAGES_RETRY_NUM);
|
filterList, READ_MESSAGES_RETRY_NUM);
|
||||||
|
|
||||||
// Submit job and create callback
|
// Submit job and create callback
|
||||||
|
@ -115,4 +116,16 @@ public class ThreadedBulletinBoardClient implements BulletinBoardClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
try {
|
||||||
|
listeningExecutor.shutdown();
|
||||||
|
while (! listeningExecutor.isShutdown()) {
|
||||||
|
listeningExecutor.awaitTermination(10, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.err.println(e.getCause() + " " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,9 @@ public class BulletinBoardClientIntegrationTest {
|
||||||
private class PostCallback implements ClientCallback<Object>{
|
private class PostCallback implements ClientCallback<Object>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCallback(Object msg) {}
|
public void handleCallback(Object msg) {
|
||||||
|
System.err.println("Post operation completed");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleFailure(Throwable t) {
|
public void handleFailure(Throwable t) {
|
||||||
|
@ -184,6 +186,8 @@ public class BulletinBoardClientIntegrationTest {
|
||||||
|
|
||||||
bulletinBoardClient.readMessages(filterList, readCallback);
|
bulletinBoardClient.readMessages(filterList, readCallback);
|
||||||
|
|
||||||
|
bulletinBoardClient.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,10 @@ public interface BulletinBoardClient {
|
||||||
*/
|
*/
|
||||||
void readMessages(MessageFilterList filterList, ClientCallback<List<BulletinBoardMessage>> callback);
|
void readMessages(MessageFilterList filterList, ClientCallback<List<BulletinBoardMessage>> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes all connections, if any.
|
||||||
|
* This is done in a synchronous (blocking) way.
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue