Deviceless Benchmark
[iotcloud.git] / version2 / src / java / light_fan_embed_fake_benchmark / LightsController.java
diff --git a/version2/src/java/light_fan_embed_fake_benchmark/LightsController.java b/version2/src/java/light_fan_embed_fake_benchmark/LightsController.java
new file mode 100644 (file)
index 0000000..00f265f
--- /dev/null
@@ -0,0 +1,141 @@
+import iotcloud.*;
+import java.util.*;
+
+class LightsController {
+
+    public static void main(String[] args) throws Exception {
+
+        LightBulb bulb1 = new LightBulb();
+        LightBulb bulb2 = new LightBulb();
+        LightBulb bulb3 = new LightBulb();
+
+
+        List<LightBulb> bulbs = new ArrayList<LightBulb>();
+        bulbs.add(bulb1);
+        bulbs.add(bulb2);
+        bulbs.add(bulb3);
+
+
+        String a1 = "bulb1";
+        String a2 = "bulb2";
+        String a3 = "bulb3";
+
+        IoTString ia1 = new IoTString(a1);
+        IoTString ia2 = new IoTString(a2);
+        IoTString ia3 = new IoTString(a3);
+
+
+        List<IoTString> keys = new ArrayList<IoTString>();
+        keys.add(ia1);
+        keys.add(ia2);
+        keys.add(ia3);
+
+
+        String valueA = "on";
+        IoTString iValueA = new IoTString(valueA);
+
+
+        String pingTimerKey = "bulbController";
+        IoTString ipingTimerKey = new IoTString(pingTimerKey);
+
+
+
+        System.out.println("Starting System");
+        int counter = 0;
+
+
+        Table t1 = null;
+        try {
+            t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+            t1.addLocalCommunication(1000, "192.168.2.50", 6001);
+
+            t1.rebuild();
+        } catch (Error e) {
+
+            e.printStackTrace();
+            for (int i = 0; i < 3; i++) {
+                bulbs.get(i).setColor(0, 100, 100);
+            }
+
+
+
+            while (true) {
+                for (int i = 0; i < 3; i++) {
+                    bulbs.get(i).turnOff();
+                }
+                Thread.sleep(1000);
+
+                for (int i = 0; i < 3; i++) {
+                    bulbs.get(i).turnOn();
+                }
+                Thread.sleep(1000);
+            }
+        }
+
+
+
+
+        // Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
+        // t2.rebuild();
+
+
+        while (true) {
+
+            try {
+
+                System.out.println("Loop");
+
+                String pingTimer = Long.toString(System.currentTimeMillis());
+                IoTString ipingTimer = new IoTString(pingTimer);
+
+                // t1.update();
+                t1.startTransaction();
+                t1.addKV(ipingTimerKey, ipingTimer);
+                t1.commitTransaction();
+
+                // // t2.update();
+                // t2.startTransaction();
+                // t2.addKV(ipingTimerKey, ipingTimer);
+                // t2.commitTransaction();
+
+
+
+
+
+
+
+                for (int i = 0; i < 3; i++) {
+                    IoTString testValA1 = t1.getCommitted(keys.get(i));
+                    if ((testValA1 != null) && (testValA1.equals(iValueA) == true)) {
+                        bulbs.get(i).turnOn();
+                    } else {
+                        bulbs.get(i).turnOff();
+                    }
+                }
+
+                Thread.sleep(1000);
+
+            } catch (Error e) {
+
+                e.printStackTrace();
+                for (int i = 0; i < 3; i++) {
+                    bulbs.get(i).setColor(0, 100, 100);
+                }
+
+
+
+                while (true) {
+                    for (int i = 0; i < 3; i++) {
+                        bulbs.get(i).turnOff();
+                    }
+                    Thread.sleep(1000);
+
+                    for (int i = 0; i < 3; i++) {
+                        bulbs.get(i).turnOn();
+                    }
+                    Thread.sleep(1000);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file