1 package iotrmi.Java.sample;
3 import java.io.IOException;
5 import iotrmi.Java.IoTRMIObject;
7 import java.util.Arrays;
9 public class TestClass_Skeleton {
11 private String[] methodSignatures = {
18 "intsetACAndGetA(string,int)",
20 "voidregisterCallBack(CallBackInterface)"
24 private IoTRMIObject rmiObj;
25 private CallBackInterface cbstub;
31 //public TestClass_Skeleton(Object[] paramObj, int _port) throws
32 public TestClass_Skeleton(TestClass _tc, int _port) throws
33 ClassNotFoundException, InstantiationException,
34 IllegalAccessException, IOException {
36 //tc = new TestClass((int)paramObj[0], (float)paramObj[1], (String)paramObj[2]);
38 rmiObj = new IoTRMIObject(_port, methodSignatures);
42 public void waitRequestInvokeMethod() throws IOException {
44 // Loop continuously waiting for incoming bytes
47 rmiObj.getMethodBytes();
48 String methodSign = rmiObj.getSignature();
49 Object[] paramObj = null;
51 System.out.println("Method sign: " + methodSign);
53 if (methodSign.equals("voidsetA(int)")) {
54 paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
55 new Class<?>[] { null }, new Class<?>[] { null });
56 tc.setA((int) paramObj[0]);
57 } else if (methodSign.equals("voidsetB(float)")) {
58 paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
59 new Class<?>[] { null }, new Class<?>[] { null });
60 tc.setB((float) paramObj[0]);
61 } else if (methodSign.equals("voidsetC(string)")) {
62 paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class },
63 new Class<?>[] { null }, new Class<?>[] { null });
64 tc.setC((String) paramObj[0]);
65 } else if (methodSign.equals("sumArray(string[])")) {
66 paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class },
67 new Class<?>[] { null }, new Class<?>[] { null });
68 retObj = tc.sumArray((String[]) paramObj[0]);
69 } else if (methodSign.equals("intsetAndGetA(int)")) {
70 paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
71 new Class<?>[] { null }, new Class<?>[] { null });
72 retObj = tc.setAndGetA((int) paramObj[0]);
73 } else if (methodSign.equals("intsetACAndGetA(string,int)")) {
74 paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class },
75 new Class<?>[] { null, null }, new Class<?>[] { null, null });
76 retObj = tc.setACAndGetA((String) paramObj[0], (int) paramObj[1]);
77 } else if (methodSign.equals("voidregisterCallBack(CallBackInterface)")) {
78 paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },
79 new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
80 CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
81 tc.registerCallback((CallBackInterface) cbstub);
82 } else if (methodSign.equals("intcallBack()")) {
83 retObj = tc.callBack();
85 throw new Error("Signature un-recognized!");
88 rmiObj.sendReturnObj(retObj);
90 System.out.println("Servicing remote call for method: " + methodSign);
95 public static void main(String[] args) throws Exception {
98 TestClass tc = new TestClass(3, 5f, "7911");
99 //TestClass_Skeleton tcSkel = new TestClass_Skeleton(new Object[] { 3, 5f, "7911"}, port);
100 TestClass_Skeleton tcSkel = new TestClass_Skeleton(tc, port);
101 tcSkel.waitRequestInvokeMethod();