-
Notifications
You must be signed in to change notification settings - Fork 46
/
events.sarl
536 lines (473 loc) · 15.3 KB
/
events.sarl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.core
import java.util.Arrays
import java.util.Collection
import java.util.Collections
import java.util.UUID
import io.sarl.lang.^annotation.EarlyExit
import io.sarl.lang.core.SpaceID
import io.sarl.lang.core.Address
import io.sarl.util.Collections3;
/**
* Initialization event.
* The source of this event is the agent itself.
*
* <h4>For an Agent</h4>
* This event is received by the agent's native behavior when the agent is spawned.
*
* <h4>For a Behavior</h4>
* Each Behavior instance within the agent receives this event when it is registered for the first time.
*
* <h4>For a Skill</h4>
* No skill receives this event.
*
* <h4>For Agent Members</h4>
* The member agents do not receive this event from the parent agent because they are not yet created when the agent is spawned.
*
* @author $Author: srodriguez$
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event Initialize {
/** The initialization parameters.
* Usually, they are the arguments passed to the agent spawning function.
*/
val parameters : Object[]
/** Identifier of the agent, which has spawned the under-initialization agent.
* If the under-initialization agent was spawned by the SARL run-time environment
* (and not by another agent), the identifier is {@code null}.
*
* @since 0.5
*/
val spawner : UUID
/** Constructor.
*
* @param spawner the identifier of the spawner of the under-initialization agent.
* @param params the initialization parameters to give to the under-initialization agent.
* @since 0.5
*/
new(spawner : UUID, params : Object*) {
this(null, spawner, params)
}
/** Constructor.
*
* @param source address of the agent that is emitting this event.
* @param spawner the identifier of the spawner of the under-initialization agent.
* @param params the initialization parameters to give to the under-initialization agent.
* @since 0.5
*/
new(source : Address, spawner : UUID, params : Object*) {
super(source)
this.spawner = spawner
this.parameters = params
}
}
/**
* Notifies the destruction of an element.
* The source of this event is the agent itself.
* This event is marked as an early exit event. It means that any action that is firing this
* event is supposed to never return, e.g. the <code>killMe</code> action.
*
* <h4>For an Agent</h4>
* This event is received by the agent's native behavior when the agent is destroyed, usually after
* a call to {@code killMe}.
* All the agent behaviors of the agent are unregistered prior to the firing of this events.
* All the agent tasks are canceled prior to the firing of this events.
* Agent skills are uninstalled after the {@code Destroy} event handler is ran.
*
* <h4>For a Behavior</h4>
* Each Behavior instance within the agent receives this event when it is unregistered for the last time.
*
* <h4>For a Skill</h4>
* No skill receives this event, except if you have registered the skill as an event listener on the
* agent internal event bus. In the last case, the skill will receive the {@code Destroy} event because
* is will be uninstalled after its firing.
*
* <h4>For Agent Members</h4>
* The member agents do not receive this event from the parent agent because the parent agent cannot be
* destroyed if it has agent members.
*
* @author $Author: srodriguez$
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@EarlyExit
final event Destroy
/**
* Informs the creation of a new agent in a spawning context.
* The event is fired within the default space of the spawning context, i.e. the context in which the agent was created.
* The spawned agent does not receive this event.
* The source of the event is the spawning agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event AgentSpawned {
/** Identifier of the spawned agent.
* It is the first identifier in {@link #agentIdentifiers}.
*
* @deprecated since 0.5, See {@link #agentIdentifiers}.
*/
@Deprecated
val agentID : UUID
/** Identifiers of the spawned agents.
* @since 0.5
*/
val agentIdentifiers : Collection<UUID>
/** Fully qualifiedname of the type of the agent.
*/
val agentType : String
/** Constuct the event.
*
* @param source the address of the emitter.
* @param agentID : the identifier of the spawned agent.
* @param agentType fully qualified name of the type of the agent.
* @deprecated
*/
@Deprecated
new (source : Address, agentID : UUID, agentType : String) {
setSource(source)
this.agentIdentifiers = Collections::singleton(agentID)
this.agentID = agentID
this.agentType = agentType
}
/** Constuct the event.
*
* @param source the address of the emitter.
* @param agentType fully qualified name of the type of the agent.
* @param agentID : the identifiers of the spawned agents.
*/
new (source : Address, agentType : String, agentID : UUID*) {
setSource(source)
this.agentIdentifiers = Collections::unmodifiableCollection(Arrays::asList(agentID))
this.agentID = agentID.get(0)
this.agentType = agentType
}
/** Constuct the event.
*
* @param source the address of the emitter.
* @param agentType fully qualified name of the type of the agent.
* @param agentID : the identifiers of the spawned agents.
*/
new (source : Address, agentType : String, agentID : Collection<UUID>) {
setSource(source)
this.agentIdentifiers = Collections::unmodifiableCollection(Collections3::serializableCollection(agentID))
this.agentID = agentID.iterator.next
this.agentType = agentType
}
}
/**
* Informs an agent has been killed.
* The event is fires within all the external contexts (including the default context) of the killed agent.
* The killed agent does not receive this event.
* The source of the event is the killed agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event AgentKilled {
/** The identifier of the killed agent.
* @deprecated since 0.7, See the event source.
*/
@Deprecated
val agentID : UUID
/** The fully qualified name of the type of the killed agent.
*/
val agentType : String
/** Construct the event.
*
* @param source the address of the emitter.
* @param agentID the identifier of the killed agent.
* @param agentType fully qualified name of the type of the agent.
*/
new (source : Address, agentID : UUID, agentType : String) {
setSource(source)
this.agentID = agentID
this.agentType = agentType
}
}
/**
* Informs the creation of a new space in a given context.
* The event is fired within the default space of the context in which the space was created.
* The source of the event is the parent agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event SpaceCreated {
/** Identifier of the created space.
*/
val spaceID : SpaceID
/** Construct the event.
*
* @param source the address of the emitter.
* @param spaceID the identifier of the space.
*/
new (source : Address, spaceID : SpaceID) {
setSource(source)
this.spaceID = spaceID
}
}
/** Informs the destruction of a space in a given context.
* The event is fired within the default space of the context from which the space was removed.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
* The source of the event is the parent agent.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event SpaceDestroyed {
/** The identifier of the destroyed space.
*/
val spaceID : SpaceID
/** Construct the event.
*
* @param source the address of the emitter.
* @param spaceID the identifier of the space.
*/
new (source : Address, spaceID : SpaceID) {
setSource(source)
this.spaceID = spaceID
}
}
/** Notifies other members the member with agentID has effectively
* integrated the holon context.
* The event is fired within the default space of the context in which the new agent entered.
* The joining agent does not receive this event.
* The source of the event is the parent agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event MemberJoined {
/** The identifier of the context that the member joined.
* @deprecated See the event source
*/
@Deprecated
val parentContextID : UUID
/** The identifier of the agent that has joined the context.
*/
val agentID : UUID
/** The fully qualified name of the type of the agent.
*/
val agentType : String
/** Construct the event.
*
* @param source the address of the emitter.
* @param contextID the identifier of the context.
* @param agentID the identifier of the agent.
* @param agentType fully qualified name of the type of the agent.
*/
new (source : Address, contextID : UUID, agentID : UUID, agentType : String) {
setSource(source)
this.parentContextID = contextID
this.agentID = agentID
this.agentType = agentType
}
}
/** Notifies other members the member with agentID was
* excluded (forced to leave) the holon context parentContextID.
* The event is fired within the default space of the context from which the agent was excluded.
* The excluded agent does not receive this event.
* The source of the event is the parent agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event MemberExcluded {
/** The identifier of the context from which the member was excluded.
* @deprecated See source
*/
@Deprecated
val parentContextID : UUID
/** The identifier of the agent that was excluded from the context.
*/
val agentID : UUID
/** The fully qualified name of the type of the agent.
*/
val agentType : String
/** Construct the event.
*
* @param source the address of the emitter.
* @param contextID the identifier of the context.
* @param agentID the identifier of the agent.
* @param agentType fully qualified name of the type of the agent.
*/
new (source : Address, contextID : UUID, agentID : UUID, agentType : String) {
setSource(source)
this.parentContextID = contextID
this.agentID = agentID
this.agentType = agentType
}
}
/** Notifies other members the member with agentID has left the holon context.
* The event is fired within the default space of the context from which the agent has left.
* The left agent does not receive this event.
* The source of the event is the parent agent.
* The context id can be retrieved via {@code ev.source.spaceID.contextID}.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event MemberLeft {
/** The identifier of the agent that has left the holon context.
*/
val agentID : UUID
/** The fully qualified name of the type of the agent.
*/
val agentType : String
/** Construct the event.
*
* @param source the address of the emitter.
* @param agentID the identifier of the agent.
* @param agentType fully qualified name of the type of the agent.
*/
new (source : Address, agentID : UUID, agentType : String) {
setSource(source)
this.agentID = agentID
this.agentType = agentType
}
}
/** Notifies behaviors the agent has joined a new super-holon.
* The event is fired within the internal bus of the agent that have joined a super-holon.
* The source of the event is the agent itself.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event ContextJoined {
/** The identifier of the context in the super-holon.
*/
val holonContextID : UUID
/** The identifier of the default space in the super-holon context.
*/
val defaultSpaceID : UUID
/** Construct the event.
*
* @param contextID the identifier of the context.
* @param defaultSpaceID the identifier of the default space.
*/
new (contextID : UUID, defaultSpaceID : UUID) {
this.holonContextID = contextID
this.defaultSpaceID = defaultSpaceID
}
}
/**
* Notifies behaviors the agent has left a super-holon.
* The event is fired within the internal bus of the agent that have left a super-holon.
* The source of the event is the agent itself.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
final event ContextLeft {
/** The identifier of the context in the super-holon.
*/
val holonContextID : UUID
/** Construct the event.
*
* @param contextID the identifier of the context.
*/
new (contextID : UUID) {
this.holonContextID = contextID
}
}
/** Notifies other participants that a member has effectively
* integrated the space.
* The event is fired within the default space of the context in which the agent entered a new space.
* The joining agent does not receive this event.
* The source of the event is the entering agent.
*
* @author $Author: ngaud$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.10
*/
final event ParticipantJoined {
/** The identifier of the space in which the agent is entering.
*/
val spaceID : SpaceID
/** Construct the event.
*
* @param source the address of the emitter.
* @param spaceID the identifier of the space.
*/
new (source : Address, spaceID : SpaceID) {
this.source = source
this.spaceID = spaceID
}
}
/** Notifies other participants the member with agentID has effectively
* left the space.
* The event is fired within the default space of the context in which the agent left the space.
* The leaving agent does not receive this event.
* The source of the event is the leaving agent.
*
* @author $Author: ngaud$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.10
*/
final event ParticipantLeft {
/** The identifier of the space the agent just left.
*/
val spaceID : SpaceID
/** Construct the event.
*
* @param source the address of the emitter.
* @param spaceID the identifier of the space.
*/
new (source : Address, spaceID : SpaceID) {
this.source = source
this.spaceID = spaceID
}
}