Updating the fourth benchmark with new stubs/skeletons; it is probably better to...
authorrtrimana <rtrimana@uci.edu>
Thu, 23 Feb 2017 22:21:42 +0000 (14:21 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 23 Feb 2017 22:21:42 +0000 (14:21 -0800)
13 files changed:
benchmarks/Java/HomeSecurityController/AlarmSmart_Stub.java
benchmarks/Java/HomeSecurityController/CameraCallback_CallbackSkeleton.java [deleted file]
benchmarks/Java/HomeSecurityController/CameraCallback_Skeleton.java [new file with mode: 0644]
benchmarks/Java/HomeSecurityController/CameraSmart_Stub.java
benchmarks/Java/HomeSecurityController/Makefile
benchmarks/Java/HomeSecurityController/RoomSmart_Stub.java
benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_CallbackSkeleton.java [deleted file]
benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_Skeleton.java [new file with mode: 0644]
benchmarks/Java/HomeSecurityController/SmartthingsSensorSmart_Stub.java
benchmarks/drivers/Java/EspAlarm/Alarm_Skeleton.java
benchmarks/drivers/Java/MotionSensor/SmartthingsSensor_Skeleton.java
benchmarks/drivers/Java/MultipurposeSensor/SmartthingsSensor_Skeleton.java
benchmarks/drivers/Java/WaterLeakSensor/SmartthingsSensor_Skeleton.java

index 3dc3500..acd3116 100644 (file)
@@ -4,24 +4,45 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
 import iotcode.interfaces.*;
 
 public class AlarmSmart_Stub implements AlarmSmart {
 
 
 import iotcode.interfaces.*;
 
 public class AlarmSmart_Stub implements AlarmSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
+       private int objectId = 1;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
        
 
        
 
-       public AlarmSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+       public AlarmSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
+               if (_localPortSend != 0 && _localPortRecv != 0) {
+                       rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
+               } else
+               {
+                       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
+               }
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public AlarmSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
        }
 
        public boolean doesHaveZoneTimers() {
        }
 
        public boolean doesHaveZoneTimers() {
@@ -29,7 +50,13 @@ public class AlarmSmart_Stub implements AlarmSmart {
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived4.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived4.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
                return (boolean)retObj;
        }
 
@@ -38,8 +65,14 @@ public class AlarmSmart_Stub implements AlarmSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retLenObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
-               int retLen = (int) retLenObj;
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived2.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived2.set(false);
+               rmiComm.setGetReturnBytes();
+
+               int retLen = (int) retObj;
                Class<?>[] retCls = new Class<?>[3*retLen];
                Class<?>[] retClsVal = new Class<?>[3*retLen];
                int retPos = 0;
                Class<?>[] retCls = new Class<?>[3*retLen];
                Class<?>[] retClsVal = new Class<?>[3*retLen];
                int retPos = 0;
@@ -51,14 +84,19 @@ public class AlarmSmart_Stub implements AlarmSmart {
                        retCls[retPos] = int.class;
                        retClsVal[retPos++] = null;
                }
                        retCls[retPos] = int.class;
                        retClsVal[retPos++] = null;
                }
-               Object[] retObj = rmiCall.getStructObjects(retCls, retClsVal);
+               // Waiting for return value
+               while (!retValueReceived2.get());
+               Object[] retActualObj = rmiComm.getStructObjects(retCls, retClsVal);
+               retValueReceived2.set(false);
+               rmiComm.setGetReturnBytes();
+
                List<ZoneState> structRet = new ArrayList<ZoneState>();
                int retObjPos = 0;
                for(int i = 0; i < retLen; i++) {
                        ZoneState structRetMem = new ZoneState();
                List<ZoneState> structRet = new ArrayList<ZoneState>();
                int retObjPos = 0;
                for(int i = 0; i < retLen; i++) {
                        ZoneState structRetMem = new ZoneState();
-                       structRetMem.zoneNumber = (int) retObj[retObjPos++];
-                       structRetMem.onOffState = (boolean) retObj[retObjPos++];
-                       structRetMem.duration = (int) retObj[retObjPos++];
+                       structRetMem.zoneNumber = (int) retActualObj[retObjPos++];
+                       structRetMem.onOffState = (boolean) retActualObj[retObjPos++];
+                       structRetMem.duration = (int) retActualObj[retObjPos++];
                        structRet.add(structRetMem);
                }
                return structRet;
                        structRet.add(structRetMem);
                }
                return structRet;
@@ -69,7 +107,7 @@ public class AlarmSmart_Stub implements AlarmSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
        }
 
        public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
