- rmiObj = new IoTRMIObject(_port, methodSignatures);
- waitRequestInvokeMethod();
- }
-
-
- public void waitRequestInvokeMethod() throws IOException {
-
- // Loop continuously waiting for incoming bytes
- while (true) {
-
- rmiObj.getMethodBytes();
- int _objectId = rmiObj.getObjectId();
- if (_objectId == objectId) {
- // Multiplex based on object Id
- String methodSign = rmiObj.getSignature();
- Object[] paramObj = null;
- Object retObj = null;
-
- if (methodSign.equals("voidsetA(int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setA((int) paramObj[0]);
- } else if (methodSign.equals("voidsetB(float)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setB((float) paramObj[0]);
- } else if (methodSign.equals("voidsetC(string)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setC((String) paramObj[0]);
- } else if (methodSign.equals("sumArray(string[])")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class },
- new Class<?>[] { null }, new Class<?>[] { null });
- retObj = sumArray((String[]) paramObj[0]);
- } else if (methodSign.equals("intsetAndGetA(int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- retObj = setAndGetA((int) paramObj[0]);
- } else if (methodSign.equals("intsetACAndGetA(string,int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class },
- new Class<?>[] { null, null }, new Class<?>[] { null, null });
- retObj = setACAndGetA((String) paramObj[0], (int) paramObj[1]);
- } else if (methodSign.equals("voidregisterCallBack(CallBackInterface)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },
- new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
- CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
- registerCallback((CallBackInterface) cbstub);
- } else if (methodSign.equals("voidregisterCallBack(CallBackInterface[])")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- //String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
- //IoTRMICall rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
- int numStubs = (int) paramObj[0];
- CallBackInterface[] stub = new CallBackInterface[numStubs];
- for (int objId = 0; objId < numStubs; objId++) {
- stub[objId] = new CallBack_CBStub(rmiCall, objIdCnt);
- objIdCnt++;
- }
- registerCallback(stub);
- } else if (methodSign.equals("intcallBack()")) {
- retObj = callBack();
- // Special option to register callback
- } else if (methodSign.equals("registercallback")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },
- new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
- String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
- rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
- System.out.println("Creating a new IoTRMICall object");
- } else
- throw new Error("Signature not recognized!");
-
- if (retObj != null) {
- rmiObj.sendReturnObj(retObj);
- }
- System.out.println("Servicing remote call for object: " + objectId + " - method: " + methodSign);
- }
- }