git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 455f5db59297ab334a58c1589e8743cebdab3817

add caps manager

wanderer committed on 11/21/2017, 7:49:30 PM
Parent: fe85db02d3b6f1a6ef9490d75086d13614896ba4

Files changed

README.mdchanged
index.jschanged
scheduler.jschanged
capsManager.jsadded
README.mdView
@@ -19,5 +19,7 @@
1919 # API
2020 [./docs](./docs/index.md)
2121
2222 # LICENSE
23-[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))
23+[MPL-2.0][LICENSE]
24+
25+[LICENSE]: https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)
index.jsView
@@ -4,18 +4,23 @@
44 module.exports = class Hypervisor {
55 /**
66 * The Hypervisor manages the container instances by instantiating them and
77 * destorying them when possible. It also facilitates localating Containers
8- * @param {Graph} dag an instance of [ipfs.dag](https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag#dag-api)
9- * @param {object} state - the starting state
8+ * @param {Tree} tree - a [radix tree](https://github.com/dfinity/js-dfinity-radix-tree) to store the state
109 */
1110 constructor (tree) {
1211 this.tree = tree
1312 this.scheduler = new Scheduler()
1413 this._containerTypes = {}
1514 this.nonce = 0
1615 }
1716
17+ /**
18+ * sends a message
19+ * @param {Object} cap - the capabilitly used to send the message
20+ * @param {Object} message - the [message](https://github.com/primea/js-primea-message) to send
21+ * @returns {Promise} a promise that resolves once the receiving container is loaded
22+ */
1823 async send (cap, message) {
1924 const id = cap.destId
2025 const instance = await this.getInstance(id)
2126 instance.queue(message)
@@ -58,8 +63,14 @@
5863 return instance
5964 }
6065 }
6166
67+ /**
68+ * creates an instance of a container
69+ * @param {Integer} type - the type id for the container
70+ * @param {Object} message - an intial [message](https://github.com/primea/js-primea-message) to send newly created instance
71+ * @param {Object} id - the id for the instance
72+ */
6273 async createInstance (type, message, id = {nonce: this.nonce, parent: null}) {
6374 const encoded = encodedID(id)
6475 this.nonce++
6576 const idHash = await this._getHashFromObj(encoded)
@@ -104,9 +115,9 @@
104115 /**
105116 * regirsters a container with the hypervisor
106117 * @param {Class} Constructor - a Class for instantiating the container
107118 * @param {*} args - any args that the contructor takes
108- * @param {interger} typeId - the container's type identification ID
119+ * @param {Interger} typeId - the container's type identification ID
109120 */
110121 registerContainer (Constructor, args, typeId = Constructor.typeId) {
111122 this._containerTypes[typeId] = {
112123 Constructor: Constructor,
scheduler.jsView
@@ -54,9 +54,9 @@
5454 }
5555
5656 /**
5757 * deletes an instance from the scheduler
58- * @param {string} id - the containers id
58+ * @param {String} id - the containers id
5959 */
6060 done (id) {
6161 this._running.delete(id)
6262 this.instances.delete(id)
capsManager.jsView
@@ -1,0 +1,42 @@
1+module.exports = class CapsManager {
2+ /**
3+ * The port manager manages the the ports. This inculdes creation, deletion
4+ * fetching and waiting on ports
5+ * @param {Object} opts
6+ * @param {Object} opts.state
7+ * @param {Object} opts.hypervisor
8+ * @param {Object} opts.exoInterface
9+ */
10+ constructor (caps) {
11+ this._storedCaps = caps
12+ this.clist = new Set()
13+ }
14+
15+ /**
16+ * binds a port to a name
17+ * @param {Object} port - the port to bind
18+ * @param {String} name - the name of the port
19+ */
20+ store (name, cap) {
21+ // save the port instance
22+ this._storedCaps[name] = cap
23+ }
24+
25+ /**
26+ * gets a port given it's name
27+ * @param {String} name
28+ * @return {Object}
29+ */
30+ get (name) {
31+ const cap = this._storedCaps[name]
32+ return cap
33+ }
34+
35+ /**
36+ * delete an port given the name it is bound to
37+ * @param {string} name
38+ */
39+ delete (name) {
40+ delete this._storedCaps[name]
41+ }
42+}

Built with git-ssb-web