创建-删除-修改定时器
更新时间:2019-06-14
创建定时器
请参考以下代码创建规则:
Plain Text
1 // prepare parameters
2 String name = "myTimerName";
3 String description = "this is a demo timer description";
4 String mqttEndpoint = "mymqttendpoint"; // 物接入实例名
5 String destTopic = "timer_send_msg_to_this_topic";
6 String msg = "{\"info\": \"this message is sent by timer myTimerName, every 30 seconds\"}";
7 long totalExecuteTimes = 100;
8 long period = 30; // send message every 30 seconds
9 // start first time execute period seconds later
10 long beginAt = System.currentTimeMillis() / 1000 + period;
11
12 // construct the CreateIotTimerRequest
13 CreateIotTimerRequest req = new CreateIotTimerRequest();
14 req.setName(name);
15 req.setDescription(description);
16 req.setEndpointName(mqttEndpoint);
17 req.setTopic(destTopic);
18 req.setMsg(msg);
19 req.setTimes(totalExecuteTimes);
20 req.setPeriod(period);
21 req.setBeginAt(beginAt);
22
23 // invoke the creation
24 String uuid = client.create(req).getUuid();
25 // now, uuid the unique id of the timer
删除定时器
请参考以下代码删除定时器:
Plain Text
1// uuid为创建定时器返回的唯一id,请参考创建定时器代码
2client.delete(uuid);
修改定时器
修改定时器信息
请参考以下代码修改定时器:
Plain Text
1 String name = "myTimerName_new";
2 String description = "this is a demo timer description_new";
3 String mqttEndpoint = "mymqttendpoint_new"; // 物接入实例名
4 String destTopic = "timer_send_msg_to_this_topic_new";
5 String msg = "{\"info\": \"this message is sent by timer myTimerName, every 30 seconds_new\"}";
6 long totalExecuteTimes = 100 + 200;
7 long period = 30 + 30; // send message every 60 seconds
8
9 UpdateIotTimerRequest req = new UpdateIotTimerRequest();
10 req.setName(name);
11 req.setDescription(description);
12 req.setEndpointName(mqttEndpoint);
13 req.setTopic(destTopic);
14 req.setMsg(msg);
15 req.setTimes(totalExecuteTimes);
16 req.setPeriod(period);
17
18 // uuid为创建定时器返回的唯一id,请参考创建定时器代码
19 client.update(req, uuid);