/**
* remoteCall() calls a method remotely by passing in parameters and getting a return Object
*/
- public Object remoteCall(String methodSign, Class<?> retType, Class<?> retGenTypeKey,
+ public Object remoteCall(int objectId, String methodSign, Class<?> retType, Class<?> retGenTypeKey,
Class<?> retGenTypeVal, Class<?>[] paramCls, Object[] paramObj) {
// Send method info
- byte[] methodBytes = methodToBytes(methodSign, paramCls, paramObj);
+ byte[] methodBytes = methodToBytes(objectId, methodSign, paramCls, paramObj);
try {
rmiClient.sendBytes(methodBytes);
} catch (IOException ex) {
/**
* methodToBytes() returns byte representation of a method
*/
- public byte[] methodToBytes(String methodSign, Class<?>[] paramCls, Object[] paramObj) {
+ public byte[] methodToBytes(int objectId, String methodSign, Class<?>[] paramCls, Object[] paramObj) {
+ // Initialized to the length of method ID
+ int methodLen = IoTRMIUtil.OBJECT_ID_LEN;
+ byte[] objId = IoTRMIUtil.intToByteArray(objectId);
// Get method ID in bytes
int methId = listMethodId.indexOf(methodSign);
byte[] methodId = IoTRMIUtil.intToByteArray(methId);
-
// Get byte arrays and calculate method bytes length
int numbParam = paramObj.length;
- int methodLen = IoTRMIUtil.METHOD_ID_LEN; // Initialized to the length of method ID
+ methodLen = methodLen + IoTRMIUtil.METHOD_ID_LEN;
byte[][] objBytesArr = new byte[numbParam][];
for (int i = 0; i < numbParam; i++) {
// Get byte arrays for the objects
}
methodLen = methodLen + objBytesArr[i].length;
}
-
// Construct method in byte array
byte[] method = new byte[methodLen];
int pos = 0;
- System.arraycopy(methodId, 0, method, 0, methodId.length);
+ System.arraycopy(objId, 0, method, 0, IoTRMIUtil.METHOD_ID_LEN);
+ pos = pos + IoTRMIUtil.OBJECT_ID_LEN;
+ System.arraycopy(methodId, 0, method, pos, IoTRMIUtil.METHOD_ID_LEN);
pos = pos + IoTRMIUtil.METHOD_ID_LEN;
// Second iteration for copying bytes
for (int i = 0; i < numbParam; i++) {