Using methodId directly without method signature; placing sendReturnObj in individual...
[iot2.git] / iotjava / iotrmi / Java / sample / CallBack_Stub.java
1 package iotrmi.Java.sample;
2
3 import java.io.IOException;
4 import iotrmi.Java.IoTRMICall;
5
6 public class CallBack_Stub implements CallBackInterface {
7
8         /**
9          * Class Properties
10          */
11         private IoTRMICall rmiCall;
12
13         private int objectId = 0;       // Default value is 0
14         private final static String[] methodSignatures = {
15
16                 "intprintInt()",
17                 "voidsetInt(int)"
18         };
19
20         /**
21          * Constructors
22          */
23         public CallBack_Stub(int _port, String _address, int _rev) throws IOException {
24
25                 rmiCall = new IoTRMICall(_port, _address, _rev);
26         }
27
28
29         // Return method signatures
30         public static String[] getMethodSignatures() {
31
32                 return methodSignatures;
33         }
34
35
36         public int printInt() {
37
38                 int methodId = 0;
39                 Class<?> retType = int.class;
40                 Class<?>[] paramCls = new Class<?>[] { };
41                 Object[] paramObj = new Object[] { };
42                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
43                 return (int)retObj;
44         }
45
46
47         public void setInt(int _i) {
48
49                 int methodId = 1;
50                 Class<?> retType = void.class;
51                 Class<?>[] paramCls = new Class<?>[] { int.class };
52                 Object[] paramObj = new Object[] { _i };
53                 rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
54         }
55
56
57         public static void main(String[] args) throws Exception {
58
59                 int port = 5010;
60                 String address = "localhost";
61                 int rev = 0;
62
63                 CallBack_Stub cbstub = new CallBack_Stub(port, address, rev);
64                 cbstub.setInt(23);
65                 cbstub.printInt();
66         }
67 }