First benchmark working with capability-based RMI; adjustments in callbacks, etc.
authorrtrimana <rtrimana@uci.edu>
Wed, 21 Dec 2016 21:16:32 +0000 (13:16 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 21 Dec 2016 21:16:32 +0000 (13:16 -0800)
24 files changed:
benchmarks/Lifxtest/Lifxtest.java
benchmarks/Makefile
benchmarks/SmartLightsController/CameraCallback_CallbackSkeleton.java
benchmarks/SmartLightsController/CameraSmart_Stub.java
benchmarks/SmartLightsController/LightBulbSmart_Stub.java
benchmarks/SmartLightsController/Makefile
benchmarks/SmartLightsController/MotionDetection.java
benchmarks/SmartLightsController/SmartLightsController.java
benchmarks/drivers/AmcrestCamera/AmcrestCamera.java
benchmarks/drivers/AmcrestCamera/CameraSmartCallback_CallbackStub.java [new file with mode: 0644]
benchmarks/drivers/AmcrestCamera/Camera_Skeleton.java
benchmarks/drivers/LifxLightBulb/LifxLightBulb.config
benchmarks/drivers/LifxLightBulb/LightBulb_Skeleton.java
benchmarks/drivers/Makefile
benchmarks/interfaces/CameraCallback.java
benchmarks/interfaces/CameraSmartCallback.java
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/Java/IoTRMICall.java
iotjava/iotrmi/Java/IoTSocket.java
iotjava/iotruntime/master/CommunicationHandler.java
iotjava/iotruntime/master/IoTMaster.java
iotjava/iotruntime/slave/IoTSlave.java
localconfig/iotpolicy/AmcrestCamera/motiondetection.pol
localconfig/iotruntime/IoTMaster.config

index df951141c8e30d9769e7e58394b575a8a84a3a36..97860552ec9917ca46c9a107a2defe39f31d639d 100644 (file)
@@ -27,12 +27,12 @@ public class Lifxtest {
        public void init() throws InterruptedException {
 
                for(LightBulbTest lifx : lifx_light_bulb.values()) {
-                       Thread thread = new Thread(new Runnable() {
-                               public void run() {
+                       //Thread thread = new Thread(new Runnable() {
+                       //      public void run() {
                                        lifx.init();
-                               }
-                       });
-                       thread.start();
+                       //      }
+                       //});
+                       //thread.start();
                        Thread.sleep(1000);
 
                        for (int i = 0; i < 5; i++) {
@@ -68,7 +68,7 @@ public class Lifxtest {
                                Thread.sleep(500);
                        }
 
-                       thread.join();
+                       //thread.join();
                }
        }
 }
index 0c49d348827e08b8e73cfaf4aa0599eb0d578348..1e0aeeae8aa348b455e829b5074773ae9e9f9473 100644 (file)
@@ -4,7 +4,7 @@ BOOFJARS := $(BOOFDIR)/BoofCV-feature-0.21.jar:$(BOOFDIR)/BoofCV-io-0.21.jar:$(B
 
 include $(BASE)/common.mk
 
-all: interfaces annotation drivers Lifxtest
+all: interfaces annotation drivers Lifxtest SmartLights
 
 PHONY += interfaces
 interfaces:
index 913092afb2af4a826c041cbfcde0e7e1b2e8a61e..4c4f592578ae545d2b7d63452c704f74c2cfd206 100644 (file)
@@ -14,10 +14,6 @@ public class CameraCallback_CallbackSkeleton implements CameraCallback {
        private CameraCallback mainObj;
        private int objectId = 0;
        private String callbackAddress;
-       private static int objIdCnt = 0;
-       private IoTRMICall rmiCall;
-       private int[] ports;
-
        
 
        public CameraCallback_CallbackSkeleton(CameraCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
@@ -26,34 +22,20 @@ public class CameraCallback_CallbackSkeleton implements CameraCallback {
                objectId = _objectId;
        }
 
-       public void newCameraFrameAvailable(CameraSmart _camera) {
-               mainObj.newCameraFrameAvailable(_camera);
-       }
-
-       public void ___regCB(IoTRMIObject rmiObj) throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
-               ports = (int[]) paramObj[0];
-               rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], ports[1]);
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
+               mainObj.newCameraFrameAvailable(latestFrame, timeStamp);
        }
 
        public void ___newCameraFrameAvailable(IoTRMIObject rmiObj) {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-               new Class<?>[] { null });
-               try {
-                       CameraSmart stub0 = new CameraSmart_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
-                       objIdCnt++;
-                       newCameraFrameAvailable(stub0);
-               } catch(Exception ex) {
-                       ex.printStackTrace();
-                       throw new Error("Exception from callback object instantiation!");
-               }
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { byte[].class, long.class }, 
+               new Class<?>[] { null, null });
+               newCameraFrameAvailable((byte[]) paramObj[0], (long) paramObj[1]);
        }
 
        public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
                int methodId = rmiObj.getMethodId();
                switch (methodId) {
                        case 0: ___newCameraFrameAvailable(rmiObj); break;
-                       case -9999: ___regCB(rmiObj); break;
                        default: 
                        throw new Error("Method Id " + methodId + " not recognized!");
                }
