Adjusting back into the original lengthy version of IrrigationController; for testing...
[iot2.git] / benchmarks / Java / IrrigationController / WeatherGatewaySmart_Stub.java
1 package IrrigationController;
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 WeatherGatewaySmart_Stub implements WeatherGatewaySmart {
18
19         private int objectId = 3;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
23         private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
24         private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
25         private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
26         
27
28         public WeatherGatewaySmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
29                 if (_localPortSend != 0 && _localPortRecv != 0) {
30                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
31                 } else
32                 {
33                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
34                 }
35                 rmiComm.registerStub(objectId, 3, retValueReceived3);
36                 rmiComm.registerStub(objectId, 6, retValueReceived6);
37                 rmiComm.registerStub(objectId, 5, retValueReceived5);
38                 rmiComm.registerStub(objectId, 4, retValueReceived4);
39                 IoTRMIUtil.mapStub.put(objectId, this);
40         }
41
42         public WeatherGatewaySmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
43                 rmiComm = _rmiComm;
44                 objectId = _objectId;
45                 rmiComm.registerStub(objectId, 3, retValueReceived3);
46                 rmiComm.registerStub(objectId, 6, retValueReceived6);
47                 rmiComm.registerStub(objectId, 5, retValueReceived5);
48                 rmiComm.registerStub(objectId, 4, retValueReceived4);
49         }
50
51         public double getInchesPerWeek() {
52                 int methodId = 3;
53                 Class<?> retType = double.class;
54                 Class<?>[] paramCls = new Class<?>[] {  };
55                 Object[] paramObj = new Object[] {  };
56                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
57                 // Waiting for return value
58                 while (!retValueReceived3.get());
59                 Object retObj = rmiComm.getReturnValue(retType, null);
60                 retValueReceived3.set(false);
61                 rmiComm.setGetReturnBytes();
62
63                 return (double)retObj;
64         }
65
66         public double getInchesPerMinute() {
67                 int methodId = 6;
68                 Class<?> retType = double.class;
69                 Class<?>[] paramCls = new Class<?>[] {  };
70                 Object[] paramObj = new Object[] {  };
71                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
72                 // Waiting for return value
73                 while (!retValueReceived6.get());
74                 Object retObj = rmiComm.getReturnValue(retType, null);
75                 retValueReceived6.set(false);
76                 rmiComm.setGetReturnBytes();
77
78                 return (double)retObj;
79         }
80
81         public int getDaysToWaterOn() {
82                 int methodId = 5;
83                 Class<?> retType = int.class;
84                 Class<?>[] paramCls = new Class<?>[] {  };
85                 Object[] paramObj = new Object[] {  };
86                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
87                 // Waiting for return value
88                 while (!retValueReceived5.get());
89                 Object retObj = rmiComm.getReturnValue(retType, null);
90                 retValueReceived5.set(false);
91                 rmiComm.setGetReturnBytes();
92
93                 return (int)retObj;
94         }
95
96         public void registerCallback(WeatherGatewayCallback _callbackTo) {
97                 int[] objIdSent0 = new int[1];
98                 try {
99                         if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
100                                 int newObjIdSent = rmiComm.getObjectIdCounter();
101                                 objIdSent0[0] = newObjIdSent;
102                                 rmiComm.decrementObjectIdCounter();
103                                 WeatherGatewayCallback_Skeleton skel0 = new WeatherGatewayCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
104                                 IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
105                                 IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
106                                 Thread thread = new Thread() {
107                                         public void run() {
108                                                 try {
109                                                         skel0.___waitRequestInvokeMethod();
110                                                         } catch (Exception ex) {
111                                                         ex.printStackTrace();
112                                                         throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for WeatherGatewayCallback_Skeleton!");
113                                                 }
114                                         }
115                                 };
116                                 thread.start();
117                                 while(!skel0.didAlreadyInitWaitInvoke());
118                         }
119                         else
120                         {
121                                 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
122                                 objIdSent0[0] = newObjIdSent;
123                         }
124                 } catch (Exception ex) {
125                         ex.printStackTrace();
126                         throw new Error("Exception when generating skeleton objects!");
127                 }
128
129                 int methodId = 7;
130                 Class<?> retType = void.class;
131                 Class<?>[] paramCls = new Class<?>[] { int[].class };
132                 Object[] paramObj = new Object[] { objIdSent0 };
133                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
134         }
135
136         public void stop() {
137                 int methodId = 2;
138                 Class<?> retType = void.class;
139                 Class<?>[] paramCls = new Class<?>[] {  };
140                 Object[] paramObj = new Object[] {  };
141                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
142         }
143
144         public void start() {
145                 int methodId = 1;
146                 Class<?> retType = void.class;
147                 Class<?>[] paramCls = new Class<?>[] {  };
148                 Object[] paramObj = new Object[] {  };
149                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
150         }
151
152         public void init() {
153                 int methodId = 0;
154                 Class<?> retType = void.class;
155                 Class<?>[] paramCls = new Class<?>[] {  };
156                 Object[] paramObj = new Object[] {  };
157                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
158         }
159
160         public int getWeatherZipCode() {
161                 int methodId = 4;
162                 Class<?> retType = int.class;
163                 Class<?>[] paramCls = new Class<?>[] {  };
164                 Object[] paramObj = new Object[] {  };
165                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
166                 // Waiting for return value
167                 while (!retValueReceived4.get());
168                 Object retObj = rmiComm.getReturnValue(retType, null);
169                 retValueReceived4.set(false);
170                 rmiComm.setGetReturnBytes();
171
172                 return (int)retObj;
173         }
174
175 }