@@ -77,7 +115,7 @@ public class AlarmSmart_Stub implements AlarmSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class, boolean.class, int.class };
                Object[] paramObj = new Object[] { _zone, _onOff, _onDurationSeconds };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class, boolean.class, int.class };
                Object[] paramObj = new Object[] { _zone, _onOff, _onDurationSeconds };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public int getNumberOfZones() {
        }
 
        public int getNumberOfZones() {
@@ -85,7 +123,13 @@ public class AlarmSmart_Stub implements AlarmSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
                return (int)retObj;
        }
 
diff --git a/benchmarks/Java/HomeSecurityController/CameraCallback_CallbackSkeleton.java b/benchmarks/Java/HomeSecurityController/CameraCallback_CallbackSkeleton.java
deleted file mode 100644 (file)
index a980927..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package HomeSecurityController;
-
-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 CameraCallback_CallbackSkeleton implements CameraCallback {
-
-       private CameraCallback mainObj;
-       private int objectId = 0;
-       private String callbackAddress;
-       
-
-       public CameraCallback_CallbackSkeleton(CameraCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
-               callbackAddress = _callbackAddress;
-               mainObj = _mainObj;
-               objectId = _objectId;
-       }
-
-       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
-               mainObj.newCameraFrameAvailable(latestFrame, timeStamp);
-       }
-
-       public void ___newCameraFrameAvailable(IoTRMIObject rmiObj) {
-               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;
-                       default: 
-                       throw new Error("Method Id " + methodId + " not recognized!");
-               }
-       }
-
-}
diff --git a/benchmarks/Java/HomeSecurityController/CameraCallback_Skeleton.java b/benchmarks/Java/HomeSecurityController/CameraCallback_Skeleton.java
new file mode 100644 (file)
index 0000000..8dfc182
--- /dev/null
@@ -0,0 +1,116 @@
+package HomeSecurityController;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
+
+import iotcode.interfaces.*;
+
+public class CameraCallback_Skeleton implements CameraCallback {
+
+       private CameraCallback mainObj;
+       private int objectId = 3;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private static Integer[] object3Permission = { 0 };
+       private static List<Integer> set3Allowed;
+       
+
+       public CameraCallback_Skeleton(CameraCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public CameraCallback_Skeleton(CameraCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
+       }
+
+       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
+               mainObj.newCameraFrameAvailable(latestFrame, timeStamp);
+       }
+
+       public void ___newCameraFrameAvailable() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { byte[].class, long.class }, new Class<?>[] { null, null }, localMethodBytes);
+               newCameraFrameAvailable((byte[]) paramObj[0], (long) paramObj[1]);
+       }
+
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
+               while (true) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
+                               if (!set3Allowed.contains(methodId)) {
+                                       throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
+                               }
+                       }
+                       else {
+                               continue;
+                       }
+                       switch (methodId) {
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___newCameraFrameAvailable();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               default: 
+                               throw new Error("Method Id " + methodId + " not recognized!");
+                       }
+               }
+       }
+
+}
index d58dfba..a62b4b2 100644 (file)
@@ -4,35 +4,57 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
 import iotcode.interfaces.*;
 
 public class CameraSmart_Stub implements CameraSmart {
 
 
 import iotcode.interfaces.*;
 
 public class CameraSmart_Stub implements CameraSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
-       // Callback properties
-       private IoTRMIObject rmiObj;
-       List<CameraCallback> listCallbackObj;
-       private static int objIdCnt = 0;
-       private final static int object0Id = 0; //CameraSmartCallback
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 2;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived7 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived9 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
        
 
        
 
-       public CameraSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               listCallbackObj = new ArrayList<CameraCallback>();
-               set0Allowed.add(-9999);
-               ___initCallBack();
+       public CameraSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
+               if (_localPortSend != 0 && _localPortRecv != 0) {
+                       rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
+               } else
+               {
+                       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
+               }
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public CameraSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
        }
 
        public int getMaxFPS() {
        }
 
        public int getMaxFPS() {
@@ -40,7 +62,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived8.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived8.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
                return (int)retObj;
        }
 
@@ -49,7 +77,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _fps };
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _fps };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived7.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived7.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
                return (boolean)retObj;
        }
 
@@ -58,7 +92,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived9.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived9.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
                return (int)retObj;
        }
 
