git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 16503279a2722f474cd5b0d92906f32e9da38577

simplifed getting instances

wanderer committed on 5/15/2017, 3:15:41 PM
Parent: 993a67d6ed59227e98922bba72cc4bd827f37964

Files changed

index.jschanged
kernel.jschanged
portManager.jschanged
index.jsView
@@ -8,19 +8,16 @@
88 this._vmInstances = new Map()
99 this._VMs = {}
1010 }
1111
12- async getInstance (port, createIfNotFound = true) {
12+ async getInstance (port, createIfNotFound, parentPort) {
1313 const id = await this.generateID(port)
1414 let kernel = this._vmInstances.get(id)
1515 if (!kernel && createIfNotFound) {
1616 // load the the ID from the merkle store
1717 await this.graph.tree(port.id, 1)
18- const parentID = await this.generateID({id: port.id['/'].parent})
19- const parentKernel = await this._vmInstances.get(parentID)
20- const parentPort = parentKernel.entryPort
2118
22- kernel = await this.createInstanceFromPort(port, parentPort)
19+ kernel = await this.createInstance(port.type, port.link, port, parentPort)
2320 kernel.on('idle', () => {
2421 this._vmInstances.delete(id)
2522 })
2623 }
@@ -62,17 +59,8 @@
6259 await kernel.start()
6360 return kernel
6461 }
6562
66- /**
67- * opts.entryPort
68- * opts.parentPort
69- */
70- async createInstanceFromPort (entryPort, parentPort) {
71- const state = entryPort.link
72- return this.createInstance(entryPort.type, state, entryPort, parentPort)
73- }
74-
7563 async createStateRoot (container, ticks) {
7664 await container.wait(ticks)
7765 return this.graph.flush(container.state)
7866 }
kernel.jsView
@@ -118,9 +118,9 @@
118118 async send (portRef, message) {
119119 message._fromPort = this.entryPort
120120 message._fromPortTicks = this.ticks
121121
122- const vm = await this.hypervisor.getInstance(portRef)
122+ const vm = await this.hypervisor.getInstance(portRef, true, this.entryPort)
123123 vm.queue(message)
124124
125125 const waiter = this._waitingMap.get(portRef)
126126 if (waiter) {
portManager.jsView
@@ -20,8 +20,10 @@
2020 } else if (a.priority !== b.priority) {
2121 // decide by priority
2222 return a.priority > b.priority ? pairA : pairB
2323 } else if (portA.name === ENTRY) {
24+ // pairB can never be the entry port since the port map is odered by
25+ // insertion order
2426 return pairA
2527 } else {
2628 return portA.name < portB.name ? pairA : pairB
2729 }
@@ -56,9 +58,9 @@
5658 }
5759
5860 set (name, port) {
5961 this.ports[name] = port
60- return this._mapPort(name, port)
62+ this._mapPort(name, port)
6163 }
6264
6365 get (key) {
6466 return this.ports[key]

Built with git-ssb-web