Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/iot2
[iot2.git] / iotjava / iotrmi / Java / IoTRMIObject.java
index 6f52228bb0d021b72c02a69582e03997b65f0e07..c960aa7080d3b08b344bf7027e308d53a6d038e0 100644 (file)
@@ -10,6 +10,9 @@ import java.util.Map;
 import java.util.Set;
 import java.lang.reflect.*;
 
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
 
 /** Class IoTRMIObject is a class that stores info of an object.
  *  <p>
@@ -23,7 +26,7 @@ import java.lang.reflect.*;
  * @version     1.0
  * @since       2016-10-03
  */
-public class IoTRMIObject {
+public final class IoTRMIObject {
 
        /**
         * Class Properties
@@ -32,6 +35,7 @@ public class IoTRMIObject {
        private IoTRMIUtil rmiUtil;
        private IoTSocketServer rmiServer;
        private byte[] methodBytes;
+       private Lock lock = new ReentrantLock();
 
 
        /**
@@ -54,8 +58,9 @@ public class IoTRMIObject {
        public byte[] getMethodBytes() throws IOException {
 
                // Receive method info
+               //System.out.println("Method RMIObj before: " + Arrays.toString(methodBytes));
                methodBytes = rmiServer.receiveBytes(methodBytes);
-               System.out.println("Method: " + Arrays.toString(methodBytes));
+               //System.out.println("Method RMIObj after: " + Arrays.toString(methodBytes));
                return methodBytes;
        }
 
@@ -88,16 +93,6 @@ public class IoTRMIObject {
        }
 
 
-       /**
-        * setMethodBytes() sets bytes for method
-        */
-       /*public void setMethodBytes(byte[] _methodBytes) throws IOException {
-
-               // Set method bytes
-               methodBytes = _methodBytes;
-       }*/
-
-
        /**
         * getMethodId() gets method Id from bytes
         */
@@ -109,7 +104,6 @@ public class IoTRMIObject {
                System.arraycopy(methodBytes, IoTRMIUtil.OBJECT_ID_LEN, methodIdBytes, 0, IoTRMIUtil.METHOD_ID_LEN);
                // Get method Id
                int methodId = IoTRMIUtil.byteArrayToInt(methodIdBytes);
-               // Get method Id
                return methodId;
        }
 
@@ -125,7 +119,6 @@ public class IoTRMIObject {
                System.arraycopy(methodBytes, IoTRMIUtil.OBJECT_ID_LEN, methodIdBytes, 0, IoTRMIUtil.METHOD_ID_LEN);
                // Get method Id
                int methodId = IoTRMIUtil.byteArrayToInt(methodIdBytes);
-               // Get method Id
                return methodId;
        }
 
@@ -236,16 +229,4 @@ public class IoTRMIObject {
 
                return retBytes;
        }
-
-
-       public static void main(String[] args) throws Exception {
-
-               int port = 5010;
-               IoTRMIObject rmiObj = new IoTRMIObject(port);
-
-               Class<?>[] retCls = new Class<?>[] { int.class, String.class, int.class };
-               Object[] retObj = new Object[] { 1234, "teststring", 5432 };
-
-               System.out.println("Bytes: " + Arrays.toString(rmiObj.returnToBytes(retCls, retObj)));
-       }
 }