Updating the first benchmark with new stubs/skeletons; somehow motion detection is...
[iot2.git] / benchmarks / Java / SmartLightsController / LightBulbSmart_Stub.java
index ecfccf97eea61a4e4f999b567fe195b0920645c6..ef0c4bcb57c02c9ec0a00514b4a46f7a8ea879ae 100644 (file)
@@ -4,23 +4,75 @@ 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.LightBulbSmart;
 
 public class LightBulbSmart_Stub implements LightBulbSmart {
 
-       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 retValueReceived10 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived11 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived12 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived7 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived13 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived9 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived16 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived17 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived14 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived15 = new AtomicBoolean(false);
        
 
-       public LightBulbSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+       public LightBulbSmart_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, 10, retValueReceived10);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 11, retValueReceived11);
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 12, retValueReceived12);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 13, retValueReceived13);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 16, retValueReceived16);
+               rmiComm.registerStub(objectId, 17, retValueReceived17);
+               rmiComm.registerStub(objectId, 14, retValueReceived14);
+               rmiComm.registerStub(objectId, 15, retValueReceived15);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public LightBulbSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 10, retValueReceived10);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 11, retValueReceived11);
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 12, retValueReceived12);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 13, retValueReceived13);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 16, retValueReceived16);
+               rmiComm.registerStub(objectId, 17, retValueReceived17);
+               rmiComm.registerStub(objectId, 14, retValueReceived14);
+               rmiComm.registerStub(objectId, 15, retValueReceived15);
        }
 
        public void turnOn() {
@@ -28,7 +80,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 double getBrightnessRangeLowerBound() {
@@ -36,7 +88,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived10.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived10.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -45,7 +103,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 getState() {
@@ -53,7 +111,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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;
        }
 
@@ -62,7 +126,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived11.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived11.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -71,7 +141,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (double)retObj;
        }
 
@@ -80,7 +156,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived12.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived12.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -89,7 +171,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived7.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived7.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -98,7 +186,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived13.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived13.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -107,7 +201,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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;
        }
 
@@ -116,7 +216,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (double)retObj;
        }
 
@@ -125,7 +231,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 (!retValueReceived16.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived16.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -134,7 +246,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 (!retValueReceived17.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived17.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -143,7 +261,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { double.class, double.class, double.class };
                Object[] paramObj = new Object[] { _hue, _saturation, _brightness };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void init() {
@@ -151,7 +269,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 double getSaturationRangeLowerBound() {
@@ -159,7 +277,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived14.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived14.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -168,7 +292,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived15.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived15.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -177,7 +307,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _temperature };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
 }