Updating the third benchmark with new stubs and skeletons
authorrtrimana <rtrimana@uci.edu>
Thu, 23 Feb 2017 21:22:14 +0000 (13:22 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 23 Feb 2017 21:22:14 +0000 (13:22 -0800)
benchmarks/Java/SpeakerController/GPSGatewayCallback_Skeleton.java [new file with mode: 0644]
benchmarks/Java/SpeakerController/GPSGatewaySmart_Stub.java
benchmarks/Java/SpeakerController/RoomSmart_Stub.java
benchmarks/Java/SpeakerController/SpeakerCallback_Skeleton.java [new file with mode: 0644]
benchmarks/Java/SpeakerController/SpeakerSmart_Stub.java

diff --git a/benchmarks/Java/SpeakerController/GPSGatewayCallback_Skeleton.java b/benchmarks/Java/SpeakerController/GPSGatewayCallback_Skeleton.java
new file mode 100644 (file)
index 0000000..c253bfd
--- /dev/null
@@ -0,0 +1,139 @@
+package SpeakerController;
+
+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 GPSGatewayCallback_Skeleton implements GPSGatewayCallback {
+
+       private GPSGatewayCallback mainObj;
+       private int objectId = 4;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private static Integer[] object4Permission = { 0, 1 };
+       private static List<Integer> set4Allowed;
+       
+
+       public GPSGatewayCallback_Skeleton(GPSGatewayCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+               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 GPSGatewayCallback_Skeleton(GPSGatewayCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
+       }
+
+       public void newRoomIDRetrieved(int _roomIdentifier) {
+               mainObj.newRoomIDRetrieved(_roomIdentifier);
+       }
+
+       public void newRingStatusRetrieved(boolean _ringStatus) {
+               mainObj.newRingStatusRetrieved(_ringStatus);
+       }
+
+       public void ___newRoomIDRetrieved() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
+               newRoomIDRetrieved((int) paramObj[0]);
+       }
+
+       public void ___newRingStatusRetrieved() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { boolean.class }, new Class<?>[] { null }, localMethodBytes);
+               newRingStatusRetrieved((boolean) paramObj[0]);
+       }
+
+       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 (!set4Allowed.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 {
+                                                       ___newRoomIDRetrieved();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 1:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___newRingStatusRetrieved();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               default: 
+                               throw new Error("Method Id " + methodId + " not recognized!");
+                       }
+               }
+       }
+
+}
index f5bc2caf02649e03afa08440f2b3d9f93fe91ed6..a3a433e8200d3fe9e1aabef51e3d35b3e0c60384 100644 (file)
@@ -4,35 +4,42 @@ 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 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 GPSGatewaySmart_Stub implements GPSGatewaySmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
-       // Callback properties
-       private IoTRMIObject rmiObj;
-       List<GPSGatewayCallback> listCallbackObj;
-       private int objIdCnt = 0;
-       private final static int object0Id = 0; //GPSGatewaySmartCallback
-       private static Integer[] object0Permission = { 0, 1 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 3;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
        
 
-       public GPSGatewaySmart_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<GPSGatewayCallback>();
-               set0Allowed.add(-9999);
-               ___initCallBack();
+       public GPSGatewaySmart_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, 4, retValueReceived4);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public GPSGatewaySmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
        }
 
        public void setNewRoomIDAvailable(boolean bValue) {
@@ -40,7 +47,7 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { boolean.class };
                Object[] paramObj = new Object[] { bValue };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void setNewRingStatusAvailable(boolean bValue) {
@@ -48,7 +55,7 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { boolean.class };
                Object[] paramObj = new Object[] { bValue };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void stop() {
@@ -56,7 +63,7 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                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() {
@@ -64,7 +71,7 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                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 init() {
@@ -72,7 +79,7 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                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 int getRoomID() {
@@ -80,14 +87,44 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                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;
        }
 
        public void registerCallback(GPSGatewayCallback _callbackTo) {
+               int[] objIdSent0 = new int[1];
                try {
-                       GPSGatewayCallback_CallbackSkeleton skel0 = new GPSGatewayCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
-                       listCallbackObj.add(skel0);
+                       if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               GPSGatewayCallback_Skeleton skel0 = new GPSGatewayCallback_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 GPSGatewayCallback_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!");
@@ -95,43 +132,9 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
 
                int methodId = 7;
                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);
-                                               GPSGatewayCallback_CallbackSkeleton skel = (GPSGatewayCallback_CallbackSkeleton) listCallbackObj.get(objId);
-                                               if (skel != null) {
-                                                       int methodId = IoTRMIObject.getMethodId(method);
-                                                       if (!set0Allowed.contains(methodId)) {
-                                                               throw new Error("Callback object for GPSGatewayCallback is not allowed to access method: " + methodId);
-                                                       }
-                                                       skel.invokeMethod(rmiObj);
-                                               } else {
-                                                       throw new Error("GPSGatewayCallback: Object with Id " + objId + " not found!");
-                                               }
-                                       }
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       throw new Error("Error instantiating class GPSGatewayCallback_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 boolean getRingStatus() {
@@ -139,7 +142,13 @@ public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
                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;
        }
 
index a45b77580dac2f323fcc59bd4c59835de30633de..e7e8f9e1e1fe2fa7f8ca0ecc982388e147075e48 100644 (file)
@@ -4,24 +4,39 @@ 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 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 {
 
-       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() {
@@ -29,7 +44,13 @@ public class RoomSmart_Stub implements RoomSmart {
                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;
        }
 
diff --git a/benchmarks/Java/SpeakerController/SpeakerCallback_Skeleton.java b/benchmarks/Java/SpeakerController/SpeakerCallback_Skeleton.java
new file mode 100644 (file)
index 0000000..316d3ea
--- /dev/null
@@ -0,0 +1,116 @@
+package SpeakerController;
+
+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 SpeakerCallback_Skeleton implements SpeakerCallback {
+
+       private SpeakerCallback mainObj;
+       private int objectId = 2;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private static Integer[] object2Permission = { 0 };
+       private static List<Integer> set2Allowed;
+       
+
+       public SpeakerCallback_Skeleton(SpeakerCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+               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 SpeakerCallback_Skeleton(SpeakerCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
+       }
+
+       public void speakerDone() {
+               mainObj.speakerDone();
+       }
+
+       public void ___speakerDone() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
+               speakerDone();
+       }
+
+       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 (!set2Allowed.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 {
+                                                       ___speakerDone();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               default: 
+                               throw new Error("Method Id " + methodId + " not recognized!");
+                       }
+               }
+       }
+
+}
index 71147e695d44408e2a510e0a9b9d69622ef99255..3bc830126c387d07f71823878cd2c69184cbd02c 100644 (file)
@@ -4,35 +4,54 @@ 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 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 SpeakerSmart_Stub implements SpeakerSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
-       // Callback properties
-       private IoTRMIObject rmiObj;
-       List<SpeakerCallback> listCallbackObj;
-       private int objIdCnt = 0;
-       private final static int object0Id = 0; //SpeakerSmartCallback
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 1;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
        
 
-       public SpeakerSmart_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<SpeakerCallback>();
-               set0Allowed.add(-9999);
-               ___initCallBack();
+       public SpeakerSmart_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, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 1, retValueReceived1);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public SpeakerSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 2, retValueReceived2);
+               rmiComm.registerStub(objectId, 1, retValueReceived1);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
        }
 
        public int getPosition() {
@@ -40,7 +59,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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 (!retValueReceived6.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived6.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -49,7 +74,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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;
        }
 
@@ -58,7 +89,7 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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 boolean startPlayback() {
@@ -66,7 +97,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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 (!retValueReceived1.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived1.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
@@ -75,7 +112,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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 (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
@@ -84,7 +127,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] { float.class };
                Object[] paramObj = new Object[] { _percent };
-               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;
        }
 
@@ -93,7 +142,13 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                Class<?> retType = float.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 (float)retObj;
        }
 
@@ -102,7 +157,7 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _mSec };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void loadData(short _samples[], int _offs, int _len) {
@@ -110,7 +165,7 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { short[].class, int.class, int.class };
                Object[] paramObj = new Object[] { _samples, _offs, _len };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void init() {
@@ -118,13 +173,37 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
                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(SpeakerCallback _cb) {
+               int[] objIdSent0 = new int[1];
                try {
-                       SpeakerCallback_CallbackSkeleton skel0 = new SpeakerCallback_CallbackSkeleton(_cb, callbackAddress, objIdCnt++);
-                       listCallbackObj.add(skel0);
+                       if (!IoTRMIUtil.mapSkel.containsKey(_cb)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               SpeakerCallback_Skeleton skel0 = new SpeakerCallback_Skeleton(_cb, rmiComm, newObjIdSent);
+                               IoTRMIUtil.mapSkel.put(_cb, skel0);
+                               IoTRMIUtil.mapSkelId.put(_cb, 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 SpeakerCallback_Skeleton!");
+                                               }
+                                       }
+                               };
+                               thread.start();
+                               while(!skel0.didAlreadyInitWaitInvoke());
+                       }
+                       else
+                       {
+                               int newObjIdSent = IoTRMIUtil.mapSkelId.get(_cb);
+                               objIdSent0[0] = newObjIdSent;
+                       }
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
@@ -132,43 +211,9 @@ public class SpeakerSmart_Stub implements SpeakerSmart {
 
                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);
-                                               SpeakerCallback_CallbackSkeleton skel = (SpeakerCallback_CallbackSkeleton) listCallbackObj.get(objId);
-                                               if (skel != null) {
-                                                       int methodId = IoTRMIObject.getMethodId(method);
-                                                       if (!set0Allowed.contains(methodId)) {
-                                                               throw new Error("Callback object for SpeakerCallback is not allowed to access method: " + methodId);
-                                                       }
-                                                       skel.invokeMethod(rmiObj);
-                                               } else {
-                                                       throw new Error("SpeakerCallback: Object with Id " + objId + " not found!");
-                                               }
-                                       }
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       throw new Error("Error instantiating class SpeakerCallback_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);
        }
 
 }