@@ -69,7 +109,13 @@ public class CameraSmart_Stub implements CameraSmart {
                paramEnum0[0] = _res.ordinal();
                Class<?>[] paramCls = new Class<?>[] { int[].class };
                Object[] paramObj = new Object[] { paramEnum0 };
                paramEnum0[0] = _res.ordinal();
                Class<?>[] paramCls = new Class<?>[] { int[].class };
                Object[] paramObj = new Object[] { paramEnum0 };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived6.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived6.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
                return (boolean)retObj;
        }
 
@@ -78,7 +124,7 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void start() {
        }
 
        public void start() {
@@ -86,7 +132,7 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public long getTimestamp() {
        }
 
        public long getTimestamp() {
@@ -94,7 +140,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = long.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = long.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived4.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived4.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (long)retObj;
        }
 
                return (long)retObj;
        }
 
@@ -103,7 +155,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = byte[].class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = byte[].class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (byte[])retObj;
        }
 
                return (byte[])retObj;
        }
 
@@ -112,13 +170,37 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void registerCallback(CameraCallback _callbackTo) {
        }
 
        public void registerCallback(CameraCallback _callbackTo) {
+               int[] objIdSent0 = new int[1];
                try {
                try {
-                       CameraCallback_CallbackSkeleton skel0 = new CameraCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
-                       listCallbackObj.add(skel0);
+                       if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               CameraCallback_Skeleton skel0 = new CameraCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
+                               IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
+                               IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
+                               Thread thread = new Thread() {
+                                       public void run() {
+                                               try {
+                                                       skel0.___waitRequestInvokeMethod();
+                                                       } catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                                       throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for CameraCallback_Skeleton!");
+                                               }
+                                       }
+                               };
+                               thread.start();
+                               while(!skel0.didAlreadyInitWaitInvoke());
+                       }
+                       else
+                       {
+                               int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
+                               objIdSent0[0] = newObjIdSent;
+                       }
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
@@ -126,43 +208,9 @@ public class CameraSmart_Stub implements CameraSmart {
 
                int methodId = 10;
                Class<?> retType = void.class;
 
                int methodId = 10;
                Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int.class };
-               Object[] paramObj = new Object[] { new Integer(1) };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
-       }
-
-       public void ___initCallBack() {
-               Thread thread = new Thread() {
-                       public void run() {
-                               try {
-                                       rmiObj = new IoTRMIObject(ports[0]);
-                                       while (true) {
-                                               byte[] method = rmiObj.getMethodBytes();
-                                               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!");
-                                               }
-                                       }
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       throw new Error("Error instantiating class CameraCallback_CallbackSkeleton!");
-                               }
-                       }
-               };
-               thread.start();
-
-               int methodId = -9998;
-               Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
-               Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               Class<?>[] paramCls = new Class<?>[] { int[].class };
+               Object[] paramObj = new Object[] { objIdSent0 };
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public List<Resolution> getSupportedResolutions() {
        }
 
        public List<Resolution> getSupportedResolutions() {
@@ -170,7 +218,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = int[].class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int[].class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived5.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived5.set(false);
+               rmiComm.setGetReturnBytes();
+
                int[] retEnum = (int[]) retObj;
                Resolution[] enumVals = Resolution.values();
                int retLen = retEnum.length;
                int[] retEnum = (int[]) retObj;
                Resolution[] enumVals = Resolution.values();
                int retLen = retEnum.length;
index 0a28e91..7094972 100644 (file)
@@ -22,12 +22,12 @@ PHONY += homesecurity
 homesecurity:
        $(JAVAC) $(JFLAGS) *.java
        cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController
 homesecurity:
        $(JAVAC) $(JFLAGS) *.java
        cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController
-       cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/MotionDetection*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class  ../iotcode/interfaces/ZoneState*.class
+       cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/MotionDetection*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class  ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class
 
 PHONY += check-homesecurity
 check-homesecurity:
        $(JAVAC) $(JFLAGS) $(CHECKER_OPT) $(ASTUBS) *.java
        cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController
 
 PHONY += check-homesecurity
 check-homesecurity:
        $(JAVAC) $(JFLAGS) $(CHECKER_OPT) $(ASTUBS) *.java
        cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController
-       cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/MotionDetection*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class  ../iotcode/interfaces/ZoneState*.class
+       cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/MotionDetection*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class  ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class
 
 .PHONY: $(PHONY)
 
 .PHONY: $(PHONY)
index 0c04049..9d2c37a 100644 (file)
@@ -4,24 +4,39 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
 
-import iotcode.interfaces.RoomSmart;
+import iotcode.interfaces.*;
 
 public class RoomSmart_Stub implements RoomSmart {
 
 
 public class RoomSmart_Stub implements RoomSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
+       private int objectId = 4;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived0 = new AtomicBoolean(false);
        
 
        
 
-       public RoomSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+       public RoomSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
+               if (_localPortSend != 0 && _localPortRecv != 0) {
+                       rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
+               } else
+               {
+                       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
+               }
+               rmiComm.registerStub(objectId, 0, retValueReceived0);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public RoomSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 0, retValueReceived0);
        }
 
        public int getRoomID() {
        }
 
        public int getRoomID() {
@@ -29,7 +44,13 @@ public class RoomSmart_Stub implements RoomSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived0.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived0.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
                return (int)retObj;
        }
 
