1 package iotrmi.Java.sample;
3 import java.io.IOException;
4 import iotrmi.Java.IoTRMICall;
5 import iotruntime.master.CommunicationHandler;
7 import java.util.Arrays;
9 public class TestClass_Stub {
14 private IoTRMICall rmiCall;
15 private String address;
21 private final static int NUM_CB_OBJ = 1;
26 public TestClass_Stub(int _port, String _address, int _rev, int[] _ports) throws IOException {
30 rmiCall = new IoTRMICall(_port, _address, _rev);
35 * Instantiation of callback objects
37 public static int numCallbackObjects() {
39 return NUM_CB_OBJ; // Generated by the IoTCompiler
43 private void registerCallback(CallBackInterface _cb) {
45 //int port = 5011; // Send this info to the other end to start the stub
46 //String address = "localhost";
48 Thread thread = new Thread() {
51 CallBack_Skeleton cbskel = new CallBack_Skeleton(_cb, ports[0]);
52 cbskel.waitRequestInvokeMethod();
53 } catch (Exception ex){
55 throw new Error("Error instantiating class CallBack_Skeleton!");
61 String sign = "voidregisterCallBack(CallBackInterface)";
62 Class<?> retType = void.class;
63 // port, address, and rev
64 Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };
65 Object[] paramObj = new Object[] { ports[0], address, 0 };
66 rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
70 public void setA(int _int) {
72 String sign = "voidsetA(int)";
73 Class<?> retType = void.class;
74 Class<?>[] paramCls = new Class<?>[] { int.class };
75 Object[] paramObj = new Object[] { _int };
76 rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
80 public void setB(float _float) {
82 String sign = "voidsetB(float)";
83 Class<?> retType = void.class;
84 Class<?>[] paramCls = new Class<?>[] { float.class };
85 Object[] paramObj = new Object[] { _float };
86 rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
90 public void setC(String _string) {
92 String sign = "voidsetC(string)";
93 Class<?> retType = void.class;
94 Class<?>[] paramCls = new Class<?>[] { String.class };
95 Object[] paramObj = new Object[] { _string };
96 rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
101 public String sumArray(String[] newA) {
103 String sign = "sumArray(string[])";
104 Class<?> retType = String.class;
105 Class<?>[] paramCls = new Class<?>[] { String[].class };
106 Object[] paramObj = new Object[] { newA };
107 Object retObj = rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
108 return (String)retObj;
112 public int setAndGetA(int newA) {
113 String sign = "intsetAndGetA(int)";
114 Class<?> retType = int.class;
115 Class<?>[] paramCls = new Class<?>[] { int.class };
116 Object[] paramObj = new Object[] { newA };
117 Object retObj = rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
122 public int setACAndGetA(String newC, int newA) {
124 String sign = "intsetACAndGetA(string,int)";
125 Class<?> retType = int.class;
126 Class<?>[] paramCls = new Class<?>[] { String.class, int.class };
127 Object[] paramObj = new Object[] { newC, newA };
128 Object retObj = rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
133 public int callBack() {
135 String sign = "intcallBack()";
136 Class<?> retType = int.class;
137 Class<?>[] paramCls = new Class<?>[] { };
138 Object[] paramObj = new Object[] { };
139 Object retObj = rmiCall.remoteCall(sign, retType, null, null, paramCls, paramObj);
145 public static void main(String[] args) throws Exception {
147 CommunicationHandler comHan = new CommunicationHandler(true);
148 int numOfPorts = TestClass_Stub.numCallbackObjects();
149 int[] ports = comHan.getCallbackPorts(numOfPorts);
151 System.out.println("Allocated ports: " + Arrays.toString(ports));
154 String address = "localhost";
157 TestClass_Stub tcstub = new TestClass_Stub(port, address, rev, ports);
158 System.out.println("Return value: " + tcstub.setAndGetA(123));
159 System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
160 System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
162 CallBack cb = new CallBack(23);
163 tcstub.registerCallback(cb);
164 System.out.println("Return value from callback: " + tcstub.callBack());
165 //System.out.println("Return value: " + tcstub.setAndGetA(1234));