*
* @throws Exception
*/
@SuppressWarnings("unchecked")
public void run() throws Exception {
Request req;
Object result;
eventloop: while (!this.stop) {
req = this.sock.recvRequest();
switch (req.method) {
case "init":
final String sid = (String) req.args.get(0);
result = this.sim.init(sid, req.kwargs);
break;
case "create":
final int num = ((Number) req.args.get(0)).intValue();
final String model = (String) req.args.get(1);
result = this.sim.create(num, model, req.kwargs);
break;
case "step":
final long time = ((Number) req.args.get(0)).longValue();
final JSONObject inputs = (JSONObject) req.args.get(1);
result = this.sim.step(time, inputs);
break;
case "get_data":
final JSONObject outputs = (JSONObject) req.args.get(0);
result = this.sim.getData(outputs);
break;
case "stop":
this.stop = true;
break eventloop;
default:
throw new RuntimeException("Unkown method: " + req.method);
}
req.reply(result);
}
this.sock.close();
}