1 package iotrmi.Java.sample;
3 import java.io.IOException;
5 import java.util.Arrays;
6 import iotrmi.Java.IoTRMIObject;
8 public class CallBack_Skeleton implements CallBackInterface {
10 private int objectId = 0; // Default value is 0
11 private final static String[] methodSignatures = {
16 private CallBackInterface cb;
17 private IoTRMIObject rmiObj;
23 public CallBack_Skeleton(CallBackInterface _cb, int _port) throws
24 ClassNotFoundException, InstantiationException,
25 IllegalAccessException, IOException {
28 System.out.println("Creating CallBack_Skeleton and waiting!");
29 rmiObj = new IoTRMIObject(_port, methodSignatures);
30 ___waitRequestInvokeMethod();
34 public int printInt() {
39 public int ___printInt() {
44 public void setInt(int _i) {
49 public void ___setInt() {
50 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
51 new Class<?>[] { null }, new Class<?>[] { null });
52 setInt((int) paramObj[0]);
56 private void ___waitRequestInvokeMethod() throws IOException {
58 // Loop continuously waiting for incoming bytes
61 rmiObj.getMethodBytes();
62 int objId = rmiObj.getObjectId();
63 if (objId == objectId) {
64 // Multiplex based on object Id
65 rmiObj.getMethodBytes();
66 String methodSign = rmiObj.getSignature();
67 Object[] paramObj = null;
69 System.out.println("Method sign: " + methodSign);
71 if (methodSign.equals("intprintInt()")) {
72 retObj = ___printInt();
73 } else if (methodSign.equals("voidsetInt(int)")) {
76 throw new Error("Signature not recognized!");
77 System.out.println("Return object: " + retObj);
80 rmiObj.sendReturnObj(retObj);
82 System.out.println("Servicing remote call for method: " + methodSign);
88 // Return method signatures
89 public static String[] getMethodSignatures() {
91 return methodSignatures;
95 public static void main(String[] args) throws Exception {
98 CallBack cb = new CallBack(23);
99 CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
100 //cbSkel.waitRequestInvokeMethod();