git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 3a2129ef21fb40c0212b10d052749c0437d93ffc

remove opts

wanderer committed on 4/29/2017, 4:31:32 PM
Parent: 4a1f9a53b0854ec031013d473ac2f51e826d4dc5

Files changed

index.jschanged
kernel.jschanged
portManager.jschanged
index.jsView
@@ -9,17 +9,12 @@
99 }
1010
1111 module.exports = class Hypervisor {
1212 constructor (opts) {
13- this._opts = {
14- VMs: {}
15- }
16-
1713 this.graph = new Graph(opts.dag)
18- delete opts.dag
1914 this.root = new Root()
2015 this._vmInstances = new Map([[null, new Root()]])
21- Object.assign(this._opts, opts)
16+ this._VMs = {}
2217 }
2318
2419 async getInstance (port) {
2520 let id = await this.generateID(port)
@@ -28,12 +23,13 @@
2823 // load the container from the state
2924 await this.graph.tree(port, 2)
3025
3126 // create a new kernel instance
32- const VM = this._opts.VMs[port.type]
27+ const VM = this._VMs[port.type]
3328
3429 kernel = new Kernel({
3530 parentPort: port,
31+ state: port.link['/'],
3632 hypervisor: this,
3733 VM: VM
3834 })
3935
@@ -60,9 +56,9 @@
6056 return kernel.wait(threshold)
6157 }
6258
6359 createPort (type, id = {nonce: [0], parent: null}) {
64- const VM = this._opts.VMs[type]
60+ const VM = this._VMs[type]
6561 return {
6662 'messages': [],
6763 'id': {
6864 '/': id
@@ -93,7 +89,7 @@
9389 return id
9490 }
9591
9692 addVM (type, vm) {
97- this._opts.VMs[type] = vm
93+ this._VMs[type] = vm
9894 }
9995 }
kernel.jsView
@@ -5,13 +5,21 @@
55
66 module.exports = class Kernel extends EventEmitter {
77 constructor (opts) {
88 super()
9- this._opts = opts
10- this.state = opts.parentPort.link['/']
9+ this.state = opts.state
10+ this.parentPort = opts.parentPort
11+ this.hypervisor = opts.hypervisor
12+
1113 this.vmState = 'idle'
1214 this.ticks = 0
13- this.ports = new PortManager(this)
15+ // create the port manager
16+ this.ports = new PortManager({
17+ kernel: this,
18+ hypervisor: opts.hypervisor,
19+ ports: opts.state.ports,
20+ parentPort: opts.parentPort
21+ })
1422 this.vm = new opts.VM(this)
1523 this._waitingQueue = new PriorityQueue((a, b) => {
1624 return a.threshold > b.threshold
1725 })
@@ -56,19 +64,19 @@
5664 * to by the VM to retrive infromation from the Environment.
5765 */
5866 async _run (message) {
5967 // shallow copy
60- const oldState = Object.assign({}, this._opts.state)
68+ const oldState = Object.assign({}, this.state)
6169 let result
6270 try {
6371 result = await this.vm.run(message) || {}
6472 } catch (e) {
6573 result = {
6674 exception: true,
6775 exceptionError: e
6876 }
69- clearObject(this._opts.state)
70- Object.assign(this._opts.state, oldState)
77+ clearObject(this.state)
78+ Object.assign(this.state, oldState)
7179 }
7280
7381 this.emit('result', result)
7482 return result
@@ -106,11 +114,11 @@
106114 const nonce = new BN(this.state.nonce)
107115 nonce.iaddn(1)
108116 this.state.nonce = nonce.toArray()
109117
110- let portRef = this._opts.hypervisor.createPort(type, {
118+ let portRef = this.hypervisor.createPort(type, {
111119 nonce: this.state.nonce,
112- parent: this._opts.parentPort.id
120+ parent: this.parentPort.id
113121 })
114122 await manager.set(name, portRef)
115123 return portRef
116124 }
@@ -122,9 +130,9 @@
122130 async send (portRef, message) {
123131 message._ticks = this.ticks
124132 const portInstance = await this.ports.get(portRef)
125133 portInstance.hasSent = true
126- return this._opts.hypervisor.send(portRef, message)
134+ return this.hypervisor.send(portRef, message)
127135 }
128136 }
129137
130138 function clearObject (myObject) {
portManager.jsView
@@ -23,13 +23,10 @@
2323 }
2424 }
2525
2626 module.exports = class PortManager {
27- constructor (kernel) {
28- this.kernel = kernel
29- this.hypervisor = kernel._opts.hypervisor
30- this.ports = kernel.state.ports
31- this.parentPort = kernel._opts.parentPort
27+ constructor (opts) {
28+ Object.assign(this, opts)
3229 this.parentId = {
3330 id: this.parentPort.id['/'].parent
3431 }
3532 this._portMap = new Map()

Built with git-ssb-web