diff --git a/benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_CallbackSkeleton.java b/benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_CallbackSkeleton.java
deleted file mode 100644 (file)
index 6e09471..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package HomeSecurityController;
-
-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 SmartthingsSensorCallback_CallbackSkeleton implements SmartthingsSensorCallback {
-
-       private SmartthingsSensorCallback mainObj;
-       private int objectId = 0;
-       private String callbackAddress;
-       
-
-       public SmartthingsSensorCallback_CallbackSkeleton(SmartthingsSensorCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
-               callbackAddress = _callbackAddress;
-               mainObj = _mainObj;
-               objectId = _objectId;
-       }
-
-       public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
-               mainObj.newReadingAvailable(_sensorId, _value, _activeValue);
-       }
-
-       public void ___newReadingAvailable(IoTRMIObject rmiObj) {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, int.class, boolean.class }, 
-               new Class<?>[] { null, null, null });
-               newReadingAvailable((int) paramObj[0], (int) paramObj[1], (boolean) paramObj[2]);
-       }
-
-       public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
-               int methodId = rmiObj.getMethodId();
-               switch (methodId) {
-                       case 0: ___newReadingAvailable(rmiObj); break;
-                       default: 
-                       throw new Error("Method Id " + methodId + " not recognized!");
-               }
-       }
-
-}
diff --git a/benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_Skeleton.java b/benchmarks/Java/HomeSecurityController/SmartthingsSensorCallback_Skeleton.java
new file mode 100644 (file)
index 0000000..6a95279
--- /dev/null
@@ -0,0 +1,116 @@
+package HomeSecurityController;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
+
+import iotcode.interfaces.*;
+
+public class SmartthingsSensorCallback_Skeleton implements SmartthingsSensorCallback {
+
+       private SmartthingsSensorCallback mainObj;
+       private int objectId = 3;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private static Integer[] object3Permission = { 0 };
+       private static List<Integer> set3Allowed;
+       
+
+       public SmartthingsSensorCallback_Skeleton(SmartthingsSensorCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public SmartthingsSensorCallback_Skeleton(SmartthingsSensorCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
+       }
+
+       public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+               mainObj.newReadingAvailable(_sensorId, _value, _activeValue);
+       }
+
+       public void ___newReadingAvailable() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, int.class, boolean.class }, new Class<?>[] { null, null, null }, localMethodBytes);
+               newReadingAvailable((int) paramObj[0], (int) paramObj[1], (boolean) paramObj[2]);
+       }
+
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
+               while (true) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
+                               if (!set3Allowed.contains(methodId)) {
+                                       throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
+                               }
+                       }
+                       else {
+                               continue;
+                       }
+                       switch (methodId) {
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___newReadingAvailable();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               default: 
+                               throw new Error("Method Id " + methodId + " not recognized!");
+                       }
+               }
+       }
+
+}
index 87eff75..010e4c2 100644 (file)
@@ -4,35 +4,48 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
 import iotcode.interfaces.*;
 
 public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
 
 
 import iotcode.interfaces.*;
 
 public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
-       // Callback properties
-       private IoTRMIObject rmiObj;
-       List<SmartthingsSensorCallback> listCallbackObj;
-       private int objIdCnt = 0;
-       private final static int object0Id = 0; //SmartthingsSensorSmartCallback
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 3;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
        
 
        
 
-       public SmartthingsSensorSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               listCallbackObj = new ArrayList<SmartthingsSensorCallback>();
-               set0Allowed.add(-9999);
-               ___initCallBack();
+       public SmartthingsSensorSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
+               if (_localPortSend != 0 && _localPortRecv != 0) {
+                       rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
+               } else
+               {
+                       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
+               }
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
+               rmiComm.registerStub(objectId, 1, retValueReceived1);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public SmartthingsSensorSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
+               rmiComm.registerStub(objectId, 1, retValueReceived1);
        }
 
        public long getTimestampOfLastReading() {
        }
 
        public long getTimestampOfLastReading() {
@@ -40,7 +53,13 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = long.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = long.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (long)retObj;
        }
 
                return (long)retObj;
        }
 
