added Rejected message
[iotcloud.git] / src / js / iotjs / src / rejectedmessage.js
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