Commit 16503279a2722f474cd5b0d92906f32e9da38577
simplifed getting instances
wanderer committed on 5/15/2017, 3:15:41 PMParent: 993a67d6ed59227e98922bba72cc4bd827f37964
Files changed
index.js | changed |
kernel.js | changed |
portManager.js | changed |
index.js | ||
---|---|---|
@@ -8,19 +8,16 @@ | ||
8 | 8 | this._vmInstances = new Map() |
9 | 9 | this._VMs = {} |
10 | 10 | } |
11 | 11 | |
12 | - async getInstance (port, createIfNotFound = true) { | |
12 | + async getInstance (port, createIfNotFound, parentPort) { | |
13 | 13 | const id = await this.generateID(port) |
14 | 14 | let kernel = this._vmInstances.get(id) |
15 | 15 | if (!kernel && createIfNotFound) { |
16 | 16 | // load the the ID from the merkle store |
17 | 17 | 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 | |
21 | 18 | |
22 | - kernel = await this.createInstanceFromPort(port, parentPort) | |
19 | + kernel = await this.createInstance(port.type, port.link, port, parentPort) | |
23 | 20 | kernel.on('idle', () => { |
24 | 21 | this._vmInstances.delete(id) |
25 | 22 | }) |
26 | 23 | } |
@@ -62,17 +59,8 @@ | ||
62 | 59 | await kernel.start() |
63 | 60 | return kernel |
64 | 61 | } |
65 | 62 | |
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 | - | |
75 | 63 | async createStateRoot (container, ticks) { |
76 | 64 | await container.wait(ticks) |
77 | 65 | return this.graph.flush(container.state) |
78 | 66 | } |
kernel.js | ||
---|---|---|
@@ -118,9 +118,9 @@ | ||
118 | 118 | async send (portRef, message) { |
119 | 119 | message._fromPort = this.entryPort |
120 | 120 | message._fromPortTicks = this.ticks |
121 | 121 | |
122 | - const vm = await this.hypervisor.getInstance(portRef) | |
122 | + const vm = await this.hypervisor.getInstance(portRef, true, this.entryPort) | |
123 | 123 | vm.queue(message) |
124 | 124 | |
125 | 125 | const waiter = this._waitingMap.get(portRef) |
126 | 126 | if (waiter) { |
portManager.js | ||
---|---|---|
@@ -20,8 +20,10 @@ | ||
20 | 20 | } else if (a.priority !== b.priority) { |
21 | 21 | // decide by priority |
22 | 22 | return a.priority > b.priority ? pairA : pairB |
23 | 23 | } else if (portA.name === ENTRY) { |
24 | + // pairB can never be the entry port since the port map is odered by | |
25 | + // insertion order | |
24 | 26 | return pairA |
25 | 27 | } else { |
26 | 28 | return portA.name < portB.name ? pairA : pairB |
27 | 29 | } |
@@ -56,9 +58,9 @@ | ||
56 | 58 | } |
57 | 59 | |
58 | 60 | set (name, port) { |
59 | 61 | this.ports[name] = port |
60 | - return this._mapPort(name, port) | |
62 | + this._mapPort(name, port) | |
61 | 63 | } |
62 | 64 | |
63 | 65 | get (key) { |
64 | 66 | return this.ports[key] |
Built with git-ssb-web