@jayesol/jayeson.lib.sports 2.2.6 → 2.2.7
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.d.ts +11 -0
- package/lib/basketball_codec.js +209 -0
- package/lib/client.d.ts +202 -0
- package/lib/client.js +686 -0
- package/lib/codec.d.ts +57 -0
- package/lib/codec.js +129 -0
- package/lib/core.d.ts +159 -0
- package/lib/core.js +497 -0
- package/lib/data_structure.d.ts +113 -0
- package/lib/data_structure.js +208 -0
- package/lib/dispatch.d.ts +126 -0
- package/lib/dispatch.js +324 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +27 -0
- package/lib/merge.d.ts +33 -0
- package/lib/merge.js +569 -0
- package/lib/message_class.d.ts +152 -0
- package/lib/message_class.js +466 -0
- package/lib/module.d.ts +12 -0
- package/lib/module.js +87 -0
- package/lib/mutable.d.ts +118 -0
- package/lib/mutable.js +1061 -0
- package/lib/protobuf_bundle.d.ts +3210 -0
- package/lib/protobuf_bundle.js +9683 -0
- package/lib/receive.d.ts +88 -0
- package/lib/receive.js +484 -0
- package/lib/soccer_codec.d.ts +13 -0
- package/lib/soccer_codec.js +168 -0
- package/lib/tennis_codec.d.ts +13 -0
- package/lib/tennis_codec.js +177 -0
- package/package.json +1 -1
package/lib/core.js
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
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;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as Collections from 'typescript-collections';
|
|
2
|
+
import { IMessageClass } from "@jayesol/jayeson.lib.delivery";
|
|
3
|
+
import { ISnapshot, Snapshot, PartitionKey, IBetMatch } from "@jayesol/jayeson.lib.record";
|
|
4
|
+
export declare class Incoming {
|
|
5
|
+
private _msgType;
|
|
6
|
+
private _stream;
|
|
7
|
+
private _data;
|
|
8
|
+
constructor(_msgType: IMessageClass, _stream: string, _data: IndexedSnapshot);
|
|
9
|
+
msgType(): IMessageClass;
|
|
10
|
+
stream(): string;
|
|
11
|
+
data(): IndexedSnapshot;
|
|
12
|
+
}
|
|
13
|
+
export interface IndexedSnapshot extends ISnapshot<IBetMatch> {
|
|
14
|
+
getPartitions(): Collections.Set<PartitionKey>;
|
|
15
|
+
getPartitionMap(): Collections.Dictionary<PartitionKey, number>;
|
|
16
|
+
}
|
|
17
|
+
export declare class IndexedSnapshotImpl extends Snapshot<IBetMatch> implements IndexedSnapshot {
|
|
18
|
+
private partitions;
|
|
19
|
+
static EMPTY_SNAPSHOT: IndexedSnapshotImpl;
|
|
20
|
+
constructor(matches?: {
|
|
21
|
+
[sport: number]: IBetMatch[];
|
|
22
|
+
}, partitions?: Collections.Dictionary<PartitionKey, number>);
|
|
23
|
+
getPartitions(): Collections.Set<PartitionKey>;
|
|
24
|
+
getPartitionMap(): Collections.Dictionary<PartitionKey, number>;
|
|
25
|
+
}
|
|
26
|
+
export interface Outgoing {
|
|
27
|
+
msgType(): IMessageClass;
|
|
28
|
+
}
|
|
29
|
+
export interface DeltaOutgoing extends Outgoing {
|
|
30
|
+
/**
|
|
31
|
+
* Indexed snapshot after Merge
|
|
32
|
+
*/
|
|
33
|
+
after(): IndexedSnapshot;
|
|
34
|
+
/**
|
|
35
|
+
* Contents of this Delta
|
|
36
|
+
*/
|
|
37
|
+
delta(): IndexedSnapshot;
|
|
38
|
+
/**
|
|
39
|
+
* Indexed Snapshot before Merge
|
|
40
|
+
*/
|
|
41
|
+
before(): IndexedSnapshot;
|
|
42
|
+
}
|
|
43
|
+
export declare class OutgoingImpl implements Outgoing {
|
|
44
|
+
private _msgType;
|
|
45
|
+
private _msg;
|
|
46
|
+
constructor(_msgType: IMessageClass, _msg: any);
|
|
47
|
+
msgType(): IMessageClass;
|
|
48
|
+
msg(): any;
|
|
49
|
+
}
|
|
50
|
+
export declare class DeltaOutgoingImpl extends OutgoingImpl implements DeltaOutgoing {
|
|
51
|
+
private _delta;
|
|
52
|
+
private _after?;
|
|
53
|
+
private _before?;
|
|
54
|
+
constructor(_msgType: IMessageClass, _delta: IndexedSnapshot, _after?: IndexedSnapshot, _before?: IndexedSnapshot);
|
|
55
|
+
after(): IndexedSnapshot;
|
|
56
|
+
delta(): IndexedSnapshot;
|
|
57
|
+
before(): IndexedSnapshot;
|
|
58
|
+
}
|
|
59
|
+
export declare class MessageBeforeTransform {
|
|
60
|
+
private transformEvent;
|
|
61
|
+
private insertEvent;
|
|
62
|
+
private deleteEvent;
|
|
63
|
+
private suppressMatch;
|
|
64
|
+
private insertMatch;
|
|
65
|
+
private deleteMatch;
|
|
66
|
+
private afterSs;
|
|
67
|
+
private beforeSs;
|
|
68
|
+
constructor();
|
|
69
|
+
getTransformEvent(): string[];
|
|
70
|
+
setTransformEvent(eventId: string): void;
|
|
71
|
+
getSuppressMatch(): string[];
|
|
72
|
+
setSuppressMatch(matchId: string): void;
|
|
73
|
+
setAfterSs(afterSs: IndexedSnapshot): void;
|
|
74
|
+
getAfterSs(): IndexedSnapshot;
|
|
75
|
+
setBeforeSs(beforeSs: IndexedSnapshot): void;
|
|
76
|
+
getBeforeSs(): IndexedSnapshot;
|
|
77
|
+
setInsertEvent(eventId: string): void;
|
|
78
|
+
getInsertEvent(): string[];
|
|
79
|
+
setDeleteEvent(eventId: string): void;
|
|
80
|
+
getDeleteEvent(): string[];
|
|
81
|
+
setInsertMatch(matchId: string): void;
|
|
82
|
+
getInsertMatch(): string[];
|
|
83
|
+
setDeleteMatch(matchId: string): void;
|
|
84
|
+
getDeleteMatch(): string[];
|
|
85
|
+
}
|
|
86
|
+
export declare enum ConvertedMsg {
|
|
87
|
+
INSERT_EVENT_TO_UPDATE = 0,
|
|
88
|
+
DELETE_EVENT_TO_UPDATE = 1,
|
|
89
|
+
INSERT_MATCH_SUPPRESS = 2,
|
|
90
|
+
DELETE_MATCH_SUPPRESS = 3,
|
|
91
|
+
ORIGINAL = 4
|
|
92
|
+
}
|
|
93
|
+
export declare class MergeableWrapper {
|
|
94
|
+
private deltaOut;
|
|
95
|
+
private snap;
|
|
96
|
+
constructor();
|
|
97
|
+
setDeltaOut(out: DeltaOutgoing[]): void;
|
|
98
|
+
setAfter(after: IndexedSnapshot): void;
|
|
99
|
+
getDeltaOut(): DeltaOutgoing[];
|
|
100
|
+
getAfter(): IndexedSnapshot;
|
|
101
|
+
}
|
|
102
|
+
export declare class TTLWrapper {
|
|
103
|
+
private removedSs;
|
|
104
|
+
private remainingSs;
|
|
105
|
+
private restoredSs;
|
|
106
|
+
_RemovedKey(): void;
|
|
107
|
+
setRemovedSs(remove: IndexedSnapshot): void;
|
|
108
|
+
getRemovedSs(): IndexedSnapshot;
|
|
109
|
+
setRemainingSs(remain: IndexedSnapshot): void;
|
|
110
|
+
getRemainingSs(): IndexedSnapshot;
|
|
111
|
+
getRestoredSs(): IndexedSnapshot;
|
|
112
|
+
setRestoredSs(restore: IndexedSnapshot): void;
|
|
113
|
+
}
|