1 | var eve = require('../../index');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function PlanningAgent(id) {
|
12 |
|
13 | eve.Agent.call(this, id);
|
14 |
|
15 |
|
16 | this.connect(eve.system.transports.getAll());
|
17 | }
|
18 |
|
19 |
|
20 | PlanningAgent.prototype = Object.create(eve.Agent.prototype);
|
21 | PlanningAgent.prototype.constructor = PlanningAgent;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | PlanningAgent.prototype.sayDelayedHello = function(to, delay) {
|
29 | var time = eve.system.timer.getTime();
|
30 | console.log(time.toISOString(), this.id, 'planned saying hello with delay of', delay, 'ms');
|
31 |
|
32 | var me = this;
|
33 | eve.system.timer.setTimeout(function () {
|
34 | me.send(to, 'Hello ' + to + '!').catch(function (err) {
|
35 | console.log(err)
|
36 | })
|
37 | }, delay)
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | PlanningAgent.prototype.receive = function(from, message) {
|
47 | var time = eve.system.timer.getTime();
|
48 | console.log(time.toISOString(), from, 'said:', JSON.stringify(message));
|
49 | };
|
50 |
|
51 | module.exports = PlanningAgent;
|