7c825c8674b2952b9fe94fb8e4e921a111f294c3
[iotcloud.git] / src / js / iotjs / src / rejectedmessage.js
1 "use strict";
2
3 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; }; }();
4
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7 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; }
8
9 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; }
10
11 var RejectedMessage = function (_Entry) {
12     _inherits(RejectedMessage, _Entry);
13
14     function RejectedMessage(slot, _machineid, _oldseqnum, _newseqnum, _equalto) {
15         _classCallCheck(this, RejectedMessage);
16
17         var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RejectedMessage).call(this, slot));
18
19         _this.machineid = _machineid;
20         _this.oldseqnum = _oldseqnum;
21         _this.newseqnum = _newseqnum;
22         _this.equalto = _equalto;
23         _this.watchset = new Set();
24         return _this;
25     }
26
27     _createClass(RejectedMessage, [{
28         key: "getOldSeqNum",
29         value: function getOldSeqNum() {
30             return this.oldseqnum;
31         }
32     }, {
33         key: "getNewSeqNum",
34         value: function getNewSeqNum() {
35             return this.newseqnum;
36         }
37     }, {
38         key: "getEqual",
39         value: function getEqual() {
40             return this.equalto;
41         }
42     }, {
43         key: "getMachineID",
44         value: function getMachineID() {
45             return this.machineid;
46         }
47     }, {
48         key: "setWatchSet",
49         value: function setWatchSet(_watchset) {
50             this.watchset = _watchset;
51         }
52     }, {
53         key: "removeWatcher",
54         value: function removeWatcher(_machineid) {
55             if (this.watchset.remove(_machineid)) {
56                 if (this.watchset.isEmpty()) {
57                     this.setDead();
58                 }
59             }
60         }
61     }, {
62         key: "encode",
63         value: function encode(bb) {
64             bb.writeByte(Entry.TypeRejectedMessage);
65             bb.writeInt64(this.machineid);
66             bb.writeInt64(this.oldseqnum);
67             bb.writeInt64(this.newseqnum);
68             if (this.equalto === true) {
69                 bb.writebyte(1);
70             } else {
71                 bb.writebyte(0);
72             }
73         }
74     }, {
75         key: "getSize",
76         value: function getSize() {
77             return 3 * 8 + 2 * 1;
78         }
79     }, {
80         key: "getType",
81         value: function getType() {
82             return Entry.TypeRejectedMessage;
83         }
84     }, {
85         key: "getCopy",
86         value: function getCopy(s) {
87             return new RejectedMessage(s, this.machineid, this.oldseqnum, this.newseqnum, this.equalto);
88         }
89     }], [{
90         key: "decode",
91         value: function decode(slot, bb) {
92             this.machineid = bb.readByte();
93             this.oldseqnum = bb.readInt64();
94             this.newseqnum = bb.readInt64();
95             this.equalto = bb.readbyte();
96             return new RejectedMessage(this.slot, this.machineid, this.oldseqnum, this.newseqnum, this.equalto === 1);
97         }
98     }]);
99
100     return RejectedMessage;
101 }(Entry);