Separating socket creation from callback method, so that this method can be called...
[iot2.git] / iotjava / iotrmi / Java / sample / CallBack_CBStub.java
1 package iotrmi.Java.sample;
2
3 import java.io.IOException;
4 import iotrmi.Java.IoTRMICall;
5
6 public class CallBack_CBStub 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_CBStub(IoTRMICall _rmiCall, int _objectId) throws IOException {
24
25                 objectId = _objectId;
26                 rmiCall = _rmiCall;
27         }
28
29
30         // Return method signatures
31         public static String[] getMethodSignatures() {
32
33                 return methodSignatures;
34         }
35
36
37         public int printInt() {
38
39                 String sign = "intprintInt()";
40                 Class<?> retType = int.class;
41                 Class<?>[] paramCls = new Class<?>[] { };
42                 Object[] paramObj = new Object[] { };
43                 Object retObj = rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
44                 return (int)retObj;
45         }
46
47
48         public void setInt(int _i) {
49
50                 String sign = "voidsetInt(int)";
51                 Class<?> retType = void.class;
52                 Class<?>[] paramCls = new Class<?>[] { int.class };
53                 Object[] paramObj = new Object[] { _i };
54                 rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
55         }
56
57
58         public static void main(String[] args) throws Exception {
59
60                 int port = 5010;
61                 String address = "localhost";
62                 int rev = 0;
63
64                 CallBack_Stub cbstub = new CallBack_Stub(port, address, rev);
65                 cbstub.setInt(23);
66                 cbstub.printInt();
67         }
68 }