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);
33 public void waitRequestInvokeMethod() throws IOException {
35 // Loop continuously waiting for incoming bytes
38 rmiObj.getMethodBytes();
39 int objId = rmiObj.getObjectId();
40 if (objId == objectId) {
41 // Multiplex based on object Id
42 rmiObj.getMethodBytes();
43 String methodSign = rmiObj.getSignature();
44 Object[] paramObj = null;
46 System.out.println("Method sign: " + methodSign);
48 if (methodSign.equals("intprintInt()")) {
50 } else if (methodSign.equals("voidsetInt(int)")) {
51 paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
52 new Class<?>[] { null }, new Class<?>[] { null });
53 setInt((int) paramObj[0]);
55 throw new Error("Signature not recognized!");
56 System.out.println("Return object: " + retObj);
59 rmiObj.sendReturnObj(retObj);
61 System.out.println("Servicing remote call for method: " + methodSign);
67 // Return method signatures
68 public static String[] getMethodSignatures() {
70 return methodSignatures;
74 public int printInt() {
79 public void setInt(int _i) {
84 public static void main(String[] args) throws Exception {
87 CallBack cb = new CallBack(23);
88 CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
89 cbSkel.waitRequestInvokeMethod();