Adjusting back into the original lengthy version of IrrigationController; for testing...
[iot2.git] / benchmarks / Java / SpeakerController / RoomSmart_Stub.java
1 package SpeakerController;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Map;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
14
15 import iotcode.interfaces.*;
16
17 public class RoomSmart_Stub implements RoomSmart {
18
19         private int objectId = 4;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         private AtomicBoolean retValueReceived0 = new AtomicBoolean(false);
23         
24
25         public RoomSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
26                 if (_localPortSend != 0 && _localPortRecv != 0) {
27                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
28                 } else
29                 {
30                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
31                 }
32                 rmiComm.registerStub(objectId, 0, retValueReceived0);
33                 IoTRMIUtil.mapStub.put(objectId, this);
34         }
35
36         public RoomSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
37                 rmiComm = _rmiComm;
38                 objectId = _objectId;
39                 rmiComm.registerStub(objectId, 0, retValueReceived0);
40         }
41
42         public int getRoomID() {
43                 int methodId = 0;
44                 Class<?> retType = int.class;
45                 Class<?>[] paramCls = new Class<?>[] {  };
46                 Object[] paramObj = new Object[] {  };
47                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
48                 // Waiting for return value
49                 while (!retValueReceived0.get());
50                 Object retObj = rmiComm.getReturnValue(retType, null);
51                 retValueReceived0.set(false);
52                 rmiComm.setGetReturnBytes();
53
54                 return (int)retObj;
55         }
56
57 }