agent CarFactoryAgent { on Initialize { println("Car factory is initialized.") } def spawnAssemblyLineAgents(num: int) { for (i: int in 1..num) { spawn AssemblyLineAgent("AssemblyLineAgent" + i.toString()) } } } agent AssemblyLineAgent { val assemblyLineId: string new(id: string) { this.assemblyLineId = id } on Initialize { println("Assembly line $assemblyLineId is initialized.") startProductionProcess() } def startProductionProcess() { println("Assembly line $assemblyLineId starts production process.") } } agent MainAgent { on Initialize { spawn CarFactoryAgent } } agent EventHandlerAgent { on CustomEvent { println("Custom event received: " + occurrence.payload) } } agent TriggerAgent { on Initialize { val event = new CustomEvent("Hello SARL!") emit(event) } } agent MainAgent { on Initialize { spawn EventHandlerAgent spawn TriggerAgent } } plugins { id 'java' id 'application' id 'sarleclipse' } repositories { mavenCentral() } dependencies { implementation 'io.janusproject:janusproject-kernel:2.14.0' sarl 'io.janusproject:janusproject-maven:2.14.0' } sourceSets { main { sarl { srcDir 'src/main/sarl' outputDir 'build/classes/sarl' } } }


上一篇:
下一篇:
切换中文