git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 594efad3e6f4fb8105d5f177d77ec89c2ecd2c09

use onMessage

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 7/28/2017, 2:52:06 AM
Parent: d786c03160079c850fbcb88a109ad568e573b427

Files changed

kernel.jschanged
package.jsonchanged
tests/index.jschanged
kernel.jsView
@@ -76,20 +76,18 @@
7676 this.hypervisor.scheduler.done(this.id)
7777 }
7878
7979 startup () {
80- if (this.container.startup) {
81- return this.container.startup()
82- }
80+ return this.container.onStartup()
8381 }
8482
8583 /**
8684 * run the kernels code with a given enviroment
8785 * @param {object} message - the message to run
8886 * @param {boolean} init - whether or not to run the intialization routine
8987 * @returns {Promise}
9088 */
91- async run (message, method = 'run') {
89+ async run (message, method = 'onMessage') {
9290 if (message.constructor === DeleteMessage) {
9391 this.ports._delete(message.fromName)
9492 } else {
9593 const responsePort = message.responsePort
package.jsonView
@@ -33,20 +33,19 @@
3333 "binary-search-insert": "^1.0.3",
3434 "bn.js": "^4.11.6",
3535 "chunk": "0.0.2",
3636 "ipld-graph-builder": "1.2.2",
37- "primea-abstract-container": "0.0.3",
3837 "primea-message": "0.0.1"
3938 },
4039 "devDependencies": {
40+ "primea-abstract-container": "0.0.4",
4141 "coveralls": "^2.13.1",
4242 "documentation": "^4.0.0-rc.1",
4343 "ipfs": "^0.25.0",
4444 "istanbul": "^1.1.0-alpha.1",
4545 "level-promise": "^2.1.1",
4646 "levelup": "^1.3.8",
4747 "memdown": "^1.2.4",
48- "primea-abstract-container": "0.0.2",
4948 "standard": "10.0.2",
5049 "tape": "^4.5.1"
5150 }
5251 }
tests/index.jsView
@@ -27,9 +27,9 @@
2727 '/': 'zdpuB1wc9Pb6jUzfNt4nAxAEUxB7kNhg4vbq7YLcEyBUb6iAB'
2828 }
2929
3030 class testVMContainer extends BaseContainer {
31- run (m) {
31+ onMessage (m) {
3232 t.true(m === message, 'should recive a message')
3333 }
3434 }
3535
@@ -87,15 +87,15 @@
8787 '/': 'zdpuAtVcH6MUnvt2RXnLsDXyLB3CBSQ7aydfh2ogSKGCejJCQ'
8888 }
8989
9090 class testVMContainer2 extends BaseContainer {
91- run (m) {
91+ onMessage (m) {
9292 t.true(m === message, 'should recive a message')
9393 }
9494 }
9595
9696 class testVMContainer extends BaseContainer {
97- run (m) {
97+ onMessage (m) {
9898 const [portRef1, portRef2] = this.kernel.ports.createChannel()
9999 this.kernel.createInstance('test2', this.kernel.createMessage({
100100 ports: [portRef2]
101101 }))
@@ -133,9 +133,9 @@
133133 }
134134 let hasResolved = false
135135
136136 class testVMContainer2 extends BaseContainer {
137- run (m) {
137+ onMessage (m) {
138138 t.true(m === message, 'should recive a message')
139139 return new Promise((resolve, reject) => {
140140 setTimeout(() => {
141141 this.kernel.incrementTicks(1)
@@ -146,9 +146,9 @@
146146 }
147147 }
148148
149149 class testVMContainer extends BaseContainer {
150- run (m) {
150+ onMessage (m) {
151151 const [portRef1, portRef2] = this.kernel.ports.createChannel()
152152 this.kernel.createInstance('test2', this.kernel.createMessage({
153153 ports: [portRef2]
154154 }))
@@ -178,9 +178,9 @@
178178 t.deepEquals(stateRoot, expectedState, 'expected state')
179179
180180 // test reviving the state
181181 class testVMContainer3 extends BaseContainer {
182- run (m) {
182+ onMessage (m) {
183183 const port = this.kernel.ports.get('child')
184184 this.kernel.send(port, m)
185185 this.kernel.incrementTicks(1)
186186 }
@@ -194,9 +194,9 @@
194194
195195 tape('traps', async t => {
196196 t.plan(1)
197197 class Root extends BaseContainer {
198- async run (m) {
198+ async onMessage (m) {
199199 const [portRef1, portRef2] = this.kernel.ports.createChannel()
200200 const [portRef3, portRef4] = this.kernel.ports.createChannel()
201201 const [portRef5, portRef6] = this.kernel.ports.createChannel()
202202
@@ -238,9 +238,9 @@
238238 t.plan(2)
239239 let runs = 0
240240
241241 class Root extends BaseContainer {
242- run (m) {
242+ onMessage (m) {
243243 if (!runs) {
244244 runs++
245245
246246 const [portRef1, portRef2] = this.kernel.ports.createChannel()
@@ -270,18 +270,18 @@
270270 }
271271 }
272272
273273 class First extends BaseContainer {
274- run (m) {
274+ onMessage (m) {
275275 this.kernel.incrementTicks(2)
276276 this.kernel.send(m.fromPort, this.kernel.createMessage({
277277 data: 'first'
278278 }))
279279 }
280280 }
281281
282282 class Second extends BaseContainer {
283- run (m) {
283+ onMessage (m) {
284284 this.kernel.incrementTicks(3)
285285 this.kernel.send(m.fromPort, this.kernel.createMessage({
286286 data: 'second'
287287 }))
@@ -310,9 +310,9 @@
310310 t.plan(2)
311311 let runs = 0
312312
313313 class Root extends BaseContainer {
314- run (m) {
314+ onMessage (m) {
315315 if (!runs) {
316316 runs++
317317
318318 const [portRef1, portRef2] = this.kernel.ports.createChannel()
@@ -342,18 +342,18 @@
342342 }
343343 }
344344
345345 class First extends BaseContainer {
346- run (m) {
346+ onMessage (m) {
347347 this.kernel.incrementTicks(2)
348348 this.kernel.send(m.fromPort, this.kernel.createMessage({
349349 data: 'first'
350350 }))
351351 }
352352 }
353353
354354 class Second extends BaseContainer {
355- run (m) {
355+ onMessage (m) {
356356 this.kernel.incrementTicks(1)
357357 this.kernel.send(m.fromPort, this.kernel.createMessage({
358358 data: 'second'
359359 }))
@@ -382,9 +382,9 @@
382382 t.plan(2)
383383 let runs = 0
384384
385385 class Root extends BaseContainer {
386- run (m) {
386+ onMessage (m) {
387387 if (!runs) {
388388 runs++
389389 const [portRef1, portRef2] = this.kernel.ports.createChannel()
390390 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -415,18 +415,18 @@
415415 }
416416 }
417417
418418 class First extends BaseContainer {
419- run (m) {
419+ onMessage (m) {
420420 this.kernel.incrementTicks(1)
421421 this.kernel.send(m.fromPort, this.kernel.createMessage({
422422 data: 'first'
423423 }))
424424 }
425425 }
426426
427427 class Second extends BaseContainer {
428- run (m) {
428+ onMessage (m) {
429429 this.kernel.incrementTicks(2)
430430 this.kernel.send(m.fromPort, this.kernel.createMessage({
431431 data: 'second'
432432 }))
@@ -454,9 +454,9 @@
454454 t.plan(2)
455455 let runs = 0
456456
457457 class Root extends BaseContainer {
458- run (m) {
458+ onMessage (m) {
459459 if (!runs) {
460460 runs++
461461 const [portRef1, portRef2] = this.kernel.ports.createChannel()
462462 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -488,18 +488,18 @@
488488 }
489489 }
490490
491491 class First extends BaseContainer {
492- run (m) {
492+ onMessage (m) {
493493 this.kernel.incrementTicks(2)
494494 this.kernel.send(m.fromPort, this.kernel.createMessage({
495495 data: 'first'
496496 }))
497497 }
498498 }
499499
500500 class Second extends BaseContainer {
501- run (m) {
501+ onMessage (m) {
502502 this.kernel.incrementTicks(3)
503503 this.kernel.send(m.fromPort, this.kernel.createMessage({
504504 data: 'second'
505505 }))
@@ -549,9 +549,9 @@
549549
550550 let runs = 0
551551
552552 class Root extends BaseContainer {
553- run (m) {
553+ onMessage (m) {
554554 if (!runs) {
555555 runs++
556556 const [portRef1, portRef2] = this.kernel.ports.createChannel()
557557 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -582,18 +582,18 @@
582582 }
583583 }
584584
585585 class First extends BaseContainer {
586- run (m) {
586+ onMessage (m) {
587587 this.kernel.incrementTicks(2)
588588 this.kernel.send(m.fromPort, this.kernel.createMessage({
589589 data: 'first'
590590 }))
591591 }
592592 }
593593
594594 class Second extends BaseContainer {
595- run (m) {
595+ onMessage (m) {
596596 this.kernel.incrementTicks(2)
597597 this.kernel.send(m.fromPort, this.kernel.createMessage({
598598 data: 'second'
599599 }))
@@ -622,9 +622,9 @@
622622
623623 let runs = 0
624624
625625 class Root extends BaseContainer {
626- run (m) {
626+ onMessage (m) {
627627 if (!runs) {
628628 runs++
629629 const [portRef1, portRef2] = this.kernel.ports.createChannel()
630630 const [portRef3, portRef4] = this.kernel.ports.createChannel()
@@ -655,18 +655,18 @@
655655 }
656656 }
657657
658658 class First extends BaseContainer {
659- run (m) {
659+ onMessage (m) {
660660 this.kernel.incrementTicks(2)
661661 this.kernel.send(m.fromPort, this.kernel.createMessage({
662662 data: 'first'
663663 }))
664664 }
665665 }
666666
667667 class Second extends BaseContainer {
668- run (m) {
668+ onMessage (m) {
669669 this.kernel.incrementTicks(2)
670670 this.kernel.send(m.fromPort, this.kernel.createMessage({
671671 data: 'second'
672672 }))
@@ -696,9 +696,9 @@
696696 let runs = 0
697697 let instance
698698
699699 class Root extends BaseContainer {
700- run (m) {
700+ onMessage (m) {
701701 let one = this.kernel.ports.get('one')
702702 if (!one) {
703703 const [portRef1, portRef2] = this.kernel.ports.createChannel()
704704 this.kernel.ports.bind('one', portRef1)
@@ -713,9 +713,9 @@
713713 }
714714 }
715715
716716 class First extends BaseContainer {
717- run (m) {
717+ onMessage (m) {
718718 ++runs
719719 if (runs === 2) {
720720 t.equals(instance, this, 'should have same instances')
721721 } else {
@@ -789,9 +789,9 @@
789789 const expectedSr = {
790790 '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
791791 }
792792 class Root extends BaseContainer {
793- run (m) {
793+ onMessage (m) {
794794 const [portRef1, portRef2] = this.kernel.ports.createChannel()
795795 this.kernel.ports.bind('one', portRef1)
796796 const message1 = this.kernel.createMessage({
797797 ports: [portRef2]
@@ -803,9 +803,9 @@
803803 }
804804 }
805805
806806 class First extends BaseContainer {
807- run (m) {
807+ onMessage (m) {
808808 this.kernel.incrementTicks(2)
809809 this.kernel.ports.delete('root')
810810 }
811811 }
@@ -835,9 +835,9 @@
835835 const expectedSr = {
836836 '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
837837 }
838838 class Root extends BaseContainer {
839- run (m) {
839+ onMessage (m) {
840840 this.kernel.createInstance('root')
841841 }
842842 }
843843
@@ -864,9 +864,9 @@
864864 const expectedSr = {
865865 '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
866866 }
867867 class Root extends BaseContainer {
868- run (m) {
868+ onMessage (m) {
869869 const [, portRef2] = this.kernel.ports.createChannel()
870870 this.kernel.createInstance('sub', this.kernel.createMessage({
871871 ports: [portRef2]
872872 }))
@@ -907,9 +907,9 @@
907907 const expectedSr = {
908908 '/': 'zdpuAwsZTd5mRZBCYA1FJSHrpYDPgSZSiaTQp9xkUeajaoMHM'
909909 }
910910 class Root extends BaseContainer {
911- run (m) {
911+ onMessage (m) {
912912 if (m.ports.length) {
913913 const port = this.kernel.ports.get('test1')
914914 this.kernel.send(port, m)
915915 this.kernel.ports.unbind('test1')
@@ -932,9 +932,9 @@
932932 }
933933 }
934934
935935 class Sub extends BaseContainer {
936- run (message) {
936+ onMessage (message) {
937937 if (message.data === 'getChannel') {
938938 const ports = this.kernel.ports.createChannel()
939939 this.kernel.ports.bind('channel', ports[0])
940940 this.kernel.send(message.fromPort, this.kernel.createMessage({
@@ -971,9 +971,9 @@
971971 const expectedSr = {
972972 '/': 'zdpuAmi9tkYTpoVsZvqQgxpQFRhCgYFVv4W3fjjfVhf1j8swv'
973973 }
974974 class Root extends BaseContainer {
975- run (m) {
975+ onMessage (m) {
976976 if (m.ports.length) {
977977 const port = this.kernel.ports.get('test1')
978978 this.kernel.send(port, m)
979979 this.kernel.ports.unbind('test1')
@@ -997,9 +997,9 @@
997997 }
998998 }
999999
10001000 class Sub extends BaseContainer {
1001- run (message) {
1001+ onMessage (message) {
10021002 if (message.data === 'getChannel') {
10031003 const ports = this.kernel.ports.createChannel()
10041004 this.kernel.ports.bind('channel', ports[0])
10051005 this.kernel.send(message.fromPort, this.kernel.createMessage({
@@ -1038,9 +1038,9 @@
10381038 let runs = 0
10391039 const returnValue = 'this is a test'
10401040
10411041 class testVMContainer extends BaseContainer {
1042- run (m) {
1042+ onMessage (m) {
10431043 runs++
10441044 if (runs === 1) {
10451045 return returnValue
10461046 } else {
@@ -1075,10 +1075,10 @@
10751075
10761076 tape('start up', async t => {
10771077 t.plan(1)
10781078 class testVMContainer extends BaseContainer {
1079- run () {}
1080- startup () {
1079+ onMessage () {}
1080+ onStartup () {
10811081 t.true(true, 'should start up')
10821082 }
10831083 }
10841084
@@ -1091,9 +1091,9 @@
10911091 tape('large code size', async t => {
10921092 t.plan(1)
10931093 const content = Buffer.from(new ArrayBuffer(1000000))
10941094 class testVMContainer extends BaseContainer {
1095- run () {}
1095+ onMessage () {}
10961096 }
10971097
10981098 const hypervisor = new Hypervisor(node.dag)
10991099 hypervisor.registerContainer('test', testVMContainer)

Built with git-ssb-web