Initial version that handles multiple callback objects through 1 socket
[iot2.git] / iotjava / iotrmi / Java / sample / CallBack_CBSkeleton.java
1 package iotrmi.Java.sample;
2
3 import java.io.IOException;
4 import java.util.Set;
5 import java.util.Arrays;
6 import iotrmi.Java.IoTRMIObject;
7
8 public class CallBack_CBSkeleton implements CallBackInterface {
9
10         private int objectId = 0;       // Default value is 0
11         private final static String[] methodSignatures = {
12
13                 "intprintInt()",
14                 "voidsetInt(int)"
15         };
16         private CallBackInterface cb;
17
18
19         /**
20          * Constructors
21          */
22         public CallBack_CBSkeleton(CallBackInterface _cb, int _objectId) throws
23                 ClassNotFoundException, InstantiationException,
24                         IllegalAccessException, IOException {
25
26                 cb = _cb;
27                 objectId = _objectId;
28                 System.out.println("Creating CallBack_Skeleton and waiting!");
29         }
30
31
32         public Object invokeMethod(IoTRMIObject rmiObj) throws IOException {
33
34                 String methodSign = rmiObj.getSignature();
35                 Object[] paramObj = null;
36                 Object retObj = null;
37
38                 if (methodSign.equals("intprintInt()")) {
39                         retObj = printInt();
40                 } else if (methodSign.equals("voidsetInt(int)")) {
41                         paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
42                                 new Class<?>[] { null }, new Class<?>[] { null });
43                         setInt((int) paramObj[0]);
44                 } else
45                         throw new Error("Signature not recognized!");
46                 System.out.println("Return object: " + retObj);
47
48                 return retObj;
49         }
50
51
52         // Return method signatures
53         public static String[] getMethodSignatures() {
54
55                 return methodSignatures;
56         }
57
58
59         public int printInt() {
60                 return cb.printInt();
61         }
62
63
64         public void setInt(int _i) {
65                 cb.setInt(_i);
66         }
67
68
69         public static void main(String[] args) throws Exception {
70
71                 int port = 5010;
72                 CallBack cb = new CallBack(23);
73                 CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
74                 cbSkel.waitRequestInvokeMethod();
75         }
76 }