From 31ceb8fe6a5e571352a7609b477c17cbef26f31c Mon Sep 17 00:00:00 2001 From: "bessani@gmail.com" Date: Mon, 16 May 2011 18:22:26 +0000 Subject: [PATCH] --- src/navigators/smart/tom/demo/BFTMAPUtil.java | 102 ------- src/navigators/smart/tom/demo/BFTMap.java | 266 ------------------ src/navigators/smart/tom/demo/BFTMapImpl.java | 212 -------------- .../smart/tom/demo/CounterServer.java | 4 +- src/navigators/smart/tom/demo/KVClient.java | 200 ------------- src/navigators/smart/tom/demo/KVServer.java | 24 -- .../smart/tom/demo/RWCounterClient.java | 108 +++++++ .../smart/tom/demo/RandomServer.java | 2 +- 8 files changed, 111 insertions(+), 807 deletions(-) delete mode 100644 src/navigators/smart/tom/demo/BFTMAPUtil.java delete mode 100644 src/navigators/smart/tom/demo/BFTMap.java delete mode 100644 src/navigators/smart/tom/demo/BFTMapImpl.java delete mode 100644 src/navigators/smart/tom/demo/KVClient.java delete mode 100644 src/navigators/smart/tom/demo/KVServer.java create mode 100644 src/navigators/smart/tom/demo/RWCounterClient.java diff --git a/src/navigators/smart/tom/demo/BFTMAPUtil.java b/src/navigators/smart/tom/demo/BFTMAPUtil.java deleted file mode 100644 index 5fec258d..00000000 --- a/src/navigators/smart/tom/demo/BFTMAPUtil.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package navigators.smart.tom.demo; -import java.util.HashMap; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Scanner; - -import java.util.logging.Level; -import java.util.logging.Logger; -import navigators.smart.tom.ServiceProxy; -import java.io.Console; -import java.io.Serializable; - -/** - * - * @author sweta - */ -public class BFTMAPUtil implements Serializable { - - static final int TAB_CREATE = 1; - static final int TAB_REMOVE = 2; - static final int SIZE_TABLE=3; - static final int TAB_CREATE_CHECK = 10; - static final int PUT = 4; - static final int GET = 5; - static final int SIZE = 6; - static final int REMOVE = 7; - static final int CHECK = 8; - static final int GET_TABLE = 9; - - //private HashMap info = null; - private HashMap> info1 = null; - //private HashMap info = null; - - public BFTMAPUtil() { - - info1=new HashMap>(); - - } - - public HashMap addTable(String key,HashMap data) { - return info1.put(key, data); - } - - public byte[] addData(String tableName,String key,byte[] value) { - System.out.println("Table name"+tableName); - System.out.println("Table id"+key); - System.out.println("Value"+ new String(value)); - HashMap info= info1.get(tableName); - if (info == null) System.out.println("This is null"); - System.out.println("Table"+info); - byte[] ret = info.put(key,value); - // byte[] ret = info.get(key); - // System.out.println("Value"+ new String(ret)); - return ret; - } - - public HashMap getName(String id) { - - return info1.get(id); - } - - public byte[] getEntry(String tableName, String id) { - System.out.println("Table name"+tableName); - System.out.println("Table id"+id); - HashMap info= info1.get(tableName); - System.out.println("Table"+info); - return info.get(id); - } - - public int getSizeofTable() { - - return info1.size(); - - } - - public int getSize(String tableName) { - - HashMap info= info1.get(tableName); - return info.size(); - - } - - public HashMap removeTable(String tableName) { - - return info1.remove(tableName); - - } - - public byte[] removeEntry(String tableName,String key) { - HashMap info= info1.get(tableName); - return info.remove(key); - - } -} diff --git a/src/navigators/smart/tom/demo/BFTMap.java b/src/navigators/smart/tom/demo/BFTMap.java deleted file mode 100644 index f5f633f6..00000000 --- a/src/navigators/smart/tom/demo/BFTMap.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package navigators.smart.tom.demo; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Scanner; -import java.util.Set; - -import java.util.logging.Level; -import java.util.logging.Logger; -import navigators.smart.tom.ServiceProxy; -import java.io.Console; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author sweta - */ -public class BFTMap implements Map> { - - BFTMAPUtil bft = null; - ServiceProxy KVProxy = null; - BFTMap(int id) { - - bft = new BFTMAPUtil(); - KVProxy = new ServiceProxy(id); - } - ByteArrayOutputStream out = null; - - public HashMap get(String tableName) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.GET); - new DataOutputStream(out).writeUTF(tableName); - - byte[] rep = KVProxy.invoke(out.toByteArray(),true); - ByteArrayInputStream bis = new ByteArrayInputStream(rep) ; - ObjectInputStream in = new ObjectInputStream(bis) ; - HashMap table = (HashMap) in.readObject(); - in.close(); - return table; - } catch (ClassNotFoundException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - - } - - public byte[] getEntry(String tableName,String key) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.GET); - new DataOutputStream(out).writeUTF(tableName); - new DataOutputStream(out).writeUTF(key); - byte[] rep = KVProxy.invoke(out.toByteArray(), true); - return rep; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - } - - - public HashMap put(String key, HashMap value) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.TAB_CREATE); - new DataOutputStream(out).writeUTF(key); - //ByteArrayOutputStream bos = new ByteArrayOutputStream() ; - ObjectOutputStream out1 = new ObjectOutputStream(out) ; - out1.writeObject(value); - out1.close(); - byte[] rep = KVProxy.invoke(out.toByteArray(),true); - ByteArrayInputStream bis = new ByteArrayInputStream(rep) ; - ObjectInputStream in = new ObjectInputStream(bis) ; - HashMap table = (HashMap) in.readObject(); - in.close(); - return table; - - } catch (ClassNotFoundException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - } - - public byte[] put1(String tableName, String key, byte[] value) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.PUT); - new DataOutputStream(out).writeUTF(tableName); - new DataOutputStream(out).writeUTF(key); - new DataOutputStream(out).writeUTF(new String(value)); - byte[] rep = KVProxy.invoke(out.toByteArray(),true); - return rep; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - - } - - public HashMap remove(Object key) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.TAB_REMOVE); - new DataOutputStream(out).writeUTF((String) key); - byte[] rep = KVProxy.invoke(out.toByteArray(),false); - - ByteArrayInputStream bis = new ByteArrayInputStream(rep) ; - ObjectInputStream in = new ObjectInputStream(bis) ; - HashMap table = (HashMap) in.readObject(); - in.close(); - return table; - } catch (ClassNotFoundException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - - } - - public byte[] removeEntry(String tableName,String key) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.REMOVE); - new DataOutputStream(out).writeUTF((String) tableName); - new DataOutputStream(out).writeUTF((String) key); - byte[] rep = KVProxy.invoke(out.toByteArray(), false); - return rep; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - - } - public int size() { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.SIZE_TABLE); - byte[] rep = KVProxy.invoke(out.toByteArray(),false); - ByteArrayInputStream in = new ByteArrayInputStream(rep); - int size = new DataInputStream(in).readInt(); - return size; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return -1; - } - } - - public int size1(String tableName) { - try { - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.SIZE); - new DataOutputStream(out).writeUTF(tableName); - byte[] rep = KVProxy.invoke(out.toByteArray(), false); - ByteArrayInputStream in = new ByteArrayInputStream(rep); - int size = new DataInputStream(in).readInt(); - return size; - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return 0; - } - } - - public boolean containsKey(String key) { - - try { - - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.TAB_CREATE_CHECK); - new DataOutputStream(out).writeUTF((String) key); - byte[] rep = KVProxy.invoke(out.toByteArray(),true); - ByteArrayInputStream in = new ByteArrayInputStream(rep); - boolean res = new DataInputStream(in).readBoolean(); - return res; - - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return false; - } - - } - - public boolean containsKey1(String tableName, String key) { - - try { - - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(BFTMAPUtil.CHECK); - new DataOutputStream(out).writeUTF((String) tableName); - new DataOutputStream(out).writeUTF((String) key); - byte[] rep = KVProxy.invoke(out.toByteArray(),true); - ByteArrayInputStream in = new ByteArrayInputStream(rep); - boolean res = new DataInputStream(in).readBoolean(); - return res; - - } catch (IOException ex) { - Logger.getLogger(BFTMap.class.getName()).log(Level.SEVERE, null, ex); - return false; - } - - } - - - - - public boolean isEmpty() { - throw new UnsupportedOperationException("Not supported yet."); - } - - - - public boolean containsValue(Object value) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void putAll(Map m) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void clear() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Set keySet() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Collection values() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Set entrySet() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public boolean containsKey(Object key) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public HashMap get(Object key) { - throw new UnsupportedOperationException("Not supported yet."); - } - - - } - - diff --git a/src/navigators/smart/tom/demo/BFTMapImpl.java b/src/navigators/smart/tom/demo/BFTMapImpl.java deleted file mode 100644 index d1bee3be..00000000 --- a/src/navigators/smart/tom/demo/BFTMapImpl.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package navigators.smart.tom.demo; -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; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; -import java.lang.String; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import navigators.smart.tom.ServiceReplica; -import navigators.smart.tom.util.DebugInfo; - - -/** - * - * @author sweta - */ - -//This class extends ServiceReplica and overrides its functions serializeState(), deserializeState() and executeCommand(). -public class BFTMapImpl extends ServiceReplica { - - //The constructor passes the id of the server to the super class - public BFTMapImpl(int id) { - super(id); - } - HashMap info2 = new HashMap(); - BFTMAPUtil bftReplica = new BFTMAPUtil(); - @Override - protected byte[] serializeState() { - try { - - //save to file (not needed for now) - ObjectOutput out = new ObjectOutputStream(new FileOutputStream("MyObject.ser")); - out.writeObject(bftReplica); - out.close(); - - // serialize to byte array and return - ByteArrayOutputStream bos = new ByteArrayOutputStream() ; - out = new ObjectOutputStream(bos) ; - out.writeObject(bftReplica); - out.close(); - return bos.toByteArray(); - } catch (IOException ex) { - Logger.getLogger(BFTMapImpl.class.getName()).log(Level.SEVERE, null, ex); - return new byte[0]; - } - } - - @Override - protected void deserializeState(byte[] state) { - try { - //save to file (not needed for now) - ObjectInput in = new ObjectInputStream(new FileInputStream("MyObject.ser")); - bftReplica = (BFTMAPUtil) in.readObject(); - in.close(); - - // serialize to byte array and return - ByteArrayInputStream bis = new ByteArrayInputStream(state) ; - in = new ObjectInputStream(bis) ; - bftReplica = (BFTMAPUtil) in.readObject(); - in.close(); - - } catch (ClassNotFoundException ex) { - Logger.getLogger(BFTMapImpl.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(BFTMapImpl.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @Override - @SuppressWarnings("static-access") - public byte[] executeCommand(int clientId, long timestamp, byte[] nonces, byte[] command, DebugInfo info) { - try { - ByteArrayInputStream in = new ByteArrayInputStream(command); - ByteArrayOutputStream out = null; - byte[] reply = null; - int cmd = new DataInputStream(in).readInt(); - switch (cmd) { - //operations on the hashmap - case BFTMAPUtil.PUT: - String tableName = new DataInputStream(in).readUTF(); - String key = new DataInputStream(in).readUTF(); - String value = new DataInputStream(in).readUTF(); - byte[] b = value.getBytes(); - System.out.println("Key received" + key); - byte[] ret = bftReplica.addData(tableName, key, b); - - if (ret == null) { - System.out.println("inside if"); - ret = new byte[0]; - } - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeBytes(new String(ret)); - reply = out.toByteArray(); - break; - case BFTMAPUtil.GET: - String tableName1 = new DataInputStream(in).readUTF(); - System.out.println("tablename"+tableName1); - String id1 = new DataInputStream(in).readUTF(); - System.out.println("ID received" + id1); - byte[] b1 = bftReplica.getEntry(tableName1, id1); - String value1 = new String(b1); - System.out.println("The value to be get is"+value1); - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeBytes(value1); - reply = out.toByteArray(); - break; - case BFTMAPUtil.SIZE: - String tableName2 = new DataInputStream(in).readUTF(); - int size = bftReplica.getSize(tableName2); - System.out.println("Size " + size); - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(size); - reply = out.toByteArray(); - break; - case BFTMAPUtil.SIZE_TABLE: - int size1 = bftReplica.getSizeofTable(); - System.out.println("Size " + size1); - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeInt(size1); - reply = out.toByteArray(); - break; - case BFTMAPUtil.REMOVE: - String tableName4 = new DataInputStream(in).readUTF(); - String id2 = new DataInputStream(in).readUTF(); - System.out.println("ID received" + id2); - byte[] b2 = bftReplica.removeEntry(tableName4, id2); - String value2 = new String(b2); - System.out.println("Value removed is : " + value2); - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeBytes(value2); - reply = out.toByteArray(); - break; - case BFTMAPUtil.TAB_CREATE_CHECK: - String id3 = new DataInputStream(in).readUTF(); - System.out.println("Table of Table Key received" + id3); - HashMap b3 = bftReplica.getName(id3); - boolean tableExists = b3 != null; - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeBoolean(tableExists); - reply = out.toByteArray(); - break; - case BFTMAPUtil.CHECK: - - String tableName7 = new DataInputStream(in).readUTF(); - String id4 = new DataInputStream(in).readUTF(); - System.out.println("Table Key received" + id4); - byte[] b5 = bftReplica.getEntry(tableName7,id4); - boolean tableExists1 = b5 != null; - out = new ByteArrayOutputStream(); - new DataOutputStream(out).writeBoolean(tableExists1); - reply = out.toByteArray(); - break; - case BFTMAPUtil.TAB_CREATE: - String table4= new DataInputStream(in).readUTF(); - //ByteArrayInputStream in1 = new ByteArrayInputStream(command); - ObjectInputStream in2 = new ObjectInputStream(in) ; - HashMap table=null; - try { - table = (HashMap) in2.readObject(); - } catch (ClassNotFoundException ex) { - Logger.getLogger(BFTMapImpl.class.getName()).log(Level.SEVERE, null, ex); - } - HashMap table1=bftReplica.addTable(table4, table); - ByteArrayOutputStream bos = new ByteArrayOutputStream() ; - ObjectOutputStream out1 = new ObjectOutputStream(bos) ; - out1.writeObject(table1); - out1.close(); - in.close(); - reply = bos.toByteArray(); - break; - - case BFTMAPUtil.TAB_REMOVE: - String tableName3 = new DataInputStream(in).readUTF(); - HashMap info4=bftReplica.removeTable(tableName3); - ByteArrayOutputStream bos2 = new ByteArrayOutputStream() ; - ObjectOutputStream out3 = new ObjectOutputStream(bos2) ; - out3.writeObject(info4); - out3.close(); - out3.close(); - reply = bos2.toByteArray(); - break; - - - } - return reply; - } catch (IOException ex) { - Logger.getLogger(BFTMapImpl.class.getName()).log(Level.SEVERE, null, ex); - return null; - } - - - - } - - - } - - diff --git a/src/navigators/smart/tom/demo/CounterServer.java b/src/navigators/smart/tom/demo/CounterServer.java index 568b11b7..ce907b85 100644 --- a/src/navigators/smart/tom/demo/CounterServer.java +++ b/src/navigators/smart/tom/demo/CounterServer.java @@ -51,13 +51,13 @@ public class CounterServer extends ServiceReplica { @Override - public byte[] executeCommand(int clientId, long timestamp, byte[] nonces, byte[] command, DebugInfo info) { + public byte[] executeCommand(int clientId, long timestamp, byte[] nonces, byte[] command, boolean readOnly, DebugInfo info) { //System.out.println("Valor de counter execute "+this.counter); - iterations++; try { int increment = new DataInputStream(new ByteArrayInputStream(command)).readInt(); + System.out.println("read-only request: "+readOnly); counter += increment; if (info == null) System.out.println("[server] (" + iterations + ") Counter incremented: " + counter); else System.out.println("[server] (" + iterations + " / " + info.eid + ") Counter incremented: " + counter); diff --git a/src/navigators/smart/tom/demo/KVClient.java b/src/navigators/smart/tom/demo/KVClient.java deleted file mode 100644 index 00d70655..00000000 --- a/src/navigators/smart/tom/demo/KVClient.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package navigators.smart.tom.demo; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Scanner; - -import java.util.logging.Level; -import java.util.logging.Logger; -import navigators.smart.tom.ServiceProxy; -import java.io.Console; -import java.util.HashMap; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; -/** - * - * @author sweta - */ -public class KVClient { - - - public static void main(String[] args) throws IOException { - if(args.length < 1) { - System.out.println("Usage: java KVClient "); - System.exit(-1); - } - - BFTMap bftMap = new BFTMap(Integer.parseInt(args[0])); - - Console console = System.console(); - Scanner sc = new Scanner(System.in); - boolean res = false; - ObjectOutput out=null; - - - while(true) { - - System.out.println("select a command : 1. CREATE A NEW TABLE OF TABLES"); - System.out.println("select a command : 2. REMOVE AN EXISTING TABLE OF TABLES"); - System.out.println("select a command : 3. GET THE SIZE OF THE TABLE OF TABLES"); - System.out.println("select a command : 4. PUT VALUES INTO A TABLE"); - System.out.println("select a command : 5. GET VALUES FROM A TABLE"); - System.out.println("select a command : 6. GET THE SIZE OF A TABLE"); - System.out.println("select a command : 7. REMOVE AN EXISTING TABLE"); - - int cmd = sc.nextInt(); - - - switch(cmd) { - - //operations on the table - case BFTMAPUtil.TAB_CREATE: - - boolean result4 = false; - do { - String tableKey = console.readLine("Enter the HashMap name"); - result4 = bftMap.containsKey(tableKey); - if (!result4) { - //if the table name does not exist then create the table - bftMap.put(tableKey,new HashMap()); - } - } while(result4); - break; - - case BFTMAPUtil.SIZE_TABLE: - //obtain the size of the table of tables. - System.out.println("Computing the size of the table"); - int size=bftMap.size(); - System.out.println("The size of the table of tables is "+size); - break; - - case BFTMAPUtil.TAB_REMOVE: - //Remove the table entry - boolean result11 = false; - HashMap info = null; - String tableKey5 = null; - System.out.println("Executing remove operation on table of tables"); - do { - tableKey5 = console.readLine("Enter the valid table name you want to remove"); - result11 = bftMap.containsKey(tableKey5); - - } while(!result11); - info = bftMap.remove(tableKey5); - System.out.println("Table removed"); - break; - //operations on the hashmap - case BFTMAPUtil.PUT: - System.out.println("Execute put function"); - boolean result5 = false; - String value = null; - String tableKey = null; - String key = null; - do { - tableKey = console.readLine("Enter the valid table name in which you want to enter the data"); - result4 = bftMap.containsKey(tableKey); - if (result4) { - //if the table name does not exist then create the table - key = console.readLine("Enter the key"); - value = console.readLine("Enter the value"); - } - - } while(!result4); - - byte[] b = value.getBytes(); - byte[] result = bftMap.put1(tableKey,key, b); - System.out.println("Result : "+new String(result)); - break; - case BFTMAPUtil.GET: - System.out.println("Execute get function"); - boolean result6 = false; - boolean result7 = false; - String value2 = null; - String tableName1 = null; - String key1 = null; - do { - tableName1 = console.readLine("Enter the valid table name from which you want to get the values"); - - result6 = bftMap.containsKey(tableName1); - if (result6) { - do { - key1 = console.readLine("Enter the valid key: "); - result7 = bftMap.containsKey1(tableName1, key1); - if(result7) { - byte[] result1 = bftMap.getEntry(tableName1,key1); - System.out.println("The value received from GET is"+new String(result1)); - } - - } while(!result7); - } - } while(!result6); - - break; - case BFTMAPUtil.SIZE: - System.out.println("Execute get function"); - boolean result8 = false; - String value3 = null; - String tableName2 = null; - String key2 = null; - int size1 = -1; - do { - tableName2 = console.readLine("Enter the valid table whose size you want to detemine"); - - result8 = bftMap.containsKey(tableName2); - if (result8) { - size1 = bftMap.size1(tableName2); - System.out.println("The size is : "+size1); - - } - } while(!result8); - - - break; - case BFTMAPUtil.REMOVE: - System.out.println("Execute get function"); - boolean result9 = false; - boolean result10 = false; - String value4 = null; - String tableName3 = null; - String key3 = null; - do { - tableName3 = console.readLine("Enter the valid table name which you want to remove"); - - result9 = bftMap.containsKey(tableName3); - if (result9) { - do { - key3 = console.readLine("Enter the valid key: "); - result10 = bftMap.containsKey1(tableName3, key3); - if(result10) { - byte[] result2 = bftMap.removeEntry(tableName3,key3); - System.out.println("The previous value was : "+new String(result2)); - } - - } while(!result10); - } - } while(!result10); - - - break; - - - } - - - - - } - } -} - - - - diff --git a/src/navigators/smart/tom/demo/KVServer.java b/src/navigators/smart/tom/demo/KVServer.java deleted file mode 100644 index a4a11e66..00000000 --- a/src/navigators/smart/tom/demo/KVServer.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package navigators.smart.tom.demo; - -/** - * - * @author sweta - */ -public class KVServer { - - public static void main(String[] args){ - if(args.length < 1) { - System.out.println("Use: java KVServer "); - System.exit(-1); - } - - BFTMapImpl bftServer = new BFTMapImpl(Integer.parseInt(args[0])); - - } - -} diff --git a/src/navigators/smart/tom/demo/RWCounterClient.java b/src/navigators/smart/tom/demo/RWCounterClient.java new file mode 100644 index 00000000..dd45c3e9 --- /dev/null +++ b/src/navigators/smart/tom/demo/RWCounterClient.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2007-2009 Alysson Bessani, Eduardo Alchieri, Paulo Sousa, and the authors indicated in the @author tags + * + * This file is part of SMaRt. + * + * SMaRt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SMaRt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SMaRt. If not, see . + */ +package navigators.smart.tom.demo; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import java.util.Comparator; +import navigators.smart.tom.ServiceProxy; +import navigators.smart.tom.core.messages.TOMMessage; +import navigators.smart.tom.util.Extractor; + +/** + * Example client that updates a BFT replicated service (a counter). + * In this case in particular, the client increments the counter by 1 in + * the odd iterations (1,3,...) and read its value (using the read-only + * optimization) in the even iteractions. + * + * This example also shows how to use a Comparator and Extractor to implement + * custom processing of the reply voting. + * + * This client should be used with the CounterServer. + * + * @author alysson + */ +public class RWCounterClient { + + @SuppressWarnings("static-access") + public static void main(String[] args) throws IOException { + if (args.length < 2) { + System.err.println("Usage: java ROClient "); + System.exit(-1); + } + + ServiceProxy counterProxy = new ServiceProxy(Integer.parseInt(args[0]),"config", + new VerboseComparator(), new VerboseExtractor()); + + int iteractions = Integer.parseInt(args[1]); + + for(int i=0; i { + @Override + public int compare(byte[] o1, byte[] o2) { + try{ + int o1v = new DataInputStream(new ByteArrayInputStream(o1)).readInt(); + int o2v = new DataInputStream(new ByteArrayInputStream(o2)).readInt(); + System.out.println("comparing "+o1v+" and "+o2v); + return o1v == o2v?0:-1; + } catch(IOException ioe) { + return -1; + } + } + } + + static class VerboseExtractor implements Extractor { + @Override + public TOMMessage extractResponse(TOMMessage[] replies, int sameContent, int lastReceived) { + System.out.print("Received replies = { "); + + for(TOMMessage reply:replies) { + if(reply == null) + continue; + + try { + int v = new DataInputStream(new ByteArrayInputStream(reply.getContent())).readInt(); + System.out.print(v+" "); + } catch (IOException ioe) {} + } + + System.out.println("}"); + System.out.println("# replies with the same content = "+sameContent); + + return replies[lastReceived]; + } + + } +} diff --git a/src/navigators/smart/tom/demo/RandomServer.java b/src/navigators/smart/tom/demo/RandomServer.java index 10f8466d..a3468f7b 100644 --- a/src/navigators/smart/tom/demo/RandomServer.java +++ b/src/navigators/smart/tom/demo/RandomServer.java @@ -57,7 +57,7 @@ public class RandomServer extends ServiceReplica { } @Override - public byte[] executeCommand(int clientId, long timestamp, byte[] nonces, byte[] command, DebugInfo info) { + public byte[] executeCommand(int clientId, long timestamp, byte[] nonces, byte[] command, boolean readOnly, DebugInfo info) { /**********ISTO E CODIGO MARTELADO, PARA FAZER AVALIACOES **************/ //System.out.println(currentTime); if (initialTime > -1) currentTime = System.currentTimeMillis() - initialTime; -- GitLab