From de64521c36d8bf0b51f15f0e0e7bd471501cc24b Mon Sep 17 00:00:00 2001 From: joelbandi Date: Thu, 4 Aug 2016 17:13:39 -0700 Subject: [PATCH] added Rejected message --- src/js/iotjs/orig/compat.txt | 2 +- src/js/iotjs/orig/entry.js | 1 - src/js/iotjs/orig/rejectedmessage.js | 59 ++++++++++++++++ src/js/iotjs/src/rejectedmessage.js | 101 +++++++++++++++++++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/js/iotjs/orig/rejectedmessage.js create mode 100644 src/js/iotjs/src/rejectedmessage.js diff --git a/src/js/iotjs/orig/compat.txt b/src/js/iotjs/orig/compat.txt index a5d98b9..4006664 100644 --- a/src/js/iotjs/orig/compat.txt +++ b/src/js/iotjs/orig/compat.txt @@ -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 = 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 diff --git a/src/js/iotjs/orig/entry.js b/src/js/iotjs/orig/entry.js index 8ad481a..8421d5a 100644 --- a/src/js/iotjs/orig/entry.js +++ b/src/js/iotjs/orig/entry.js @@ -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 index 0000000..f9f775a --- /dev/null +++ b/src/js/iotjs/orig/rejectedmessage.js @@ -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 index 0000000..7c825c8 --- /dev/null +++ b/src/js/iotjs/src/rejectedmessage.js @@ -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 -- 2.34.1