Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotrmi / Java / IoTRMIComm.java
index 6840214cc137b6a6744da9b614968e57a7f627f6..651854120f641bac4367bfa15912faf9a1b89015 100644 (file)
@@ -95,15 +95,12 @@ public abstract class IoTRMIComm {
                                        // Take the current method from the queue and wake up the correct thread
                                        retValueBytes = returnQueue.poll();
                                        if (retValueBytes != null) {    // If there is method bytes
-                                               System.out.println("retValBytes in wake up thread: " + Arrays.toString(retValueBytes));
                                                int objectId = getObjectId(retValueBytes);
                                                int methodId = getMethodId(retValueBytes);
                                                String strKey = objectId + "-" + methodId;
                                                AtomicBoolean retRecv = mapStubId.get(strKey);
-                                               //System.out.println("boolean status: " + retRecv + " with key: " + strKey);
                                                didGetReturnBytes.set(false);
                                                while(!retRecv.compareAndSet(false, true));
-                                               //System.out.println("boolean status: " + retRecv + " - map has: " + mapStubId.size());
                                                while(!didGetReturnBytes.get());        // While skeleton is still processing
                                        }
                                }
@@ -128,9 +125,7 @@ public abstract class IoTRMIComm {
        public synchronized void registerStub(int objectId, int methodId, AtomicBoolean retValueReceived) {
 
                String strKey = objectId + "-" + methodId;
-               //System.out.println("Key exist? " + mapStubId.containsKey(strKey));
                mapStubId.put(strKey, retValueReceived);
-               //System.out.println("\n\nAdding keyBytes: " + strKey + " now size: " + mapStubId.size() + "\n\n");
        }
 
 
@@ -214,7 +209,6 @@ public abstract class IoTRMIComm {
                System.arraycopy(packetBytes, IoTRMIUtil.OBJECT_ID_LEN, methodIdBytes, 0, IoTRMIUtil.METHOD_ID_LEN);
                // Get method Id
                int methodId = IoTRMIUtil.byteArrayToInt(methodIdBytes);
-               // Get method Id
                return methodId;
        }
 
@@ -338,24 +332,6 @@ public abstract class IoTRMIComm {
        public abstract void remoteCall(int objectId, int methodId, Class<?>[] paramCls, Object[] paramObj);
 
 
-       /**
-        * getReturnValue() returns return value object
-        */
-       public Object getReturnValue(Class<?> retType, Class<?> retGenTypeVal) {
-
-               // Receive return value and return it to caller
-               // Now just strip off the object ID and method ID
-               int headerLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN + IoTRMIUtil.PACKET_TYPE_LEN;
-               int valByteLen = retValueBytes.length - headerLen;
-               byte[] retValBytes = new byte[valByteLen];
-               // Method Id is positioned after object Id in the byte array
-               System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
-               Object retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retValBytes);
-               // This means the right object and method have gotten the return value, so we set this back to false
-               return retObj;
-       }
-
-
        /**
         * methodToBytes() returns byte representation of a method
         */
@@ -412,23 +388,42 @@ public abstract class IoTRMIComm {
 
 
        /**
-        * getStructObjects() calls a method remotely by passing in parameters and getting a return Object
+        * getReturnValue() returns return value object
         */
-       /*public synchronized Object[] getStructObjects(Class<?>[] retType, Class<?>[] retGenTypeVal) {
+       public Object getReturnValue(Class<?> retType, Class<?> retGenTypeVal) {
 
                // Receive return value and return it to caller
-               Object[] retObj = null;
-               byte[] retObjBytes = null;
-               try {
-                       retObjBytes = rmiClientRecv.receiveBytes(retObjBytes);
-               } catch (IOException ex) {
-                       ex.printStackTrace();
-                       throw new Error("IoTRMICall: Error when receiving bytes - rmiClient.receiveBytes()");
+               // Now just strip off the object ID and method ID
+               int headerLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN + IoTRMIUtil.PACKET_TYPE_LEN;
+               int valByteLen = retValueBytes.length - headerLen;
+               byte[] retValBytes = new byte[valByteLen];
+               // Method Id is positioned after object Id in the byte array
+               Object retObj = null;
+               if (valByteLen != 0) {
+                       System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
+                       retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retValBytes);
                }
-               retObj = getReturnObjects(retObjBytes, retType, retGenTypeVal);
+               // This means the right object and method have gotten the return value, so we set this back to false
+               return retObj;
+       }
+
+
+       /**
+        * getStructObjects() calls a method remotely by passing in parameters and getting a return Object
+        */
+       public Object[] getStructObjects(Class<?>[] retType, Class<?>[] retGenTypeVal) {
+
+               // Receive return value and return it to caller
+               // Now just strip off the object ID and method ID
+               int headerLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN + IoTRMIUtil.PACKET_TYPE_LEN;
+               int valByteLen = retValueBytes.length - headerLen;
+               byte[] retValBytes = new byte[valByteLen];
+               // Method Id is positioned after object Id in the byte array
+               System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
+               Object[] retObj = getReturnObjects(retValBytes, retType, retGenTypeVal);
 
                return retObj;
-       }*/
+       }
 
 
        /**