Using sorted integer as method Id instead of hash values
[iot2.git] / iotjava / iotrmi / Java / IoTRMICall.java
index 2f21c72dee6a3bea6d2c1a967fab4ac5d0a61b52..433c6599513e921f02dc41fe4ecf2d0e1ac89908 100644 (file)
@@ -31,15 +31,17 @@ public class IoTRMICall {
         */
        private IoTRMIUtil rmiUtil;
        private IoTSocketClient rmiClient;
+       private List<String> listMethodId;      // Map from method ID to signature
 
 
        /**
         * Constructors
         */
-       public IoTRMICall(int _port, String _address, int _rev) throws IOException {
+       public IoTRMICall(int _port, String _address, int _rev, String[] _methodSign) throws IOException {
 
                rmiUtil = new IoTRMIUtil();
                rmiClient = new IoTSocketClient(_port, _address, _rev);
+               listMethodId = Arrays.asList(_methodSign); // Initialize the method ID map
        }
 
 
@@ -79,7 +81,8 @@ public class IoTRMICall {
        public byte[] methodToBytes(String methodSign, Class<?>[] paramCls, Object[] paramObj) {
 
                // Get method ID in bytes
-               byte[] methodId = IoTRMIUtil.getHashCodeBytes(methodSign);
+               int methId = listMethodId.indexOf(methodSign);
+               byte[] methodId = IoTRMIUtil.intToByteArray(methId);
 
                // Get byte arrays and calculate method bytes length
                int numbParam = paramObj.length;
@@ -119,7 +122,7 @@ public class IoTRMICall {
                return method;
        }
 
-       
+
        public static void main(String[] args) throws Exception {
 
                String[] test = { "123", "456", "789" };