index e81b00c4034b59887560f50306fe136461ff0937..87d836a49c4bc035babd246cc953342bdfe57e69 100644 (file)
@@ -31,6 +31,7 @@ public class CameraSmart_Stub implements CameraSmart {
                rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
                set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
                listCallbackObj = new ArrayList<CameraCallback>();
+               set0Allowed.add(-9999);
                ___initCallBack();
        }
 
@@ -137,13 +138,13 @@ public class CameraSmart_Stub implements CameraSmart {
                                        rmiObj = new IoTRMIObject(ports[0]);
                                        while (true) {
                                                byte[] method = rmiObj.getMethodBytes();
-                                               int methodId = IoTRMIObject.getMethodId(method);
-                                               if (!set0Allowed.contains(methodId)) {
-                                                       throw new Error("Callback object for CameraCallback is not allowed to access method: " + methodId);
-                                               }
                                                int objId = IoTRMIObject.getObjectId(method);
                                                CameraCallback_CallbackSkeleton skel = (CameraCallback_CallbackSkeleton) listCallbackObj.get(objId);
                                                if (skel != null) {
+                                                       int methodId = IoTRMIObject.getMethodId(method);
+                                                       if (!set0Allowed.contains(methodId)) {
+                                                               throw new Error("Callback object for CameraCallback is not allowed to access method: " + methodId);
+                                                       }
                                                        skel.invokeMethod(rmiObj);
                                                } else {
                                                        throw new Error("CameraCallback: Object with Id " + objId + " not found!");
index 3e93190fc20735763437216ab6b7c5790610a5fa..ecfccf97eea61a4e4f999b567fe195b0920645c6 100644 (file)
@@ -14,7 +14,6 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
        private IoTRMICall rmiCall;
        private String callbackAddress;
        private int[] ports;
-
        private final static int objectId = 0;
        
 
index cdbb18d2bd8539ea94921c283637d2ddf1033e83..ffda80c94028e42fff6cd9569b3d55137adef390 100644 (file)
@@ -14,6 +14,6 @@ PHONY += smartlights
 smartlights:
        $(JAVAC) $(JFLAGS) *.java
        cp SmartLightsController.config $(BIN_DIR)/SmartLightsController
-       cd $(BIN_DIR)/SmartLightsController; $(JAR) $(JARFLAGS) SmartLightsController.jar ../SmartLightsController/SmartLightsController*.class ../SmartLightsController/ColorTemperature*.class ../SmartLightsController/MotionDetection*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/LightBulb*.class
+       cd $(BIN_DIR)/SmartLightsController; $(JAR) $(JARFLAGS) SmartLightsController.jar ../SmartLightsController/SmartLightsController*.class ../SmartLightsController/ColorTemperature*.class ../SmartLightsController/MotionDetection*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/LightBulb*.class ../iotcode/interfaces/Resolution*.class
 
 .PHONY: $(PHONY)
index b683327b13b746aa63cc713c56b8205e499d8aff..d9c608e87c2b2fb1a3eaf026b09772f0a70f7c7c 100644 (file)
@@ -116,7 +116,7 @@ class MotionDetection implements CameraCallback {
        // counts the number of frames since a background image is added to algorithm
        private int frameCounter = 0;
 
-
+       private CameraSmart _camera;
 
        /*******************************************************************************************************************************************
        **
@@ -257,12 +257,13 @@ class MotionDetection implements CameraCallback {
         *
         *   @return [void] None.
         */
-       public void newCameraFrameAvailable(CameraSmart _camera) {
+       public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) {
                BufferedImage img = null;
 
                try {
                        // Parse the byte array into a Buffered Image
-                       InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
+                       //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
+                       InputStream in = new ByteArrayInputStream(latestFrame);
                        img = ImageIO.read(in);
 
                } catch (RemoteException e) {
@@ -279,8 +280,8 @@ class MotionDetection implements CameraCallback {
                imageWriteLock.lock();  // lock the image and timestamp buffers since multithread
                latestImage = img;              // image into image buffer
 
-               // timestamp from camera into timestamo buffer
-               long dateLong = _camera.getTimestamp();
+               // timestamp from camera into timestamp buffer
+               long dateLong = timeStamp;
                possibleDate = new Date(dateLong);
 
                imageWriteLock.unlock();        // Never forget to unlock
index f073df8f24a7b17ce5118ac5c1f97d8bc861446d..9f3ad93dd23864cbafb3752e2da2794a063633b8 100644 (file)
@@ -44,26 +44,25 @@ public class SmartLightsController {
        @config private IoTSet<LightBulbSmart> mainRoomLightBulbs;
        @config private IoTSet<CameraSmart> cameras;
 
-
        /*
         *  IoT Sets of Things that are not devices such as rooms
         */
-       @config private IoTSet<Room> rooms;
+       @config private IoTSet<RoomSmart> rooms;
 
        /*
         *  IoT Relations
         */
-       @config private IoTRelation<Room,CameraSmart> roomCameraRel;
-       @config private IoTRelation<Room,LightBulbSmart> roomMainBulbRel;
+       @config private IoTRelation<RoomSmart,CameraSmart> roomCameraRel;
+       @config private IoTRelation<RoomSmart,LightBulbSmart> roomMainBulbRel;
 
 
        /*
         *  The state that the room main lights are supposed to be in
         */
-       Map<Room, Boolean> roomLightOnOffStatus =
-               new HashMap<Room, Boolean>();
-       Map<Room, ColorTemperature> roomLightColorTemperature =
-               new HashMap<Room, ColorTemperature>();
+       Map<RoomSmart, Boolean> roomLightOnOffStatus =
+               new HashMap<RoomSmart, Boolean>();
+       Map<RoomSmart, ColorTemperature> roomLightColorTemperature =
+               new HashMap<RoomSmart, ColorTemperature>();
 
        /*
         *  Motion detectors that are bound to specific cameras
@@ -94,13 +93,13 @@ public class SmartLightsController {
        /** Method to detect if a room has seen motion within the last few seconds (time specified as parameter).
         *   Checks all the motion detectors for the given room
         *
-        *   @param _room            [Room] , Room of interest.
+        *   @param _room            [RoomSmart] , RoomSmart of interest.
         *   @param _numberOfSeconds [int]  , Number of seconds in the past that we consider recent.
         *   @param _upperThreshold  [int]  , Number of seconds as an upper bound before we turn off.
         *
         *   @return [boolean] if motion was detected recently.
         */
-       private boolean roomDidHaveMotionRecently(Room _room, int _numberOfSeconds) {
+       private boolean roomDidHaveMotionRecently(RoomSmart _room, int _numberOfSeconds) {
                long currentTimeSeconds = (new Date()).getTime() / 1000;
 
                // Loop through all the motion sensors in the room
@@ -144,7 +143,7 @@ public class SmartLightsController {
 
                long secondsSinceStartOfDay = currentTimeSeconds - (beginningOfToday.getTime() / 1000);
 
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // before 8:30 am
                        if (secondsSinceStartOfDay <= 30600) {
@@ -249,7 +248,7 @@ public class SmartLightsController {
         */
        private void setMainBulbs() throws RemoteException {
 
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // Lights in room should be turned off
                        if (!roomLightOnOffStatus.get(room)) {
@@ -328,9 +327,9 @@ public class SmartLightsController {
         */
        public void init() throws RemoteException, InterruptedException {
 
-
+               System.out.println("Initialized init()!");
                // Initialize the rooms
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // All rooms start with the lights turned off
                        roomLightOnOffStatus.put(room, false);
@@ -338,7 +337,7 @@ public class SmartLightsController {
                        // All rooms have a default color and temperature
                        roomLightColorTemperature.put(room, new ColorTemperature(0, 0, 100, 2500));
                }
-
+               System.out.println("Initialized rooms!");
 
                // Setup the cameras, start them all and assign each one a motion detector
                for (CameraSmart cam : cameras.values()) {
@@ -362,13 +361,16 @@ public class SmartLightsController {
                        // Remember which motion detector is for what camera
                        camMotionDetect.put(cam, mo);
                }
-
+               System.out.println("Initialized cameras!");
 
                //Initialize the light-bulbs, will turn off the bulb
                for (LightBulbSmart bulb : mainRoomLightBulbs.values()) {
+                       System.out.println("Trying to init bulb?");
                        bulb.init();
+                       System.out.println("Done init!");
                        Thread.sleep(1000);
                }
+               System.out.println("Initialized bulbs!");
 
                // Run the main loop that will keep check the bulbs and rooms periodically
                while (true) {
@@ -379,7 +381,7 @@ public class SmartLightsController {
                                lastTimeChecked = currentTimeSeconds;
 
                                // Check for motion in rooms and if there is motion then turn on the lights
-                               for (Room room : rooms.values()) {
+                               for (RoomSmart room : rooms.values()) {
 
                                        if (roomDidHaveMotionRecently(room, MOTION_TIME_THRESHOLD)) {
 
index ba3d8e3b2be82da3e46f13a9d5ad4ac380c7ff2c..686089f83d9ef0e81ed21701ef458443d4e9501f 100644 (file)
@@ -464,7 +464,7 @@ public class AmcrestCamera implements Camera {
 
                                for (CameraSmartCallback c : callbackList) {
 
-                                       c.newCameraFrameAvailable(this);
+                                       c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp());
                                }
                        } else {
 
diff --git a/benchmarks/drivers/AmcrestCamera/CameraSmartCallback_CallbackStub.java b/benchmarks/drivers/AmcrestCamera/CameraSmartCallback_CallbackStub.java
new file mode 100644 (file)
index 0000000..5913de2
--- /dev/null
@@ -0,0 +1,36 @@
+package iotcode.AmcrestCamera;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import iotrmi.Java.IoTRMICall;
+import iotrmi.Java.IoTRMIObject;
+
+import iotcode.interfaces.*;
+
+public class CameraSmartCallback_CallbackStub implements CameraSmartCallback {
+
+       private IoTRMICall rmiCall;
+       private String callbackAddress;
+       private int[] ports;
+
+       private int objectId = 0;
+       
+
+       public CameraSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
+               callbackAddress = _callbackAddress;
+               objectId = _objectId;
+               rmiCall = _rmiCall;
+               ports = _ports;
+       }
+
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
+               int methodId = 0;
+               Class<?> retType = void.class;
+               Class<?>[] paramCls = new Class<?>[] { byte[].class, long.class };
+               Object[] paramObj = new Object[] { latestFrame, timeStamp };
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+       }
+
+}
index 86d9aa883aa7e29dd18719e22e607ca53ff3d3e4..e0daeec81fa872aee5d56d5ce373a1228d319dff 100644 (file)
@@ -8,7 +8,6 @@ import iotrmi.Java.IoTRMICall;
 import iotrmi.Java.IoTRMIObject;
 
 import iotcode.interfaces.*;
-import SmartLightsController.CameraSmartCallback_CallbackStub;
 
 public class Camera_Skeleton implements Camera {
 
@@ -81,7 +80,7 @@ public class Camera_Skeleton implements Camera {
        public void ___regCB() throws IOException {
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
                ports = (int[]) paramObj[0];
-               rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], ports[0]);
+               rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
        }
 
        public void ___init() {
index 0a7ddcbe861161b396aed0d6123667e022410cda..fa88933f424c05c352ce959477bf88c0e3e6314b 100644 (file)
@@ -1,5 +1,6 @@
 # Skeleton/original interface
 INTERFACE_CLASS=LightBulb
 # Stub
-INTERFACE_STUB_CLASS=LightBulbTest
+#INTERFACE_STUB_CLASS=LightBulbTest
+INTERFACE_STUB_CLASS=LightBulbSmart
 
index bca38631ba1adf5b35c35522be9db9e855968263..ced4a23cc30a834378f55af8a4c6653169b624ae 100644 (file)
@@ -15,8 +15,8 @@ public class LightBulb_Skeleton implements LightBulb {
        private IoTRMIObject rmiObj;
 
        private String callbackAddress;
-       private final static int object0Id = 0; //LightBulbTest
-       private static Integer[] object0Permission = { 2, 6, 1, 3, 4, 8, 0, 5, 7, 9 };
+       private final static int object0Id = 0; //LightBulbSmart
+       private static Integer[] object0Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
        private static List<Integer> set0Allowed;
        
 
index 64f5d6cd90cf13d37b7d96dcc6f6337aedf778b6..891537b004f4b53b38cb251a225721a403f6dd53 100644 (file)
@@ -24,7 +24,7 @@ PHONY += camera
 camera:
        $(JAVAC) $(JFLAGS) AmcrestCamera/*.java
        cp AmcrestCamera/AmcrestCamera.config $(BIN_DIR)/iotcode/AmcrestCamera
-       cd $(BIN_DIR)/iotcode/AmcrestCamera; $(JAR) $(JARFLAGS) AmcrestCamera.jar ../../iotcode/AmcrestCamera/*.class ../../iotcode/interfaces/Camera*.class
+       cd $(BIN_DIR)/iotcode/AmcrestCamera; $(JAR) $(JARFLAGS) AmcrestCamera.jar ../../iotcode/AmcrestCamera/*.class ../../iotcode/interfaces/Camera*.class ../../iotcode/interfaces/Resolution*.class
 
 PHONY += labroom
 labroom:
index e4a07f04d0d85ef8f1b18d72cf916ed5a821ab5d..583c1260a539e5855b12618e88563d22cc5682a1 100644 (file)
@@ -1,8 +1,5 @@
 package iotcode.interfaces;
 
-import java.util.List;
-import java.util.ArrayList;
-
 public interface CameraCallback {
-       public void newCameraFrameAvailable(CameraSmart _camera);
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
 }
index 7febe020cdde21d89e6ff3b18a444b2dac5815c9..6c584cfe071b84a36683a1742d9337f27438d1a4 100644 (file)
@@ -1,9 +1,6 @@
 package iotcode.interfaces;
 
-import java.util.List;
-import java.util.ArrayList;
-
 public interface CameraSmartCallback {
 
-       public void newCameraFrameAvailable(Camera _camera);
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
 }
index 66287f93a79b4fc58d5813757128ff71f2ef71d0..a46a20be8ffc9a63d42ee85d52289a400b1535b5 100644 (file)
@@ -448,7 +448,7 @@ public class IoTCompiler {
                        println("// Callback properties");
                        println("private IoTRMIObject rmiObj;");
                        println("List<" + callbackType + "> listCallbackObj;");
-                       println("private static int objIdCnt = 0;");
+                       println("private int objIdCnt = 0;");
                        // Generate permission stuff for callback stubs
                        DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
                        InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
@@ -1149,7 +1149,7 @@ public class IoTCompiler {
                        println("// Callback properties");
                        println("private IoTRMIObject rmiObj;");
                        println("List<" + callbackType + "> listCallbackObj;");
-                       println("private static int objIdCnt = 0;");
+                       println("private int objIdCnt = 0;");
                        // Generate permission stuff for callback stubs
                        DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
                        InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
@@ -1244,7 +1244,7 @@ public class IoTCompiler {
                println("private String callbackAddress;");
                // Callback
                if (callbackExist) {
-                       println("private static int objIdCnt = 0;");
+                       println("private int objIdCnt = 0;");
                        println("private IoTRMICall rmiCall;");
                        println("private int[] ports;\n");
                }
@@ -2226,7 +2226,7 @@ public class IoTCompiler {
                // Callback
                if (callbackExist) {
 
-                       println("private static int objIdCnt = 0;");
+                       println("private int objIdCnt = 0;");
                        println("private IoTRMICall rmiCall;");
                        println("private int[] ports;\n");
                }
index 06753be29d0f43962e3afe093decc1cd0fc6a421..1c8722183ec6b6327f3d4e02a61a829acc03cdba 100644 (file)
@@ -31,7 +31,6 @@ public class IoTRMICall {
         */
        private IoTRMIUtil rmiUtil;
        private IoTSocketClient rmiClient;
-       //private List<String> listMethodId;    // Map from method ID to signature
 
 
        /**
@@ -52,10 +51,8 @@ public class IoTRMICall {
 
                // Send method info
                byte[] methodBytes = methodToBytes(objectId, methodId, paramCls, paramObj);
-               //System.out.println("Method RMICall: " + Arrays.toString(methodBytes));
                try {
                        rmiClient.sendBytes(methodBytes);
-                       //System.out.println("Sent bytes RMICall!!!");
                } catch (IOException ex) {
                        ex.printStackTrace();
                        throw new Error("IoTRMICall: Error when sending bytes - rmiClient.sendBytes()");
index 66089c95cd34ddfffa05a33602e78e67fd9d358e..848a2e97265cfd2dedaf5bbdbc76e64c7d2c7238 100644 (file)
@@ -50,7 +50,7 @@ public abstract class IoTSocket {
        /**
         * sendBytes() sends an array of bytes
         */
-       public void sendBytes(byte vals[]) throws IOException
+       public synchronized void sendBytes(byte vals[]) throws IOException
        {
                int len = vals.length;
                // Write the length first - convert to array of 4 bytes
@@ -69,11 +69,12 @@ public abstract class IoTSocket {
        /**
         * receiveBytes() receives an array of bytes
         */
-       public byte[] receiveBytes(byte val[]) throws IOException
+       public synchronized byte[] receiveBytes(byte val[]) throws IOException
        {
                int i;
                int totalbytes = 0;
                int numbytes;
+
                // Wait until input is available
                while(input.available() == 0);
                // Read the maxlen first - read 4 bytes here
@@ -104,7 +105,7 @@ public abstract class IoTSocket {
        /**
         * Close socket connection
         */
-       public void close() throws IOException
+       public synchronized void close() throws IOException
        {
                sock.close();
        }
@@ -113,7 +114,7 @@ public abstract class IoTSocket {
        /**
         * Send ACK
         */
-       public void sendAck() throws IOException
+       public synchronized void sendAck() throws IOException
        {
                int ack;
                ack = 0;
@@ -125,7 +126,7 @@ public abstract class IoTSocket {
        /**
         * Receive ACK
         */
-       public void receiveAck() throws IOException
+       public synchronized void receiveAck() throws IOException
        {
                int ack;
                ack = (int) input.read();
index db6b16193d46b1372ceda8b870e2f75ea18bf031..6f9c67a230f9cfe550c758aac665349cc42b7591 100644 (file)
@@ -479,13 +479,16 @@ public final class CommunicationHandler {
                                RuntimeOutput.print("Communication Port: " + hmComPort.get(iIndex), bVerbose);
                                RuntimeOutput.print("RMI Registry Port: " + hmRMIRegPort.get(iIndex), bVerbose);
                                RuntimeOutput.print("RMI Stub Port: " + hmRMIStubPort.get(iIndex), bVerbose);
+                               RuntimeOutput.print("\n", bVerbose);
                        }
                }
+               for(Integer i : hsCallbackPort)
+                       RuntimeOutput.print("RMI callback Port: " + i, bVerbose);
+               RuntimeOutput.print("\n", bVerbose);
 
                for(int iPort : hsDevicePort) {
-
                        RuntimeOutput.print("Device Port: " + iPort, bVerbose);
-
                }
+               RuntimeOutput.print("\n", bVerbose);
        }
 }
index 7b86afc38dafc0946418d704bc88e83fcd7eedb4..34f181ae372acbf383a476fab44959f92d47b3a8 100644 (file)
@@ -553,6 +553,7 @@ public class IoTMaster {
 
                int iNumCallbackPorts = Integer.parseInt(STR_NUM_CALLBACK_PORTS);
                Integer[] rmiCallbackPorts = commHan.getCallbackPorts(strObjName, iNumCallbackPorts);
+
                // Iterate over port numbers and set up policies
                for (int i=0; i<iNumCallbackPorts; i++) {
                        routerConfig.configureRouterMainPolicies(strRouterAdd, strIoTSlaveControllerHostAdd, strIoTSlaveObjectHostAdd,
@@ -967,7 +968,6 @@ public class IoTMaster {
                                strObjClassName, strObjClassInterfaceName, strObjStubClsIntfaceName, 
                                commHan.getRMIRegPort(strObjName), commHan.getRMIStubPort(strObjName),
                                commHan.getCallbackPorts(strObjName, iNumOfPorts));
-
                        // ROUTING POLICY: first and second controller objects in IoTRelation
                        routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strFirstIoTSlaveObjectHostAdd,
                                strSecondIoTSlaveObjectHostAdd, STR_TCP_PROTOCOL);
@@ -1026,7 +1026,7 @@ public class IoTMaster {
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTRELATION (SECOND OBJECT)
                                        commMasterToSlave(new MessageGetObject(IoTCommCode.GET_IOTRELATION_SECOND_OBJECT,
                                                objSecObj.getIoTSlaveObjectHostAdd(), objSecObj.getObjectName(), objSecObj.getObjectClassName(),
-                                               objSecObj.getObjectClassInterfaceName(), objInitInfo.getObjectStubClassInterfaceName(),
+                                               objSecObj.getObjectClassInterfaceName(), objSecObj.getObjectStubClassInterfaceName(),
                                                objSecObj.getRMIRegistryPort(), objSecObj.getRMIStubPort(), objSecObj.getRMICallbackPorts()), 
                                                "Get IoTRelation second object!", inStream, outStream);
                                }
index 856431a1f1fbe5d95f1c02ea854df100a01402cc..24df680fcb114c9eec585f6fbf30e378c40578bc 100644 (file)
@@ -66,6 +66,7 @@ public class IoTSlave {
        private Socket socket;
        private ObjectOutputStream outStream;
        private ObjectInputStream inStream;
+       private Map<String,Object> mapObjNameStub;
 
        /**
         * IoTSet object, e.g. IoTSet<ProximitySensor> proximity_sensors;
@@ -122,6 +123,7 @@ public class IoTSlave {
                socket = null;
                outStream = null;
                inStream = null;
+               mapObjNameStub = new HashMap<String,Object>();
 
                STR_JAR_FILE_PATH = null;
                STR_OBJ_CLS_PFX = null;
@@ -433,30 +435,37 @@ public class IoTSlave {
 
                // Translating into the actual Message class
                MessageGetObject sMessage = (MessageGetObject) sIoTMasterMsg;
-               // Instantiate the stub and put in the object
-               String strObjStubName = sMainObjectName + "." + sMessage.getObjectStubInterfaceName() + STUB_CLASS_SUFFIX;
-               RuntimeOutput.print("IoTSlave: Stub object: " + strObjStubName, BOOL_VERBOSE);
-               Class<?> clsStub = Class.forName(strObjStubName);       // Port number is integer
-               Class[] clsStubParams = { int.class, String.class, String.class, int.class, int[].class };
-               Constructor<?> objStubCons = clsStub.getDeclaredConstructor(clsStubParams);
-               Integer[] portsInteger = sMessage.getRMICallbackPorts();
-               int[] ports = Arrays.stream(portsInteger).mapToInt(Integer::intValue).toArray();
-               int rev = 0;
-               String callbackAddress = InetAddress.getLocalHost().getHostAddress();   // Callback address is this machine's address
-               Object objStubParams[] = { sMessage.getRMIStubPort(), sMessage.getHostAddress(), callbackAddress,
-                                                                       rev, ports };
-               RuntimeOutput.print("IoTSlave: Creating RMI stub: " +
-                       sMessage.getHostAddress() + ":" + sMessage.getRMIRegPort() +
-                       " with callback address: " + callbackAddress + " and RMI stub port: " + sMessage.getRMIStubPort(), BOOL_VERBOSE);
-               Object stubObj = objStubCons.newInstance(objStubParams);
-               RuntimeOutput.print("IoTSlave: Object name: " + sMessage.getObjectName(), BOOL_VERBOSE);
-               RuntimeOutput.print("IoTSlave: Stub address: " + callbackAddress, BOOL_VERBOSE);
-               // Class conversion to interface class of this class,
-               // e.g. ProximitySensorImpl has ProximitySensor interface
+               Object stubObjConv = null;
+               String strObjectName = sMessage.getObjectName();
                String strObjClassInterfaceName = STR_OBJ_CLS_PFX + "." + STR_INTERFACE_PFX + "." +
                        sMessage.getObjectStubInterfaceName();
                Class<?> clsInf = Class.forName(strObjClassInterfaceName);
-               Object stubObjConv = clsInf.cast(stubObj);
+               if (mapObjNameStub.containsKey(strObjectName)) {
+                       RuntimeOutput.print("IoTSlave: Getting back object on slave: " + strObjectName, BOOL_VERBOSE);
+                       stubObjConv = clsInf.cast(mapObjNameStub.get(strObjectName));
+               } else {
+                       // Instantiate the stub and put in the object
+                       String strObjStubName = sMainObjectName + "." + sMessage.getObjectStubInterfaceName() + STUB_CLASS_SUFFIX;
+                       Class<?> clsStub = Class.forName(strObjStubName);       // Port number is integer
+                       Class[] clsStubParams = { int.class, String.class, String.class, int.class, int[].class };
+                       Constructor<?> objStubCons = clsStub.getDeclaredConstructor(clsStubParams);
+                       Integer[] portsInteger = sMessage.getRMICallbackPorts();
+                       int[] ports = Arrays.stream(portsInteger).mapToInt(Integer::intValue).toArray();
+
+                       int rev = 0;
+                       String callbackAddress = InetAddress.getLocalHost().getHostAddress();   // Callback address is this machine's address
+                       Object objStubParams[] = { sMessage.getRMIStubPort(), sMessage.getHostAddress(), callbackAddress,
+                                                                               rev, ports };
+                       RuntimeOutput.print("IoTSlave: Creating RMI stub: " +
+                               sMessage.getHostAddress() + ":" + sMessage.getRMIRegPort() +
+                               " with callback address: " + callbackAddress + " and RMI stub port: " + sMessage.getRMIStubPort(), BOOL_VERBOSE);
+                       Object stubObj = objStubCons.newInstance(objStubParams);
+                       // Class conversion to interface class of this class,
+                       // e.g. ProximitySensorImpl has ProximitySensor interface
+                       RuntimeOutput.print("IoTSlave: Registering new stub object: " + strObjectName, BOOL_VERBOSE);
+                       mapObjNameStub.put(strObjectName, stubObj);
+                       stubObjConv = clsInf.cast(stubObj);
+               }
 
                return stubObjConv;
        }
index 95ace6fbe63881bfd5369194bea06114b07ead15..b60fa0b1c8286379ce4e62fc1c02ca9f0196fe4c 100644 (file)
@@ -1,10 +1,10 @@
 public interface CameraCallback {
 
-       public void newCameraFrameAvailable(Camera _camera);
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
 
        capability Callback {
                description = "Callback method";
-               method = "newCameraFrameAvailable(Camera _camera)";
+               method = "newCameraFrameAvailable(byte latestFrame[], long timeStamp)";
        }
 }
 
index da858ccb6acedf6ab4150311744e68b60fdeda4c..d98aa4d016d219dd320221a9c8a9c349534bbbb2 100644 (file)
@@ -28,5 +28,5 @@ ZIGBEE_IOTMASTER_PORT=12345
 VERBOSE=Yes
 
 #Number of callback ports
-NUMBER_CALLBACK_PORTS=4
+NUMBER_CALLBACK_PORTS=1