From f6b9683aab3ff000be38a99b8898f5f1953913af Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 14 May 2018 11:57:11 -0700 Subject: [PATCH] Updating files for the bug fix (sequence number starts from 1, not 0); adding a local program to test local communication. --- version2/src/Control-2bulbs/.idea/modules.xml | 2 +- .../com/example/ali/control/MainActivity.java | 27 ++++++++----------- .../app/src/main/java/iotcloud/CloudComm.java | 1 + .../app/src/main/java/iotcloud/Table.java | 10 +++---- .../LightsController.java | 5 ++-- .../README.txt | 16 ++++------- .../Setup.java | 12 +++++++-- .../run2.bash | 2 +- 8 files changed, 36 insertions(+), 39 deletions(-) diff --git a/version2/src/Control-2bulbs/.idea/modules.xml b/version2/src/Control-2bulbs/.idea/modules.xml index 893470c..718fdad 100644 --- a/version2/src/Control-2bulbs/.idea/modules.xml +++ b/version2/src/Control-2bulbs/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/version2/src/Control-2bulbs/app/src/main/java/com/example/ali/control/MainActivity.java b/version2/src/Control-2bulbs/app/src/main/java/com/example/ali/control/MainActivity.java index 9a0fd49..b24aecc 100644 --- a/version2/src/Control-2bulbs/app/src/main/java/com/example/ali/control/MainActivity.java +++ b/version2/src/Control-2bulbs/app/src/main/java/com/example/ali/control/MainActivity.java @@ -33,15 +33,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe private Handler handler = new Handler(); private static final String CLOUD_SERVER = "http://dc-6.calit2.uci.edu/test.iotcloud/"; private static final String PASSWORD = "reallysecret"; - private static final int LOCAL_MACHINE_ID = 400; - private static final int LISTENING_PORT = -1; + private static final int LOCAL_MACHINE_ID = 399; + private static final int LISTENING_PORT = 7000; private Runnable runnable = new Runnable() { @Override public void run() { - //String strAlarm = "alarm"; - //IoTString iotAlarm = new IoTString(strAlarm); String strBulb = "bulb"; IoTString iotBulb = new IoTString(strBulb); @@ -53,15 +51,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe //t1.rebuild(); t1.update(); IoTString testValStatus = t1.getCommitted(iotBulb); - t1.update(); - - int intStatus = 0; - if(testValStatus != null) { - String strStatus = testValStatus.toString(); - intStatus = Integer.parseInt(strStatus); - } + //t1.update(); + if(testValStatus == null) + return; - if (intStatus == 0) { + String strStatus = testValStatus.toString(); + Log.d("RAHMADI::::", "Getting bulb status: " + strStatus); + if (strStatus.equals("off")) { alarmStatus.setText("OFF"); alarmButton.setText("ON"); alarmStatus.setTextColor(Color.BLUE); @@ -69,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe alarmOn = false; Log.d("RAHMADI::::", "Set text to OFF and BLUE with alarm value: " + testValStatus); } - else {// value 1 + else {// value "on" alarmStatus.setText("ON"); alarmButton.setText("OFF"); alarmStatus.setTextColor(Color.RED); @@ -86,7 +82,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe Log.e("ALI::::", sw.toString()); } - // Repeat every 2 seconds handler.postDelayed(runnable, 1000); } @@ -110,7 +105,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe Log.e("Ali::::", "Here2"); //t1.initTable(); t1.rebuild(); // update - t1.addLocalCommunication(260, "192.168.1.192", 6000); + t1.addLocalCommunication(400, "192.168.1.192", 6000); Log.e("Ali::::", "Here3"); } catch (Exception e) { @@ -128,7 +123,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe alarmButton = (Button) findViewById(R.id.alarmButton); alarmButton.setOnClickListener(this); - //handler.post(runnable); + handler.post(runnable); } public void onClick(View v) { diff --git a/version2/src/Control-2bulbs/app/src/main/java/iotcloud/CloudComm.java b/version2/src/Control-2bulbs/app/src/main/java/iotcloud/CloudComm.java index 0ecaf77..c945167 100644 --- a/version2/src/Control-2bulbs/app/src/main/java/iotcloud/CloudComm.java +++ b/version2/src/Control-2bulbs/app/src/main/java/iotcloud/CloudComm.java @@ -753,6 +753,7 @@ class CloudComm { // Open a TCP socket connection to a local device + Log.e("RAHMADI::::", "host: " + host + " port: " + port); Socket socket = new Socket(host, port); socket.setReuseAddress(true); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); diff --git a/version2/src/Control-2bulbs/app/src/main/java/iotcloud/Table.java b/version2/src/Control-2bulbs/app/src/main/java/iotcloud/Table.java index b97be74..fdeaeb4 100644 --- a/version2/src/Control-2bulbs/app/src/main/java/iotcloud/Table.java +++ b/version2/src/Control-2bulbs/app/src/main/java/iotcloud/Table.java @@ -44,17 +44,17 @@ final public class Table { private int numberOfSlots = 0; // Number of slots stored in buffer private int bufferResizeThreshold = 0; // Threshold on the number of live slots before a resize is needed private long liveSlotCount = 0; // Number of currently live slots - private long oldestLiveSlotSequenceNumver = 0; // Smallest sequence number of the slot with a live entry + private long oldestLiveSlotSequenceNumver = 1; // Smallest sequence number of the slot with a live entry private long localMachineId = 0; // Machine ID of this client device private long sequenceNumber = 0; // Largest sequence number a client has received private long localSequenceNumber = 0; // private int smallestTableStatusSeen = -1; // Smallest Table Status that was seen in the latest slots sent from the server // private int largestTableStatusSeen = -1; // Largest Table Status that was seen in the latest slots sent from the server - private long localTransactionSequenceNumber = 0; // Local sequence number counter for transactions - private long lastTransactionSequenceNumberSpeculatedOn = -1; // the last transaction that was speculated on - private long oldestTransactionSequenceNumberSpeculatedOn = -1; // the oldest transaction that was speculated on - private long localArbitrationSequenceNumber = 0; + private long localTransactionSequenceNumber = 1; // Local sequence number counter for transactions + private long lastTransactionSequenceNumberSpeculatedOn = 0; // the last transaction that was speculated on + private long oldestTransactionSequenceNumberSpeculatedOn = 0; // the oldest transaction that was speculated on + private long localArbitrationSequenceNumber = 1; private boolean hadPartialSendToServer = false; private boolean attemptedToSendToServer = false; private long expectedsize; diff --git a/version2/src/java/light_fan_embed_benchmark_2bulbs/LightsController.java b/version2/src/java/light_fan_embed_benchmark_2bulbs/LightsController.java index 9be0b02..0f7e590 100644 --- a/version2/src/java/light_fan_embed_benchmark_2bulbs/LightsController.java +++ b/version2/src/java/light_fan_embed_benchmark_2bulbs/LightsController.java @@ -63,9 +63,8 @@ class LightsController { Table t1 = null; try { - t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 260, 6000); - //t1.addLocalCommunication(400, "192.168.1.108", 6000); - t1.addLocalCommunication(260, "192.168.1.192", 6000); + t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, 6000); + t1.addLocalCommunication(399, "192.168.1.192", 7000); t1.rebuild(); } catch (Error e) { diff --git a/version2/src/java/light_fan_embed_benchmark_2bulbs/README.txt b/version2/src/java/light_fan_embed_benchmark_2bulbs/README.txt index 8cb0d0b..fe7b11c 100644 --- a/version2/src/java/light_fan_embed_benchmark_2bulbs/README.txt +++ b/version2/src/java/light_fan_embed_benchmark_2bulbs/README.txt @@ -2,23 +2,17 @@ First build using: ./build.bash To run this example run: - # Set up the table on the cloud + # Set up the table on the cloud after cleaning up the cloud (delete everything on /iotcloud/test.iotcloud/) ./runSetup.bash # Starts the light bulb controller ./run1.bash - # Starts the fan controller - ./run3.bash - - - # For each switch you need to run (can launch as many of these as desired as long as input number is different) - ./run2.bash - + # Starts the other controller to test updates from a second local updater (trying local communication here) + # For some reason the android application timeouts everytime it executes server.accept() and it fails to + # connect to the necessary socket. + ./run2.bash Dont forget to clear the cloud server directory - - - https://javatutorial.net/raspberry-pi-java-tutorial diff --git a/version2/src/java/light_fan_embed_benchmark_2bulbs/Setup.java b/version2/src/java/light_fan_embed_benchmark_2bulbs/Setup.java index c1d3d7b..897ed62 100644 --- a/version2/src/java/light_fan_embed_benchmark_2bulbs/Setup.java +++ b/version2/src/java/light_fan_embed_benchmark_2bulbs/Setup.java @@ -5,13 +5,21 @@ class Setup { public static void main(String[] args) throws Exception { - Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 260, -1); + Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1); t1.initTable(); String a = "bulb"; IoTString ia = new IoTString(a); - t1.createNewKey(ia, 260); + t1.createNewKey(ia, 400); + + String valueA = "on"; + IoTString iValueA = new IoTString(valueA); + IoTString testValA1 = t1.getCommitted(ia); + + t1.startTransaction(); + t1.addKV(ia, iValueA); + t1.commitTransaction(); t1.update(); } diff --git a/version2/src/java/light_fan_embed_benchmark_2bulbs/run2.bash b/version2/src/java/light_fan_embed_benchmark_2bulbs/run2.bash index c12e81c..1494cff 100755 --- a/version2/src/java/light_fan_embed_benchmark_2bulbs/run2.bash +++ b/version2/src/java/light_fan_embed_benchmark_2bulbs/run2.bash @@ -1,3 +1,3 @@ #!/bin/sh -java -cp .:../iotcloud/bin WemoController \ No newline at end of file +java -cp .:../iotcloud/bin LocalControl -- 2.34.1