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>
* @version 1.0
* @since 2016-10-03
*/
-public class IoTRMIObject {
+public final class IoTRMIObject {
/**
* Class Properties
private IoTRMIUtil rmiUtil;
private IoTSocketServer rmiServer;
private byte[] methodBytes;
+ private Lock lock = new ReentrantLock();
/**
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;
}
/**
- * setMethodBytes() sets bytes for method
+ * getMethodId() gets method Id from bytes
*/
- /*public void setMethodBytes(byte[] _methodBytes) throws IOException {
+ public int getMethodId() {
- // Set method bytes
- methodBytes = _methodBytes;
- }*/
+ // Get method Id bytes
+ byte[] methodIdBytes = new byte[IoTRMIUtil.METHOD_ID_LEN];
+ // Method Id is positioned after object Id in the byte array
+ System.arraycopy(methodBytes, IoTRMIUtil.OBJECT_ID_LEN, methodIdBytes, 0, IoTRMIUtil.METHOD_ID_LEN);
+ // Get method Id
+ int methodId = IoTRMIUtil.byteArrayToInt(methodIdBytes);
+ return methodId;
+ }
/**
- * getMethodId() gets method Id from bytes
+ * static version of getMethodId()
*/
- public int getMethodId() {
+ public static int getMethodId(byte[] methodBytes) {
// Get method Id bytes
byte[] methodIdBytes = new byte[IoTRMIUtil.METHOD_ID_LEN];
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;
}
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)));
- }
}