added Rejected message
authorjoelbandi <joelvivekbandi@gmail.com>
Fri, 5 Aug 2016 00:13:39 +0000 (17:13 -0700)
committerjoelbandi <joelvivekbandi@gmail.com>
Fri, 5 Aug 2016 00:13:39 +0000 (17:13 -0700)
src/js/iotjs/orig/compat.txt
src/js/iotjs/orig/entry.js
src/js/iotjs/orig/rejectedmessage.js [new file with mode: 0644]
src/js/iotjs/src/rejectedmessage.js [new file with mode: 0644]

index a5d98b9e4f53babcda2138a49a84373de46548d9..4006664d8e980c48e53ae121de66f0c3208d5158 100644 (file)
@@ -1,4 +1,4 @@
 1.Byte[] -> Uint8Array
 2.Static decode method in slot.js takes the table, uint8array and the secret key as the argument
 3.Vector<Entries> = array of entries []
-4.A Byte in a 'number' in javascript
\ No newline at end of file
+4.A Byte in a 'number' in javascript
index 8ad481a86184616bbde9d6dda075dc081cd6e977..8421d5a0f97e35c35105ae57beb9950924e2c1b8 100644 (file)
@@ -36,7 +36,6 @@ class Entry{
                parentslot.decrementLiveCount();
        }
 
-       //must be overriden.
        encode(bytebuffer){
 
        }
diff --git a/src/js/iotjs/orig/rejectedmessage.js b/src/js/iotjs/orig/rejectedmessage.js
new file mode 100644 (file)
index 0000000..f9f775a
--- /dev/null
@@ -0,0 +1,59 @@
+class RejectedMessage extends Entry {
+    constructor(slot, _machineid, _oldseqnum, _newseqnum, _equalto) {
+        super(slot);
+        this.machineid = _machineid;
+        this.oldseqnum = _oldseqnum;
+        this.newseqnum = _newseqnum;
+        this.equalto = _equalto;
+        this.watchset = new Set();
+    }
+    getOldSeqNum() {
+        return this.oldseqnum;
+    }
+    getNewSeqNum() {
+        return this.newseqnum;
+    }
+    getEqual() {
+        return this.equalto;
+    }
+    getMachineID() {
+        return this.machineid;
+    }
+    static decode(slot, bb) {
+        this.machineid = bb.readByte();
+        this.oldseqnum = bb.readInt64();
+        this.newseqnum = bb.readInt64();
+        this.equalto = bb.readbyte();
+        return new RejectedMessage(this.slot, this.machineid, this.oldseqnum, this.newseqnum, this.equalto === 1)
+    }
+    setWatchSet(_watchset) {
+        this.watchset = _watchset;
+    }
+    removeWatcher(_machineid) {
+        if (this.watchset.remove(_machineid)) {
+            if (this.watchset.isEmpty()) {
+                this.setDead();
+            }
+        }
+    }
+    encode(bb) {
+        bb.writeByte(Entry.TypeRejectedMessage);
+        bb.writeInt64(this.machineid);
+        bb.writeInt64(this.oldseqnum);
+        bb.writeInt64(this.newseqnum);
+        if (this.equalto === true) {
+            bb.writebyte(1);
+        } else {
+            bb.writebyte(0);
+        }
+    }
+    getSize() {
+        return 3 * 8 + 2 * 1;
+    }
+    getType(){
+       return Entry.TypeRejectedMessage;
+    }
+    getCopy(s){
+       return new RejectedMessage(s,this.machineid,this.oldseqnum,this.newseqnum,this.equalto);
+    }
+}
diff --git a/src/js/iotjs/src/rejectedmessage.js b/src/js/iotjs/src/rejectedmessage.js
new file mode 100644 (file)
index 0000000..7c825c8
--- /dev/null
@@ -0,0 +1,101 @@
+"use strict";
+
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
+
+function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
+
+var RejectedMessage = function (_Entry) {
+    _inherits(RejectedMessage, _Entry);
+
+    function RejectedMessage(slot, _machineid, _oldseqnum, _newseqnum, _equalto) {
+        _classCallCheck(this, RejectedMessage);
+
+        var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RejectedMessage).call(this, slot));
+
+        _this.machineid = _machineid;
+        _this.oldseqnum = _oldseqnum;
+        _this.newseqnum = _newseqnum;
+        _this.equalto = _equalto;
+        _this.watchset = new Set();
+        return _this;
+    }
+
+    _createClass(RejectedMessage, [{
+        key: "getOldSeqNum",
+        value: function getOldSeqNum() {
+            return this.oldseqnum;
+        }
+    }, {
+        key: "getNewSeqNum",
+        value: function getNewSeqNum() {
+            return this.newseqnum;
+        }
+    }, {
+        key: "getEqual",
+        value: function getEqual() {
+            return this.equalto;
+        }
+    }, {
+        key: "getMachineID",
+        value: function getMachineID() {
+            return this.machineid;
+        }
+    }, {
+        key: "setWatchSet",
+        value: function setWatchSet(_watchset) {
+            this.watchset = _watchset;
+        }
+    }, {
+        key: "removeWatcher",
+        value: function removeWatcher(_machineid) {
+            if (this.watchset.remove(_machineid)) {
+                if (this.watchset.isEmpty()) {
+                    this.setDead();
+                }
+            }
+        }
+    }, {
+        key: "encode",
+        value: function encode(bb) {
+            bb.writeByte(Entry.TypeRejectedMessage);
+            bb.writeInt64(this.machineid);
+            bb.writeInt64(this.oldseqnum);
+            bb.writeInt64(this.newseqnum);
+            if (this.equalto === true) {
+                bb.writebyte(1);
+            } else {
+                bb.writebyte(0);
+            }
+        }
+    }, {
+        key: "getSize",
+        value: function getSize() {
+            return 3 * 8 + 2 * 1;
+        }
+    }, {
+        key: "getType",
+        value: function getType() {
+            return Entry.TypeRejectedMessage;
+        }
+    }, {
+        key: "getCopy",
+        value: function getCopy(s) {
+            return new RejectedMessage(s, this.machineid, this.oldseqnum, this.newseqnum, this.equalto);
+        }
+    }], [{
+        key: "decode",
+        value: function decode(slot, bb) {
+            this.machineid = bb.readByte();
+            this.oldseqnum = bb.readInt64();
+            this.newseqnum = bb.readInt64();
+            this.equalto = bb.readbyte();
+            return new RejectedMessage(this.slot, this.machineid, this.oldseqnum, this.newseqnum, this.equalto === 1);
+        }
+    }]);
+
+    return RejectedMessage;
+}(Entry);
\ No newline at end of file