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 implements TestClassInterface {
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 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 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 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 = 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 = 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 = 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 registerCallback((CallBackInterface) cbstub);
82 } else if (methodSign.equals("intcallBack()")) {
85 throw new Error("Signature un-recognized!");
88 rmiObj.sendReturnObj(retObj);
90 System.out.println("Servicing remote call for method: " + methodSign);
95 public void setA(int _int) {
101 public void setB(float _float) {
107 public void setC(String _string) {
113 public String sumArray(String[] newA) {
115 return tc.sumArray(newA);
119 public int setAndGetA(int newA) {
121 return tc.setAndGetA(newA);
125 public int setACAndGetA(String newC, int newA) {
127 return tc.setACAndGetA(newC, newA);
131 public void registerCallback(CallBackInterface _cb) {
133 tc.registerCallback(_cb);
137 public int callBack() {
139 return tc.callBack();
143 public static void main(String[] args) throws Exception {
146 TestClass tc = new TestClass(3, 5f, "7911");
147 //TestClass_Skeleton tcSkel = new TestClass_Skeleton(new Object[] { 3, 5f, "7911"}, port);
148 TestClass_Skeleton tcSkel = new TestClass_Skeleton(tc, port);
149 tcSkel.waitRequestInvokeMethod();