@@ -49,7 +68,13 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived2.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived2.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
                return (boolean)retObj;
        }
 
@@ -58,14 +83,44 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived5.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived5.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
        public void registerCallback(SmartthingsSensorCallback _callbackTo) {
                return (int)retObj;
        }
 
        public void registerCallback(SmartthingsSensorCallback _callbackTo) {
+               int[] objIdSent0 = new int[1];
                try {
                try {
-                       SmartthingsSensorCallback_CallbackSkeleton skel0 = new SmartthingsSensorCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
-                       listCallbackObj.add(skel0);
+                       if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               SmartthingsSensorCallback_Skeleton skel0 = new SmartthingsSensorCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
+                               IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
+                               IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
+                               Thread thread = new Thread() {
+                                       public void run() {
+                                               try {
+                                                       skel0.___waitRequestInvokeMethod();
+                                                       } catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                                       throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for SmartthingsSensorCallback_Skeleton!");
+                                               }
+                                       }
+                               };
+                               thread.start();
+                               while(!skel0.didAlreadyInitWaitInvoke());
+                       }
+                       else
+                       {
+                               int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
+                               objIdSent0[0] = newObjIdSent;
+                       }
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
@@ -73,43 +128,9 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
 
                int methodId = 6;
                Class<?> retType = void.class;
 
                int methodId = 6;
                Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int.class };
-               Object[] paramObj = new Object[] { new Integer(1) };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
-       }
-
-       public void ___initCallBack() {
-               Thread thread = new Thread() {
-                       public void run() {
-                               try {
-                                       rmiObj = new IoTRMIObject(ports[0]);
-                                       while (true) {
-                                               byte[] method = rmiObj.getMethodBytes();
-                                               int objId = IoTRMIObject.getObjectId(method);
-                                               SmartthingsSensorCallback_CallbackSkeleton skel = (SmartthingsSensorCallback_CallbackSkeleton) listCallbackObj.get(objId);
-                                               if (skel != null) {
-                                                       int methodId = IoTRMIObject.getMethodId(method);
-                                                       if (!set0Allowed.contains(methodId)) {
-                                                               throw new Error("Callback object for SmartthingsSensorCallback is not allowed to access method: " + methodId);
-                                                       }
-                                                       skel.invokeMethod(rmiObj);
-                                               } else {
-                                                       throw new Error("SmartthingsSensorCallback: Object with Id " + objId + " not found!");
-                                               }
-                                       }
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       throw new Error("Error instantiating class SmartthingsSensorCallback_CallbackSkeleton!");
-                               }
-                       }
-               };
-               thread.start();
-
-               int methodId = -9998;
-               Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
-               Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               Class<?>[] paramCls = new Class<?>[] { int[].class };
+               Object[] paramObj = new Object[] { objIdSent0 };
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public int getValue() {
        }
 
        public int getValue() {
@@ -117,7 +138,13 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived1.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived1.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
                return (int)retObj;
        }
 
@@ -126,7 +153,7 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { id };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { id };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void init() {
        }
 
        public void init() {
@@ -134,7 +161,7 @@ public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
 }
        }
 
 }
