提交 4e1b9021 编写于 作者: M marcelmhs@gmail.com

Changed ServiceProxy to implement invokeOrdered(byte[]) and invokeUnordered(byte[]).

Removed the methodes invoke(byte[], boolean readOnly) from ServiceProxy.
Fixed demo code to work with the new version of ServiceProxy.
上级 61efaab7
......@@ -13,8 +13,6 @@ import navigators.smart.reconfiguration.views.View;
*/
public class ClientViewManager extends ViewManager{
public ClientViewManager(int procId) {
super(procId);
View cv = getViewStore().readView();
......@@ -26,7 +24,6 @@ public class ClientViewManager extends ViewManager{
}
}
public ClientViewManager(int procId, String configHome) {
super(procId, configHome);
View cv = getViewStore().readView();
......
......@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import navigators.smart.communication.client.ReplyListener;
import navigators.smart.communication.client.ReplyReceiver;
import navigators.smart.reconfiguration.ReconfigureReply;
import navigators.smart.reconfiguration.views.View;
import navigators.smart.tom.core.messages.TOMMessage;
......@@ -134,21 +133,18 @@ public class ServiceProxy extends TOMSender {
this.invokeTimeout = invokeTimeout;
}
/**
* This method sends a request to the replicas, and returns the related reply. This method is
* thread-safe.
*
* @param request Request to be sent
* @return The reply from the replicas related to request
*/
public byte[] invoke(byte[] request) {
public byte[] invokeOrdered(byte[] request) {
return invoke(request, TOMMessageType.ORDERED_REQUEST);
}
public byte[] invoke(byte[] request, boolean readOnly) {
TOMMessageType type = (readOnly) ? TOMMessageType.UNORDERED_REQUEST
: TOMMessageType.ORDERED_REQUEST;
return invoke(request, type);
public byte[] invokeUnordered(byte[] request) {
return invoke(request, TOMMessageType.UNORDERED_REQUEST);
}
public void invokeAsynchronous(byte[] request, ReplyListener listener, int[] targets) {
reqId = generateRequestId();
this.replyListener = listener;
sendMessageToTargets(request, reqId, targets);
}
/**
......@@ -207,7 +203,7 @@ public class ServiceProxy extends TOMSender {
if (reqType == TOMMessageType.ORDERED_REQUEST) {
//invoke the operation again, whitout the read-only flag
Logger.println("###################RETRY#######################");
return invoke(request);
return invokeOrdered(request);
} else {
throw new RuntimeException("Received n-f replies without f+1 of them matching.");
}
......@@ -253,11 +249,6 @@ public class ServiceProxy extends TOMSender {
return ret;
}
public void invokeAsynchronous(byte[] request, ReplyListener listener, int[] targets) {
reqId = generateRequestId();
sendMessageToTargets(request, reqId, targets);
}
//******* EDUARDO BEGIN **************//
private void reconfigureTo(View v) {
Logger.println("Installing a most up-to-date view with id=" + v.getId());
......
......@@ -84,7 +84,11 @@ public class CounterClient {
new DataOutputStream(out).writeInt(inc);
System.out.println("Counter sending: " + i);
byte[] reply = counterProxy.invoke(out.toByteArray(), (inc == 0));
byte[] reply;
if(inc == 0)
reply = counterProxy.invokeUnordered(out.toByteArray());
else
reply = counterProxy.invokeOrdered(out.toByteArray());
if(reply != null) {
int newValue = new DataInputStream(new ByteArrayInputStream(reply)).readInt();
System.out.println("Counter value: " + newValue);
......
......@@ -42,7 +42,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
new DataOutputStream(out).writeInt(KVRequestType.GET);
new DataOutputStream(out).writeUTF(tableName);
byte[] rep = KVProxy.invoke(out.toByteArray(), false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream bis = new ByteArrayInputStream(rep) ;
ObjectInputStream in = new ObjectInputStream(bis) ;
Map<String,byte[]> table = (Map<String,byte[]>) in.readObject();
......@@ -64,7 +64,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
new DataOutputStream(out).writeInt(KVRequestType.GET);
new DataOutputStream(out).writeUTF(tableName);
new DataOutputStream(out).writeUTF(key);
byte[] rep = KVProxy.invoke(out.toByteArray(), false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
return rep;
} catch (IOException ex) {
Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex);
......@@ -82,7 +82,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
ObjectOutputStream out1 = new ObjectOutputStream(out) ;
out1.writeObject(value);
out1.close();
byte[] rep = KVProxy.invoke(out.toByteArray(),false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream bis = new ByteArrayInputStream(rep) ;
ObjectInputStream in = new ObjectInputStream(bis) ;
Map<String,byte[]> table = (Map<String,byte[]>) in.readObject();
......@@ -105,7 +105,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
new DataOutputStream(out).writeUTF(tableName);
new DataOutputStream(out).writeUTF(key);
new DataOutputStream(out).writeUTF(new String(value));
byte[] rep = KVProxy.invoke(out.toByteArray(),false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
return rep;
} catch (IOException ex) {
Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex);
......@@ -119,7 +119,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
out = new ByteArrayOutputStream();
new DataOutputStream(out).writeInt(KVRequestType.TAB_REMOVE);
new DataOutputStream(out).writeUTF((String) key);
byte[] rep = KVProxy.invoke(out.toByteArray(),false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream bis = new ByteArrayInputStream(rep) ;
ObjectInputStream in = new ObjectInputStream(bis) ;
......@@ -142,7 +142,7 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
new DataOutputStream(out).writeInt(KVRequestType.REMOVE);
new DataOutputStream(out).writeUTF((String) tableName);
new DataOutputStream(out).writeUTF((String) key);
byte[] rep = KVProxy.invoke(out.toByteArray(), false);
byte[] rep = KVProxy.invokeOrdered(out.toByteArray());
return rep;
} catch (IOException ex) {
Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex);
......@@ -154,7 +154,11 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
try {
out = new ByteArrayOutputStream();
new DataOutputStream(out).writeInt(KVRequestType.SIZE_TABLE);
byte[] rep = KVProxy.invoke(out.toByteArray(), useReadOnly);
byte[] rep;
if(useReadOnly)
rep = KVProxy.invokeUnordered(out.toByteArray());
else
rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream in = new ByteArrayInputStream(rep);
int size = new DataInputStream(in).readInt();
return size;
......@@ -169,7 +173,11 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
out = new ByteArrayOutputStream();
new DataOutputStream(out).writeInt(KVRequestType.SIZE);
new DataOutputStream(out).writeUTF(tableName);
byte[] rep = KVProxy.invoke(out.toByteArray(), useReadOnly);
byte[] rep;
if(useReadOnly)
rep = KVProxy.invokeUnordered(out.toByteArray());
else
rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream in = new ByteArrayInputStream(rep);
int size = new DataInputStream(in).readInt();
return size;
......@@ -186,7 +194,11 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
out = new ByteArrayOutputStream();
new DataOutputStream(out).writeInt(KVRequestType.TAB_CREATE_CHECK);
new DataOutputStream(out).writeUTF((String) key);
byte[] rep = KVProxy.invoke(out.toByteArray(), useReadOnly);
byte[] rep;
if(useReadOnly)
rep = KVProxy.invokeUnordered(out.toByteArray());
else
rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream in = new ByteArrayInputStream(rep);
boolean res = new DataInputStream(in).readBoolean();
return res;
......@@ -206,7 +218,11 @@ public class BFTMap implements Map<String, Map<String,byte[]>> {
new DataOutputStream(out).writeInt(KVRequestType.CHECK);
new DataOutputStream(out).writeUTF((String) tableName);
new DataOutputStream(out).writeUTF((String) key);
byte[] rep = KVProxy.invoke(out.toByteArray(),useReadOnly);
byte[] rep;
if(useReadOnly)
rep = KVProxy.invokeUnordered(out.toByteArray());
else
rep = KVProxy.invokeOrdered(out.toByteArray());
ByteArrayInputStream in = new ByteArrayInputStream(rep);
boolean res = new DataInputStream(in).readBoolean();
return res;
......
......@@ -8,8 +8,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
......
......@@ -50,7 +50,10 @@ public class LatencyClient {
System.out.println("Warm up...");
for (int i = 0; i < numberOfOps/2; i++) {
reply = counterProxy.invoke(request, readOnly);
if(readOnly)
reply = counterProxy.invokeUnordered(request);
else
reply = counterProxy.invokeOrdered(request);
}
Storage st = new Storage(numberOfOps/2);
......@@ -59,7 +62,10 @@ public class LatencyClient {
for (int i = 0; i < numberOfOps/2; i++) {
long last_send_instant = System.nanoTime();
reply = counterProxy.invoke(request, readOnly);
if(readOnly)
reply = counterProxy.invokeUnordered(request);
else
reply = counterProxy.invokeOrdered(request);
st.store(System.nanoTime() - last_send_instant);
if (interval > 0) {
......
......@@ -128,7 +128,11 @@ public class ThroughputLatencyClient {
reqId = proxy.generateRequestId();
proxy.TOMulticast(request, reqId, (readOnly) ? TOMMessageType.UNORDERED_REQUEST : TOMMessageType.ORDERED_REQUEST);
}
else reply = proxy.invoke(request, readOnly);
else
if(readOnly)
reply = proxy.invokeUnordered(request);
else
reply = proxy.invokeOrdered(request);
if (verbose) System.out.println(" sent!");
if (verbose && (req % 1000 == 0)) System.out.println(this.id + " // " + req + " operations sent!");
......@@ -147,7 +151,11 @@ public class ThroughputLatencyClient {
proxy.TOMulticast(request, reqId, (readOnly) ? TOMMessageType.UNORDERED_REQUEST : TOMMessageType.ORDERED_REQUEST);
}
else reply = proxy.invoke(request, readOnly);
else
if(readOnly)
reply = proxy.invokeUnordered(request);
else
reply = proxy.invokeOrdered(request);
if (verbose) System.out.println(this.id + " // sent!");
st.store(System.nanoTime() - last_send_instant);
......
......@@ -58,7 +58,7 @@ public class RandomClient {
new DataOutputStream(out).writeInt(argument);
new DataOutputStream(out).writeInt(operator);
byte[] reply = randomProxy.invoke(out.toByteArray(),false);
byte[] reply = randomProxy.invokeOrdered(out.toByteArray());
int newValue = new DataInputStream(new ByteArrayInputStream(reply)).readInt();
System.out.println("(" + id + ") Current value: "+newValue);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册