@jayesol/jayeson.lib.sports 2.2.7-beta2 → 2.2.7-beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/basketball_codec.js +1 -209
- package/lib/client.js +1 -686
- package/lib/codec.js +1 -129
- package/lib/core.js +1 -497
- package/lib/data_structure.js +1 -208
- package/lib/dispatch.js +1 -324
- package/lib/index.js +1 -27
- package/lib/merge.js +1 -569
- package/lib/message_class.js +1 -466
- package/lib/module.js +1 -87
- package/lib/mutable.js +1 -1061
- package/lib/protobuf_bundle.js +1 -9683
- package/lib/receive.js +1 -484
- package/lib/soccer_codec.js +1 -168
- package/lib/tennis_codec.js +1 -177
- package/package.json +6 -3
package/lib/codec.js
CHANGED
|
@@ -1,129 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Util = exports.FilterRequest = exports.CodecHelper = exports.EncodeAction = void 0;
|
|
4
|
-
const mutable_1 = require("./mutable");
|
|
5
|
-
var EncodeAction;
|
|
6
|
-
(function (EncodeAction) {
|
|
7
|
-
EncodeAction[EncodeAction["INSERT"] = 0] = "INSERT";
|
|
8
|
-
EncodeAction[EncodeAction["UPDATE"] = 1] = "UPDATE";
|
|
9
|
-
EncodeAction[EncodeAction["DELETE"] = 2] = "DELETE";
|
|
10
|
-
})(EncodeAction = exports.EncodeAction || (exports.EncodeAction = {}));
|
|
11
|
-
class CodecHelper {
|
|
12
|
-
constructor() { }
|
|
13
|
-
coerceInt64(val) {
|
|
14
|
-
if (val.toNumber) {
|
|
15
|
-
return val.toNumber();
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return val;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
populatePKIntoMetaInfo(meta, key) {
|
|
22
|
-
meta[mutable_1.Const.AGGREGATE_KEY] = key.toString();
|
|
23
|
-
return meta;
|
|
24
|
-
}
|
|
25
|
-
formatRate(num) {
|
|
26
|
-
//Round input to 4 decimal places
|
|
27
|
-
return Math.round(num * 10000) / 10000;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.CodecHelper = CodecHelper;
|
|
31
|
-
class FilterRequest {
|
|
32
|
-
constructor(_requestId, _ruleCombination) {
|
|
33
|
-
this._requestId = _requestId;
|
|
34
|
-
this._ruleCombination = _ruleCombination;
|
|
35
|
-
}
|
|
36
|
-
getRequestId() {
|
|
37
|
-
return this._requestId;
|
|
38
|
-
}
|
|
39
|
-
getFilterData() {
|
|
40
|
-
return this._ruleCombination;
|
|
41
|
-
}
|
|
42
|
-
toJSON() {
|
|
43
|
-
return { "requestId": this.getRequestId(), "namespace": this._ruleCombination.namespace, "filterRules": this._ruleCombination.filterRules };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.FilterRequest = FilterRequest;
|
|
47
|
-
FilterRequest.IGNORED_REQUEST_ID = -1;
|
|
48
|
-
class Util {
|
|
49
|
-
/**
|
|
50
|
-
* Utility to Store array of String values as single String Also see
|
|
51
|
-
* {@link #removeKey(String, String)}
|
|
52
|
-
*
|
|
53
|
-
* @param existing
|
|
54
|
-
* "IBC_LIVE,CROWN_LIVE"
|
|
55
|
-
* @param incoming
|
|
56
|
-
* "SBO_LIVE"
|
|
57
|
-
* @return "IBC_LIVE,CROWN_LIVE,SBO_LIVE"
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
static addKey(existing, incoming) {
|
|
61
|
-
if (incoming.search(Util.SEPARATOR) != -1) {
|
|
62
|
-
throw new TypeError("Incoming String cannot contain Separator: " + Util.SEPARATOR + " Incoming: " + incoming);
|
|
63
|
-
}
|
|
64
|
-
if (existing.length == 0) {
|
|
65
|
-
return incoming;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
if (existing.indexOf(incoming) === -1) {
|
|
69
|
-
return existing + Util.SEPARATOR + incoming;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return existing;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Utility to remove element from string values Stored as String Also see
|
|
78
|
-
* {@link #addKey(String, String)}
|
|
79
|
-
*
|
|
80
|
-
* @param existing
|
|
81
|
-
* "IBC_LIVE,CROWN_LIVE"
|
|
82
|
-
* @param incoming
|
|
83
|
-
* "IBC_LIVE"
|
|
84
|
-
* @return "CROWN_LIVE". return empty string if there are no more keys. Return
|
|
85
|
-
* existing string if incoming is not present in existing
|
|
86
|
-
*/
|
|
87
|
-
static removeKey(existing, incoming) {
|
|
88
|
-
let split = existing.split(Util.SEPARATOR);
|
|
89
|
-
let incomingArr = incoming.split(Util.SEPARATOR);
|
|
90
|
-
split.sort();
|
|
91
|
-
for (let incoming of incomingArr) {
|
|
92
|
-
let index = split.indexOf(incoming);
|
|
93
|
-
// If not found return
|
|
94
|
-
if (index < 0) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
split.splice(index, 1);
|
|
99
|
-
// Return empty string if removed is empty
|
|
100
|
-
if (split.length == 0) {
|
|
101
|
-
return "";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
let finalStr = split[0];
|
|
106
|
-
for (let i = 1; i < split.length; i++) {
|
|
107
|
-
finalStr = Util.addKey(finalStr, split[i]);
|
|
108
|
-
}
|
|
109
|
-
return finalStr;
|
|
110
|
-
}
|
|
111
|
-
static containsKey(existing, incoming) {
|
|
112
|
-
if (existing == undefined) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if (incoming.search(Util.SEPARATOR) != -1) {
|
|
116
|
-
throw new TypeError("Incoming String cannot contain Separator: " + Util.SEPARATOR + " Incoming: " + incoming);
|
|
117
|
-
}
|
|
118
|
-
let split = existing.split(Util.SEPARATOR);
|
|
119
|
-
let index = split.indexOf(incoming);
|
|
120
|
-
if (index < 0) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.Util = Util;
|
|
129
|
-
Util.SEPARATOR = ",";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Util=exports.FilterRequest=exports.CodecHelper=exports.EncodeAction=void 0;const mutable_1=require("./mutable");var EncodeAction;!function(t){t[t.INSERT=0]="INSERT",t[t.UPDATE=1]="UPDATE",t[t.DELETE=2]="DELETE"}(EncodeAction=exports.EncodeAction||(exports.EncodeAction={}));class CodecHelper{constructor(){}coerceInt64(t){return t.toNumber?t.toNumber():t}populatePKIntoMetaInfo(t,e){return t[mutable_1.Const.AGGREGATE_KEY]=e.toString(),t}formatRate(t){return Math.round(1e4*t)/1e4}}exports.CodecHelper=CodecHelper;class FilterRequest{constructor(t,e){this._requestId=t,this._ruleCombination=e}getRequestId(){return this._requestId}getFilterData(){return this._ruleCombination}toJSON(){return{requestId:this.getRequestId(),namespace:this._ruleCombination.namespace,filterRules:this._ruleCombination.filterRules}}}exports.FilterRequest=FilterRequest,FilterRequest.IGNORED_REQUEST_ID=-1;class Util{static addKey(t,e){if(-1!=e.search(Util.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+Util.SEPARATOR+" Incoming: "+e);return 0==t.length?e:-1===t.indexOf(e)?t+Util.SEPARATOR+e:t}static removeKey(t,e){let r=t.split(Util.SEPARATOR),n=e.split(Util.SEPARATOR);r.sort();for(let t of n){let e=r.indexOf(t);if(!(e<0)&&(r.splice(e,1),0==r.length))return""}let o=r[0];for(let t=1;t<r.length;t++)o=Util.addKey(o,r[t]);return o}static containsKey(t,e){if(null==t)return!1;if(-1!=e.search(Util.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+Util.SEPARATOR+" Incoming: "+e);return!(t.split(Util.SEPARATOR).indexOf(e)<0)}}exports.Util=Util,Util.SEPARATOR=",";
|
package/lib/core.js
CHANGED
|
@@ -1,497 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
-
};
|
|
34
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
35
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
-
};
|
|
37
|
-
var FSRepoImpl_1;
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.RecycleBin = exports.TTLRemoveCheck = exports.TTLRestoreCheck = exports.TTLCheck = exports.TTLOutgoing = exports.TTLType = exports.TTLConfig = exports.Delta = exports.FSRepoImpl = exports.AbstractFSRepo = exports.FSREPO_IMPL = void 0;
|
|
40
|
-
const data_structure_1 = require("./data_structure");
|
|
41
|
-
const Collections = __importStar(require("typescript-collections"));
|
|
42
|
-
const T = __importStar(require("ts-promise"));
|
|
43
|
-
//imports required for dependency injection
|
|
44
|
-
require("reflect-metadata");
|
|
45
|
-
const injection_js_1 = require("injection-js");
|
|
46
|
-
const jayeson_lib_record_1 = require("@jayesol/jayeson.lib.record");
|
|
47
|
-
const message_class_1 = require("./message_class");
|
|
48
|
-
const mutable_1 = require("./mutable");
|
|
49
|
-
const merge_1 = require("./merge");
|
|
50
|
-
const data_structure_2 = require("./data_structure");
|
|
51
|
-
exports.FSREPO_IMPL = new injection_js_1.InjectionToken('FSRepoInstance');
|
|
52
|
-
let AbstractFSRepo = class AbstractFSRepo {
|
|
53
|
-
constructor() {
|
|
54
|
-
this._handlers = new Collections.Set();
|
|
55
|
-
}
|
|
56
|
-
handlers() {
|
|
57
|
-
return this._handlers;
|
|
58
|
-
}
|
|
59
|
-
appendSnapshot(stream, mergeable) {
|
|
60
|
-
throw new Error("appendSnapshot is not implemented");
|
|
61
|
-
}
|
|
62
|
-
getSnapshot(streamName) {
|
|
63
|
-
throw new Error("getSnapshot is not implemented");
|
|
64
|
-
}
|
|
65
|
-
registerSnapshotHandler(ssHandler) {
|
|
66
|
-
this.handlers().add(ssHandler);
|
|
67
|
-
}
|
|
68
|
-
deRegisterSnapshotHandler(ssHandler) {
|
|
69
|
-
this.handlers().remove(ssHandler);
|
|
70
|
-
}
|
|
71
|
-
getRegisteredHandlers() {
|
|
72
|
-
return this.handlers().toArray();
|
|
73
|
-
}
|
|
74
|
-
push(outgoing) {
|
|
75
|
-
throw new Error("push is not implemented");
|
|
76
|
-
}
|
|
77
|
-
isReady(stream) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
AbstractFSRepo = __decorate([
|
|
82
|
-
(0, injection_js_1.Injectable)(),
|
|
83
|
-
__metadata("design:paramtypes", [])
|
|
84
|
-
], AbstractFSRepo);
|
|
85
|
-
exports.AbstractFSRepo = AbstractFSRepo;
|
|
86
|
-
let FSRepoImpl = FSRepoImpl_1 = class FSRepoImpl extends AbstractFSRepo {
|
|
87
|
-
constructor(outputStreamName, sportsGroup) {
|
|
88
|
-
super();
|
|
89
|
-
this.outputStreamName = outputStreamName;
|
|
90
|
-
this.sportsGroup = sportsGroup;
|
|
91
|
-
this._head = null;
|
|
92
|
-
let instance = this;
|
|
93
|
-
this.fssEndReceived = new T.Promise((resolve, reject) => {
|
|
94
|
-
instance.promiseResolver = resolve;
|
|
95
|
-
instance.promiseRejector = reject;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
head() {
|
|
99
|
-
return this._head;
|
|
100
|
-
}
|
|
101
|
-
appendSnapshot(stream, logic) {
|
|
102
|
-
//single threaded, locking is unnecessary.
|
|
103
|
-
if (this._head == null) {
|
|
104
|
-
this.result = logic.apply(null);
|
|
105
|
-
this._head = this.result.getAfter();
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
this.result = logic.apply(this._head);
|
|
109
|
-
this._head = this.result.getAfter();
|
|
110
|
-
}
|
|
111
|
-
return this.result.getDeltaOut();
|
|
112
|
-
}
|
|
113
|
-
getSnapshot(streamName = "") {
|
|
114
|
-
if (this._head == null) {
|
|
115
|
-
return data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
|
|
116
|
-
}
|
|
117
|
-
return this._head;
|
|
118
|
-
}
|
|
119
|
-
getTtlRemoveSnapshot() {
|
|
120
|
-
if (this._head == null) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
let ttlRemoveCheck = new TTLRemoveCheck(null, this._head.getPartitions().toArray(), this.outputStreamName);
|
|
124
|
-
return [ttlRemoveCheck];
|
|
125
|
-
}
|
|
126
|
-
push(outgoing) {
|
|
127
|
-
if (outgoing.msgType() == this.sportsGroup.FULLSNAPSHOT_START()) {
|
|
128
|
-
//ignore this
|
|
129
|
-
}
|
|
130
|
-
else if (outgoing.msgType() == this.sportsGroup.FULLSNAPSHOT_END()) {
|
|
131
|
-
this.promiseResolver(true);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
let _instance = this;
|
|
135
|
-
this._handlers.forEach(function (handler) {
|
|
136
|
-
handler.process(_instance.outputStreamName, outgoing);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
isReady(stream) {
|
|
141
|
-
return this.fssEndReceived;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
FSRepoImpl.outputStream = new injection_js_1.InjectionToken('aggregatedStreamName');
|
|
145
|
-
FSRepoImpl = FSRepoImpl_1 = __decorate([
|
|
146
|
-
(0, injection_js_1.Injectable)(),
|
|
147
|
-
__param(0, (0, injection_js_1.Inject)(FSRepoImpl_1.outputStream)),
|
|
148
|
-
__metadata("design:paramtypes", [String, message_class_1.SportsFeedMessageGroup])
|
|
149
|
-
], FSRepoImpl);
|
|
150
|
-
exports.FSRepoImpl = FSRepoImpl;
|
|
151
|
-
class Delta {
|
|
152
|
-
constructor(_incoming, _after, _before) {
|
|
153
|
-
this._incoming = _incoming;
|
|
154
|
-
this._after = _after;
|
|
155
|
-
this._before = _before;
|
|
156
|
-
}
|
|
157
|
-
incoming() {
|
|
158
|
-
return this._incoming;
|
|
159
|
-
}
|
|
160
|
-
msgType() {
|
|
161
|
-
return this._incoming.msgType();
|
|
162
|
-
}
|
|
163
|
-
after() {
|
|
164
|
-
return this._after;
|
|
165
|
-
}
|
|
166
|
-
delta() {
|
|
167
|
-
return this._incoming.data();
|
|
168
|
-
}
|
|
169
|
-
before() {
|
|
170
|
-
return this._before;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.Delta = Delta;
|
|
174
|
-
let TTLConfig = class TTLConfig {
|
|
175
|
-
constructor() {
|
|
176
|
-
this.livettl = 180000;
|
|
177
|
-
this.todayttl = 180000;
|
|
178
|
-
this.earlyttl = 180000;
|
|
179
|
-
// Boolean to see if ttl is enabled or not.
|
|
180
|
-
// If set to false,ttl will be disabled even though ttl values are set
|
|
181
|
-
this.enableTtl = true;
|
|
182
|
-
}
|
|
183
|
-
getLivettl() {
|
|
184
|
-
return this.livettl;
|
|
185
|
-
}
|
|
186
|
-
setLivettl(livettl) {
|
|
187
|
-
this.livettl = livettl;
|
|
188
|
-
}
|
|
189
|
-
getTodayttl() {
|
|
190
|
-
return this.todayttl;
|
|
191
|
-
}
|
|
192
|
-
setTodayttl(todayttl) {
|
|
193
|
-
this.todayttl = todayttl;
|
|
194
|
-
}
|
|
195
|
-
getEarlyttl() {
|
|
196
|
-
return this.earlyttl;
|
|
197
|
-
}
|
|
198
|
-
setEarlyttl(earlyttl) {
|
|
199
|
-
this.earlyttl = earlyttl;
|
|
200
|
-
}
|
|
201
|
-
getRunInterval() {
|
|
202
|
-
if (!this.enableTtl) {
|
|
203
|
-
return -1;
|
|
204
|
-
}
|
|
205
|
-
let liveTTL = this.getLivettl();
|
|
206
|
-
let todayTTL = this.getTodayttl();
|
|
207
|
-
let earlyTTL = this.getEarlyttl();
|
|
208
|
-
let sleepDuration = Math.min(liveTTL, todayTTL, earlyTTL) / 2;
|
|
209
|
-
return (sleepDuration < 1000) ? 10000 : sleepDuration;
|
|
210
|
-
}
|
|
211
|
-
isEnableTtl() {
|
|
212
|
-
return this.enableTtl;
|
|
213
|
-
}
|
|
214
|
-
setEnableTtl(enableTtl) {
|
|
215
|
-
this.enableTtl = enableTtl;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
TTLConfig = __decorate([
|
|
219
|
-
(0, injection_js_1.Injectable)()
|
|
220
|
-
], TTLConfig);
|
|
221
|
-
exports.TTLConfig = TTLConfig;
|
|
222
|
-
var TTLType;
|
|
223
|
-
(function (TTLType) {
|
|
224
|
-
TTLType[TTLType["REMOVE"] = 0] = "REMOVE";
|
|
225
|
-
TTLType[TTLType["RESTORE"] = 1] = "RESTORE";
|
|
226
|
-
})(TTLType = exports.TTLType || (exports.TTLType = {}));
|
|
227
|
-
class TTLOutgoing extends Delta {
|
|
228
|
-
constructor(ttlType, incoming, after, before) {
|
|
229
|
-
super(incoming, after, before);
|
|
230
|
-
this.ttlType = ttlType;
|
|
231
|
-
}
|
|
232
|
-
getTtlType() {
|
|
233
|
-
return this.ttlType;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
exports.TTLOutgoing = TTLOutgoing;
|
|
237
|
-
class TTLCheck {
|
|
238
|
-
constructor(ttlType, recycleBin, keys, stream) {
|
|
239
|
-
this.ttlType = ttlType;
|
|
240
|
-
this.recycleBin = recycleBin;
|
|
241
|
-
this.keys = keys;
|
|
242
|
-
this.stream = stream;
|
|
243
|
-
}
|
|
244
|
-
getKeys() {
|
|
245
|
-
return this.keys;
|
|
246
|
-
}
|
|
247
|
-
getKeysMapping() {
|
|
248
|
-
let mapping = new Collections.Dictionary();
|
|
249
|
-
this.keys.forEach(key => {
|
|
250
|
-
mapping.setValue(key, new Date().getTime());
|
|
251
|
-
});
|
|
252
|
-
return mapping;
|
|
253
|
-
}
|
|
254
|
-
getTtlType() {
|
|
255
|
-
return this.ttlType;
|
|
256
|
-
}
|
|
257
|
-
getRecycleBin() {
|
|
258
|
-
return this.recycleBin;
|
|
259
|
-
}
|
|
260
|
-
setRecycleBin(recycleBin) {
|
|
261
|
-
this.recycleBin = recycleBin;
|
|
262
|
-
}
|
|
263
|
-
getStream() {
|
|
264
|
-
return this.stream;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
exports.TTLCheck = TTLCheck;
|
|
268
|
-
class TTLRestoreCheck extends TTLCheck {
|
|
269
|
-
constructor(recycleBin, keys, stream) {
|
|
270
|
-
super(TTLType.RESTORE, recycleBin, keys, stream);
|
|
271
|
-
}
|
|
272
|
-
apply(before) {
|
|
273
|
-
let restoredSS = before;
|
|
274
|
-
let atLeastOneRestored = false;
|
|
275
|
-
let restoredKeys = new Collections.Dictionary();
|
|
276
|
-
let matches = {};
|
|
277
|
-
let ttlRestoredList = [];
|
|
278
|
-
//for each key in this object
|
|
279
|
-
this.getKeys().forEach((key, val) => {
|
|
280
|
-
//check if key is present in recycle bin
|
|
281
|
-
if (this.getRecycleBin().containData(key)) {
|
|
282
|
-
atLeastOneRestored = true;
|
|
283
|
-
let restoreTime = new Date().getTime();
|
|
284
|
-
restoredKeys.setValue(key, restoreTime);
|
|
285
|
-
matches = this.getRecycleBin().copyData(key, matches);
|
|
286
|
-
//if it is present, restore data
|
|
287
|
-
this.ttlRestoreWrapper = this.getRecycleBin().restoreData(new data_structure_2.TTLWrapper(), restoredSS, key, restoreTime);
|
|
288
|
-
restoredSS = this.ttlRestoreWrapper.getRemainingSs();
|
|
289
|
-
ttlRestoredList.push(this.ttlRestoreWrapper.getRestoredSs());
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
let ttlOut = [];
|
|
293
|
-
let wrap = new data_structure_2.MergeableWrapper();
|
|
294
|
-
wrap.setAfter(restoredSS);
|
|
295
|
-
if (atLeastOneRestored) {
|
|
296
|
-
console.log("restore ----->" + JSON.stringify(restoredKeys.keys()));
|
|
297
|
-
return merge_1.DeltaTransformingLogicImpl.transformTTLRestore(ttlRestoredList, this.getRecycleBin().getGrp(), this.getStream(), before, restoredSS, matches, restoredKeys);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
//mark as refresh if not a snapshot message
|
|
301
|
-
let incoming = new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(), this.getStream(), new data_structure_1.IndexedSnapshotImpl(matches, this.getKeysMapping()));
|
|
302
|
-
ttlOut.push(new TTLOutgoing(this.getTtlType(), incoming, restoredSS, before));
|
|
303
|
-
wrap.setDeltaOut(ttlOut);
|
|
304
|
-
return wrap;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
exports.TTLRestoreCheck = TTLRestoreCheck;
|
|
309
|
-
class TTLRemoveCheck extends TTLCheck {
|
|
310
|
-
constructor(recycleBin, keys, stream) {
|
|
311
|
-
super(TTLType.REMOVE, recycleBin, keys, stream);
|
|
312
|
-
}
|
|
313
|
-
apply(before) {
|
|
314
|
-
let allKeys = before.getPartitionMap();
|
|
315
|
-
let keysRemoved = new Collections.Dictionary();
|
|
316
|
-
let removedSnapshot = before;
|
|
317
|
-
let ttlRemoveList = [];
|
|
318
|
-
let ttlConfig = this.getRecycleBin().getTtlConfig();
|
|
319
|
-
let atLeastOneKeyRemoved = false;
|
|
320
|
-
for (let key of this.getKeys()) {
|
|
321
|
-
let threshold = 0;
|
|
322
|
-
if (!allKeys.containsKey(key)) {
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
switch (key.oddType()) {
|
|
326
|
-
case jayeson_lib_record_1.OddType.LIVE:
|
|
327
|
-
threshold = allKeys.getValue(key) + ttlConfig.getLivettl();
|
|
328
|
-
break;
|
|
329
|
-
case jayeson_lib_record_1.OddType.TODAY:
|
|
330
|
-
threshold = allKeys.getValue(key) + ttlConfig.getTodayttl();
|
|
331
|
-
break;
|
|
332
|
-
case jayeson_lib_record_1.OddType.EARLY:
|
|
333
|
-
threshold = allKeys.getValue(key) + ttlConfig.getEarlyttl();
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
if (threshold < new Date().getTime()) {
|
|
337
|
-
//remove expired odds
|
|
338
|
-
atLeastOneKeyRemoved = true;
|
|
339
|
-
keysRemoved.setValue(key, allKeys.getValue(key));
|
|
340
|
-
this.ttlRemoveWrapper = this.getRecycleBin().removeData(new data_structure_2.TTLWrapper(), removedSnapshot, key);
|
|
341
|
-
removedSnapshot = this.ttlRemoveWrapper.getRemainingSs();
|
|
342
|
-
ttlRemoveList.push(this.ttlRemoveWrapper.getRemovedSs());
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
let ttlOut = [];
|
|
346
|
-
if (atLeastOneKeyRemoved) {
|
|
347
|
-
console.log("reseting ----->" + JSON.stringify(keysRemoved.keys()));
|
|
348
|
-
return merge_1.DeltaTransformingLogicImpl.transformTTLRemove(ttlRemoveList, this.getRecycleBin().getGrp(), this.getStream(), before, removedSnapshot, keysRemoved);
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
let wrapper = new data_structure_2.MergeableWrapper();
|
|
352
|
-
let incoming = new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(), this.getStream(), new data_structure_1.IndexedSnapshotImpl({}, this.getKeysMapping()));
|
|
353
|
-
ttlOut.push(new TTLOutgoing(this.getTtlType(), incoming, removedSnapshot, before));
|
|
354
|
-
wrapper.setDeltaOut(ttlOut);
|
|
355
|
-
wrapper.setAfter(removedSnapshot);
|
|
356
|
-
return wrapper;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
exports.TTLRemoveCheck = TTLRemoveCheck;
|
|
361
|
-
let RecycleBin = class RecycleBin {
|
|
362
|
-
constructor(ttlConfig, grp, fsRepo) {
|
|
363
|
-
this.ttlConfig = ttlConfig;
|
|
364
|
-
this.grp = grp;
|
|
365
|
-
this.fsRepo = fsRepo;
|
|
366
|
-
this.expiredMatches = new Collections.Dictionary();
|
|
367
|
-
this.ttlStatus = new Collections.Set();
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Remove the data for a given PartitionKey from a snapshot and return the
|
|
371
|
-
* modified snapshot. The removed data will be stored in this recycle bin.
|
|
372
|
-
*
|
|
373
|
-
* @param snapshot
|
|
374
|
-
* @param key
|
|
375
|
-
*/
|
|
376
|
-
removeData(ttlRemoveWrapper, snapshot, key) {
|
|
377
|
-
if (!snapshot.getPartitions().contains(key)) {
|
|
378
|
-
ttlRemoveWrapper.setRemainingSs(snapshot);
|
|
379
|
-
ttlRemoveWrapper.setRemovedSs(null);
|
|
380
|
-
return ttlRemoveWrapper;
|
|
381
|
-
}
|
|
382
|
-
let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(snapshot);
|
|
383
|
-
// remove the data with given PartitionKey from sBuilder
|
|
384
|
-
// and get a snapshot containing only the removed data.
|
|
385
|
-
let removedData = sBuilder.reset(key).build();
|
|
386
|
-
//save the data to be removed
|
|
387
|
-
let result = sBuilder.build();
|
|
388
|
-
this.expiredMatches.setValue(key, removedData);
|
|
389
|
-
ttlRemoveWrapper.setRemovedSs(removedData);
|
|
390
|
-
ttlRemoveWrapper.setRemainingSs(result);
|
|
391
|
-
// return the snapshot with PartitionKey data removed
|
|
392
|
-
return ttlRemoveWrapper;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Retrieves the data in this bin with given PartitionKey and combine it with
|
|
396
|
-
* the given snapshot.
|
|
397
|
-
*
|
|
398
|
-
* @param parent
|
|
399
|
-
* @param key
|
|
400
|
-
*/
|
|
401
|
-
restoreData(ttlRestore, parent, key, restoreTime) {
|
|
402
|
-
let partition = this.expiredMatches.getValue(key);
|
|
403
|
-
// Return if expired data doesn't contain given key
|
|
404
|
-
if (partition == null) {
|
|
405
|
-
ttlRestore.setRemainingSs(parent);
|
|
406
|
-
ttlRestore.setRestoredSs(null);
|
|
407
|
-
return ttlRestore;
|
|
408
|
-
}
|
|
409
|
-
//update restored partition's refresh time with the restore time
|
|
410
|
-
let updateTime = new Collections.Dictionary();
|
|
411
|
-
updateTime.setValue(key, restoreTime);
|
|
412
|
-
let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(partition);
|
|
413
|
-
sBuilder.markPartitionAsUpdated(key, restoreTime);
|
|
414
|
-
partition = sBuilder.build();
|
|
415
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(), partition, parent).getAfterSs();
|
|
416
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(), partition, parent).getAfterSs();
|
|
417
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(), partition, parent).getAfterSs();
|
|
418
|
-
ttlRestore.setRestoredSs(partition);
|
|
419
|
-
ttlRestore.setRemainingSs(parent);
|
|
420
|
-
this.expiredMatches.remove(key);
|
|
421
|
-
return ttlRestore;
|
|
422
|
-
}
|
|
423
|
-
clearBin(key) {
|
|
424
|
-
this.expiredMatches.remove(key);
|
|
425
|
-
this.ttlStatus.remove(key);
|
|
426
|
-
}
|
|
427
|
-
containData(key) {
|
|
428
|
-
return this.expiredMatches.containsKey(key);
|
|
429
|
-
}
|
|
430
|
-
getTtlConfig() {
|
|
431
|
-
return this.ttlConfig;
|
|
432
|
-
}
|
|
433
|
-
getFsRepo() {
|
|
434
|
-
return this.fsRepo;
|
|
435
|
-
}
|
|
436
|
-
getTtlRestoreSnapshot(incoming) {
|
|
437
|
-
let restoreSnapshot = null;
|
|
438
|
-
if (this.ttlStatus.isEmpty()) {
|
|
439
|
-
return restoreSnapshot;
|
|
440
|
-
}
|
|
441
|
-
if (this.getGrp().DATA_RESET().id() == incoming.msgType().id()) {
|
|
442
|
-
incoming.data().getPartitions().forEach(pKey => {
|
|
443
|
-
console.log("Dropping partition " + pKey);
|
|
444
|
-
this.expiredMatches.remove(pKey);
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
incoming.data().getPartitionMap().forEach((pKey, val) => {
|
|
449
|
-
let restoreKeys = [];
|
|
450
|
-
if (this.ttlStatus.contains(pKey)) {
|
|
451
|
-
this.ttlStatus.remove(pKey);
|
|
452
|
-
restoreKeys.push(pKey);
|
|
453
|
-
}
|
|
454
|
-
if (restoreKeys.length > 0) {
|
|
455
|
-
restoreSnapshot = new TTLRestoreCheck(this, restoreKeys, incoming.stream());
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
return restoreSnapshot;
|
|
460
|
-
}
|
|
461
|
-
getTtlRemoveSnapshot() {
|
|
462
|
-
let ttlSnapshots = this.getFsRepo().getTtlRemoveSnapshot();
|
|
463
|
-
ttlSnapshots.forEach(removeSnapshot => {
|
|
464
|
-
removeSnapshot.setRecycleBin(this);
|
|
465
|
-
removeSnapshot.getKeys().forEach(partitionKey => {
|
|
466
|
-
this.ttlStatus.add(partitionKey);
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
return ttlSnapshots;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Copies the data in this RecycleBin related to the given PartitionKey into the
|
|
473
|
-
* list of matches.
|
|
474
|
-
*
|
|
475
|
-
* @param key
|
|
476
|
-
* @param matches
|
|
477
|
-
*/
|
|
478
|
-
copyData(key, matches) {
|
|
479
|
-
let snapshot = this.expiredMatches.getValue(key);
|
|
480
|
-
if (snapshot === undefined) {
|
|
481
|
-
return matches;
|
|
482
|
-
}
|
|
483
|
-
let parent = new data_structure_1.IndexedSnapshotImpl(matches);
|
|
484
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(), snapshot, parent).getAfterSs();
|
|
485
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(), snapshot, parent).getAfterSs();
|
|
486
|
-
parent = merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(), snapshot, parent).getAfterSs();
|
|
487
|
-
return parent.matchesSport;
|
|
488
|
-
}
|
|
489
|
-
getGrp() {
|
|
490
|
-
return this.grp;
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
RecycleBin = __decorate([
|
|
494
|
-
(0, injection_js_1.Injectable)(),
|
|
495
|
-
__metadata("design:paramtypes", [TTLConfig, message_class_1.SportsFeedMessageGroup, AbstractFSRepo])
|
|
496
|
-
], RecycleBin);
|
|
497
|
-
exports.RecycleBin = RecycleBin;
|
|
1
|
+
"use strict";var FSRepoImpl_1,__createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__decorate=this&&this.__decorate||function(e,t,r,s){var i,n=arguments.length,a=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,s);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(n<3?i(a):n>3?i(t,r,a):i(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,a),a},__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__param=this&&this.__param||function(e,t){return function(r,s){t(r,s,e)}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.RecycleBin=exports.TTLRemoveCheck=exports.TTLRestoreCheck=exports.TTLCheck=exports.TTLOutgoing=exports.TTLType=exports.TTLConfig=exports.Delta=exports.FSRepoImpl=exports.AbstractFSRepo=exports.FSREPO_IMPL=void 0;const data_structure_1=require("./data_structure"),Collections=__importStar(require("typescript-collections")),T=__importStar(require("ts-promise"));require("reflect-metadata");const injection_js_1=require("injection-js"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),message_class_1=require("./message_class"),mutable_1=require("./mutable"),merge_1=require("./merge"),data_structure_2=require("./data_structure");exports.FSREPO_IMPL=new injection_js_1.InjectionToken("FSRepoInstance");let AbstractFSRepo=class{constructor(){this._handlers=new Collections.Set}handlers(){return this._handlers}appendSnapshot(e,t){throw new Error("appendSnapshot is not implemented")}getSnapshot(e){throw new Error("getSnapshot is not implemented")}registerSnapshotHandler(e){this.handlers().add(e)}deRegisterSnapshotHandler(e){this.handlers().remove(e)}getRegisteredHandlers(){return this.handlers().toArray()}push(e){throw new Error("push is not implemented")}isReady(e){return null}};AbstractFSRepo=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[])],AbstractFSRepo),exports.AbstractFSRepo=AbstractFSRepo;let FSRepoImpl=FSRepoImpl_1=class extends AbstractFSRepo{constructor(e,t){super(),this.outputStreamName=e,this.sportsGroup=t,this._head=null;let r=this;this.fssEndReceived=new T.Promise((e,t)=>{r.promiseResolver=e,r.promiseRejector=t})}head(){return this._head}appendSnapshot(e,t){return null==this._head?(this.result=t.apply(null),this._head=this.result.getAfter()):(this.result=t.apply(this._head),this._head=this.result.getAfter()),this.result.getDeltaOut()}getSnapshot(e=""){return null==this._head?data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT:this._head}getTtlRemoveSnapshot(){if(null==this._head)return[];return[new TTLRemoveCheck(null,this._head.getPartitions().toArray(),this.outputStreamName)]}push(e){if(e.msgType()==this.sportsGroup.FULLSNAPSHOT_START());else if(e.msgType()==this.sportsGroup.FULLSNAPSHOT_END())this.promiseResolver(!0);else{let t=this;this._handlers.forEach(function(r){r.process(t.outputStreamName,e)})}}isReady(e){return this.fssEndReceived}};FSRepoImpl.outputStream=new injection_js_1.InjectionToken("aggregatedStreamName"),FSRepoImpl=FSRepoImpl_1=__decorate([(0,injection_js_1.Injectable)(),__param(0,(0,injection_js_1.Inject)(FSRepoImpl_1.outputStream)),__metadata("design:paramtypes",[String,message_class_1.SportsFeedMessageGroup])],FSRepoImpl),exports.FSRepoImpl=FSRepoImpl;class Delta{constructor(e,t,r){this._incoming=e,this._after=t,this._before=r}incoming(){return this._incoming}msgType(){return this._incoming.msgType()}after(){return this._after}delta(){return this._incoming.data()}before(){return this._before}}exports.Delta=Delta;let TTLConfig=class{constructor(){this.livettl=18e4,this.todayttl=18e4,this.earlyttl=18e4,this.enableTtl=!0}getLivettl(){return this.livettl}setLivettl(e){this.livettl=e}getTodayttl(){return this.todayttl}setTodayttl(e){this.todayttl=e}getEarlyttl(){return this.earlyttl}setEarlyttl(e){this.earlyttl=e}getRunInterval(){if(!this.enableTtl)return-1;let e=this.getLivettl(),t=this.getTodayttl(),r=this.getEarlyttl(),s=Math.min(e,t,r)/2;return s<1e3?1e4:s}isEnableTtl(){return this.enableTtl}setEnableTtl(e){this.enableTtl=e}};var TTLType;TTLConfig=__decorate([(0,injection_js_1.Injectable)()],TTLConfig),exports.TTLConfig=TTLConfig,function(e){e[e.REMOVE=0]="REMOVE",e[e.RESTORE=1]="RESTORE"}(TTLType=exports.TTLType||(exports.TTLType={}));class TTLOutgoing extends Delta{constructor(e,t,r,s){super(t,r,s),this.ttlType=e}getTtlType(){return this.ttlType}}exports.TTLOutgoing=TTLOutgoing;class TTLCheck{constructor(e,t,r,s){this.ttlType=e,this.recycleBin=t,this.keys=r,this.stream=s}getKeys(){return this.keys}getKeysMapping(){let e=new Collections.Dictionary;return this.keys.forEach(t=>{e.setValue(t,(new Date).getTime())}),e}getTtlType(){return this.ttlType}getRecycleBin(){return this.recycleBin}setRecycleBin(e){this.recycleBin=e}getStream(){return this.stream}}exports.TTLCheck=TTLCheck;class TTLRestoreCheck extends TTLCheck{constructor(e,t,r){super(TTLType.RESTORE,e,t,r)}apply(e){let t=e,r=!1,s=new Collections.Dictionary,i={},n=[];this.getKeys().forEach((e,a)=>{if(this.getRecycleBin().containData(e)){r=!0;let a=(new Date).getTime();s.setValue(e,a),i=this.getRecycleBin().copyData(e,i),this.ttlRestoreWrapper=this.getRecycleBin().restoreData(new data_structure_2.TTLWrapper,t,e,a),t=this.ttlRestoreWrapper.getRemainingSs(),n.push(this.ttlRestoreWrapper.getRestoredSs())}});let a=[],o=new data_structure_2.MergeableWrapper;if(o.setAfter(t),r)return console.log("restore -----\x3e"+JSON.stringify(s.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRestore(n,this.getRecycleBin().getGrp(),this.getStream(),e,t,i,s);{let r=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl(i,this.getKeysMapping()));return a.push(new TTLOutgoing(this.getTtlType(),r,t,e)),o.setDeltaOut(a),o}}}exports.TTLRestoreCheck=TTLRestoreCheck;class TTLRemoveCheck extends TTLCheck{constructor(e,t,r){super(TTLType.REMOVE,e,t,r)}apply(e){let t=e.getPartitionMap(),r=new Collections.Dictionary,s=e,i=[],n=this.getRecycleBin().getTtlConfig(),a=!1;for(let e of this.getKeys()){let o=0;if(t.containsKey(e)){switch(e.oddType()){case jayeson_lib_record_1.OddType.LIVE:o=t.getValue(e)+n.getLivettl();break;case jayeson_lib_record_1.OddType.TODAY:o=t.getValue(e)+n.getTodayttl();break;case jayeson_lib_record_1.OddType.EARLY:o=t.getValue(e)+n.getEarlyttl()}o<(new Date).getTime()&&(a=!0,r.setValue(e,t.getValue(e)),this.ttlRemoveWrapper=this.getRecycleBin().removeData(new data_structure_2.TTLWrapper,s,e),s=this.ttlRemoveWrapper.getRemainingSs(),i.push(this.ttlRemoveWrapper.getRemovedSs()))}}let o=[];if(a)return console.log("reseting -----\x3e"+JSON.stringify(r.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRemove(i,this.getRecycleBin().getGrp(),this.getStream(),e,s,r);{let t=new data_structure_2.MergeableWrapper,r=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl({},this.getKeysMapping()));return o.push(new TTLOutgoing(this.getTtlType(),r,s,e)),t.setDeltaOut(o),t.setAfter(s),t}}}exports.TTLRemoveCheck=TTLRemoveCheck;let RecycleBin=class{constructor(e,t,r){this.ttlConfig=e,this.grp=t,this.fsRepo=r,this.expiredMatches=new Collections.Dictionary,this.ttlStatus=new Collections.Set}removeData(e,t,r){if(!t.getPartitions().contains(r))return e.setRemainingSs(t),e.setRemovedSs(null),e;let s=mutable_1.BuilderProvider.getSnapshotBuilder(t),i=s.reset(r).build(),n=s.build();return this.expiredMatches.setValue(r,i),e.setRemovedSs(i),e.setRemainingSs(n),e}restoreData(e,t,r,s){let i=this.expiredMatches.getValue(r);if(null==i)return e.setRemainingSs(t),e.setRestoredSs(null),e;(new Collections.Dictionary).setValue(r,s);let n=mutable_1.BuilderProvider.getSnapshotBuilder(i);return n.markPartitionAsUpdated(r,s),i=n.build(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),i,t).getAfterSs(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),i,t).getAfterSs(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),i,t).getAfterSs(),e.setRestoredSs(i),e.setRemainingSs(t),this.expiredMatches.remove(r),e}clearBin(e){this.expiredMatches.remove(e),this.ttlStatus.remove(e)}containData(e){return this.expiredMatches.containsKey(e)}getTtlConfig(){return this.ttlConfig}getFsRepo(){return this.fsRepo}getTtlRestoreSnapshot(e){let t=null;return this.ttlStatus.isEmpty()||(this.getGrp().DATA_RESET().id()==e.msgType().id()?e.data().getPartitions().forEach(e=>{console.log("Dropping partition "+e),this.expiredMatches.remove(e)}):e.data().getPartitionMap().forEach((r,s)=>{let i=[];this.ttlStatus.contains(r)&&(this.ttlStatus.remove(r),i.push(r)),i.length>0&&(t=new TTLRestoreCheck(this,i,e.stream()))})),t}getTtlRemoveSnapshot(){let e=this.getFsRepo().getTtlRemoveSnapshot();return e.forEach(e=>{e.setRecycleBin(this),e.getKeys().forEach(e=>{this.ttlStatus.add(e)})}),e}copyData(e,t){let r=this.expiredMatches.getValue(e);if(void 0===r)return t;let s=new data_structure_1.IndexedSnapshotImpl(t);return s=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),r,s).getAfterSs(),s=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),r,s).getAfterSs(),s=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),r,s).getAfterSs(),s.matchesSport}getGrp(){return this.grp}};RecycleBin=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[TTLConfig,message_class_1.SportsFeedMessageGroup,AbstractFSRepo])],RecycleBin),exports.RecycleBin=RecycleBin;
|