From d4e77a58ddf0dc143e14f50ab9fa81ea2de73e84 Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:16:01 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-jamsh1.js | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/test-jamsh1.js diff --git a/test/test-jamsh1.js b/test/test-jamsh1.js new file mode 100644 index 0000000..199d20a --- /dev/null +++ b/test/test-jamsh1.js @@ -0,0 +1,51 @@ +// Simple jamsh test demonstrating lifetime resource control and negotiation +// with capabilities + +// Ports for node negotiation +var port = Port.unique() +var rand = Port.unique(); + +function hello(cap) { + this.cap=cap; + this.act = { + init: function () { + log('START'); + // negotiate more lifetime (default is 2000) + log(negotiate('LIFE',10000,this.cap)) + // if negotiation was successful, we can sleep in peace, else.. + sleep(5000) + }, + stop: function () { log('STOP'); kill() } + } + this.trans = { + init:"stop" + } + this.on = { + error: function (e,arg) { log('Error: '+e) }, + } + this.next="init" +} +var security = {} +security[Port.toString(port)]=Port.toString(rand); + +// default platform settings +config({ + IDLETIME:1000, + LIFETIME:2000, + // remember the private ports for node negotiation + security :security, + verbose:3, +}) + +compile(hello,{verbose:1}) +start() + +// Capability for lifetime negotation of the agent +var cap = Capability(port,Private.encode(0,Rights.NEG_LIFE,rand)) +print(Capability.toString(cap)) +var id1=create(hello,cap) +var id2=create(hello) +later(500,function () { + print(info('agent',id1).resources) + print(info('agent',id2).resources) +})