index 8d8ab89..a7b02cf 100644 (file)
@@ -4,28 +4,65 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
 import iotcode.interfaces.*;
 
 public class Alarm_Skeleton implements Alarm {
 
        private Alarm mainObj;
 
 import iotcode.interfaces.*;
 
 public class Alarm_Skeleton implements Alarm {
 
        private Alarm mainObj;
-       private IoTRMIObject rmiObj;
-
-       private String callbackAddress;
-       private final static int object0Id = 0; //AlarmSmart
-       private static Integer[] object0Permission = { 4, 2, 0, 1, 3 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 1;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private static Integer[] object1Permission = { 4, 2, 0, 1, 3 };
+       private static List<Integer> set1Allowed;
        
 
        
 
-       public Alarm_Skeleton(Alarm _mainObj, String _callbackAddress, int _port) throws Exception {
+       public Alarm_Skeleton(Alarm _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public Alarm_Skeleton(Alarm _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
                mainObj = _mainObj;
                mainObj = _mainObj;
-               callbackAddress = _callbackAddress;
-               rmiObj = new IoTRMIObject(_port);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               ___waitRequestInvokeMethod();
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
        }
 
        public void init() {
        }
 
        public void init() {
@@ -49,24 +86,27 @@ public class Alarm_Skeleton implements Alarm {
        }
 
        public void ___init() {
        }
 
        public void ___init() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                init();
        }
 
        public void ___setZone() {
                init();
        }
 
        public void ___setZone() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class }, 
-               new Class<?>[] { null, null, null });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class }, new Class<?>[] { null, null, null }, localMethodBytes);
                setZone((int) paramObj[0], (boolean) paramObj[1], (int) paramObj[2]);
        }
 
        public void ___getZoneStates() throws IOException {
                setZone((int) paramObj[0], (boolean) paramObj[1], (int) paramObj[2]);
        }
 
        public void ___getZoneStates() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                List<ZoneState> retStruct = getZoneStates();
                int retLen = retStruct.size();
                Object retLenObj = retLen;
                List<ZoneState> retStruct = getZoneStates();
                int retLen = retStruct.size();
                Object retLenObj = retLen;
-               rmiObj.sendReturnObj(retLenObj);
+               rmiComm.sendReturnObj(retLenObj, localMethodBytes);
                Class<?>[] retCls = new Class<?>[3*retLen];
                Object[] retObj = new Object[3*retLen];
                int retPos = 0;
                Class<?>[] retCls = new Class<?>[3*retLen];
                Object[] retObj = new Object[3*retLen];
                int retPos = 0;
@@ -78,42 +118,104 @@ public class Alarm_Skeleton implements Alarm {
                        retCls[retPos] = int.class;
                        retObj[retPos++] = retStruct.get(i).duration;
                }
                        retCls[retPos] = int.class;
                        retObj[retPos++] = retStruct.get(i).duration;
                }
-               rmiObj.sendReturnObj(retCls, retObj);
+               rmiComm.sendReturnObj(retCls, retObj, localMethodBytes);
        }
 
        public void ___getNumberOfZones() throws IOException {
        }
 
        public void ___getNumberOfZones() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getNumberOfZones();
                Object retObj = getNumberOfZones();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___doesHaveZoneTimers() throws IOException {
        }
 
        public void ___doesHaveZoneTimers() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = doesHaveZoneTimers();
                Object retObj = doesHaveZoneTimers();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        }
 
-       private void ___waitRequestInvokeMethod() throws IOException {
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
                while (true) {
                while (true) {
-                       rmiObj.getMethodBytes();
-                       int _objectId = rmiObj.getObjectId();
-                       int methodId = rmiObj.getMethodId();
-                       if (_objectId == object0Id) {
-                               if (!set0Allowed.contains(methodId)) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
+                               if (!set1Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
                        else {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
                        else {
-                               throw new Error("Object Id: " + _objectId + " not recognized!");
+                               continue;
                        }
                        switch (methodId) {
                        }
                        switch (methodId) {
-                               case 0: ___init(); break;
-                               case 1: ___setZone(); break;
-                               case 2: ___getZoneStates(); break;
-                               case 3: ___getNumberOfZones(); break;
-                               case 4: ___doesHaveZoneTimers(); break;
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___init();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 1:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___setZone();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 2:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getZoneStates();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 3:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getNumberOfZones();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 4:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___doesHaveZoneTimers();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
                                default: 
                                throw new Error("Method Id " + methodId + " not recognized!");
                        }
                                default: 
                                throw new Error("Method Id " + methodId + " not recognized!");
                        }
index d6924b4..f66fa7f 100644 (file)
@@ -17,7 +17,7 @@ import iotcode.interfaces.*;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
-       private int objectId = 2;
+       private int objectId = 3;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
index 6ddc6cf..0222a0d 100644 (file)
@@ -17,7 +17,7 @@ import iotcode.interfaces.*;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
-       private int objectId = 2;
+       private int objectId = 3;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
index 62cf61c..5ec84c2 100644 (file)
@@ -17,7 +17,7 @@ import iotcode.interfaces.*;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
 public class SmartthingsSensor_Skeleton implements SmartthingsSensor {
 
        private SmartthingsSensor mainObj;
-       private int objectId = 2;
+       private int objectId = 3;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;