@jayesol/jayeson.lib.sports 2.2.7-beta1 → 2.2.7-beta3
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 -325
- 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 +7 -7
package/lib/receive.js
CHANGED
|
@@ -1,484 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.MergeableIncoming = exports.SportsFeedInProcessor = exports.StreamCommandProcessor = exports.InEndPointEventHandler = void 0;
|
|
39
|
-
const D = __importStar(require("@jayesol/jayeson.lib.delivery"));
|
|
40
|
-
const Collections = __importStar(require("typescript-collections"));
|
|
41
|
-
const core_1 = require("./core");
|
|
42
|
-
const message_class_1 = require("./message_class");
|
|
43
|
-
const merge_1 = require("./merge");
|
|
44
|
-
const data_structure_1 = require("./data_structure");
|
|
45
|
-
let circular = require("circular-json");
|
|
46
|
-
//imports required for dependency injection
|
|
47
|
-
require("reflect-metadata");
|
|
48
|
-
const injection_js_1 = require("injection-js");
|
|
49
|
-
const codec_1 = require("./codec");
|
|
50
|
-
let InEndPointEventHandler = class InEndPointEventHandler {
|
|
51
|
-
constructor(startMessage, sportsMsgGrp, streamNameCode) {
|
|
52
|
-
this._streamSources = {};
|
|
53
|
-
this._filterData = null;
|
|
54
|
-
//to be injected
|
|
55
|
-
this._startMessage = startMessage;
|
|
56
|
-
this._sportsMsgGrp = sportsMsgGrp;
|
|
57
|
-
this._streamNameCode = streamNameCode;
|
|
58
|
-
this._exclude = startMessage.exclude;
|
|
59
|
-
this._wireFormat = startMessage.wireFormat;
|
|
60
|
-
}
|
|
61
|
-
setfilterData(rule) {
|
|
62
|
-
this._filterData = rule;
|
|
63
|
-
}
|
|
64
|
-
streamSources() {
|
|
65
|
-
return this._streamSources;
|
|
66
|
-
}
|
|
67
|
-
exclude() {
|
|
68
|
-
return this._exclude;
|
|
69
|
-
}
|
|
70
|
-
wireFormat() {
|
|
71
|
-
return this._wireFormat;
|
|
72
|
-
}
|
|
73
|
-
startMessage() {
|
|
74
|
-
return this._startMessage;
|
|
75
|
-
}
|
|
76
|
-
sportsMsgGrp() {
|
|
77
|
-
return this._sportsMsgGrp;
|
|
78
|
-
}
|
|
79
|
-
streamNameCode() {
|
|
80
|
-
return this._streamNameCode;
|
|
81
|
-
}
|
|
82
|
-
filterData() {
|
|
83
|
-
return this._filterData;
|
|
84
|
-
}
|
|
85
|
-
onEvent(event) {
|
|
86
|
-
if (event instanceof D.Subscriber.Event.ConsumptionStart) {
|
|
87
|
-
for (let property in event.streams) {
|
|
88
|
-
if (event.streams.hasOwnProperty(property)) {
|
|
89
|
-
for (let i = 0; i < event.streams[property].length; i++) {
|
|
90
|
-
let grpId = parseInt(property);
|
|
91
|
-
//only connect to sports streams
|
|
92
|
-
if (grpId == this.sportsMsgGrp().id()) {
|
|
93
|
-
//set end point mapping.
|
|
94
|
-
let streamId = event.streams[property][i];
|
|
95
|
-
this._streamSources[streamId] = event.endPoint;
|
|
96
|
-
//send filter
|
|
97
|
-
let filterRequest = new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID, this.filterData());
|
|
98
|
-
this.sendFilter(filterRequest, streamId);
|
|
99
|
-
//send start message
|
|
100
|
-
console.log("Sending Start Message to stream : '" + streamId + "'");
|
|
101
|
-
let mw = new D.MessageWrapper(this._startMessage, this._sportsMsgGrp.ADMIN_START_SUBSCRIBE_FEED());
|
|
102
|
-
this.sendMessage(streamId, mw);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (event instanceof D.Subscriber.Event.ConsumptionError) {
|
|
109
|
-
let logMessage = event.client.config.url + " has errors on consumption: ";
|
|
110
|
-
for (let property in event.streams) {
|
|
111
|
-
if (event.streams.hasOwnProperty(property)) {
|
|
112
|
-
logMessage += "\n" + property + ":[";
|
|
113
|
-
for (let i = 0; i < event.streams[property].length; i++) {
|
|
114
|
-
logMessage += event.streams[property][i] + ",";
|
|
115
|
-
}
|
|
116
|
-
logMessage = logMessage.substring(1, logMessage.length - 1);
|
|
117
|
-
logMessage += "]";
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
console.log(logMessage);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
console.log("Unidentified event received by onEvent: " + circular.stringify(event));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
sendMessage(streamId, mw) {
|
|
127
|
-
//Append Stream name as meta info
|
|
128
|
-
mw.addMetaInfo(this._streamNameCode.code(), streamId);
|
|
129
|
-
//Get EndPoint to corresponding to this stream
|
|
130
|
-
let ep = this._streamSources[streamId];
|
|
131
|
-
//If EndPoint is not present, no action
|
|
132
|
-
if (ep == null) {
|
|
133
|
-
console.log("No Endpoint present corresponding to stream '" + streamId + "'. Unable to send message");
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
ep.send(mw);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
updateFilter(filterRequest) {
|
|
140
|
-
this._filterData = filterRequest.getFilterData();
|
|
141
|
-
this.sendFilter(filterRequest);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Sends filter to server
|
|
145
|
-
* @param streamId - sends filter for a particular streamId
|
|
146
|
-
* if null, sends filter for all stream ids
|
|
147
|
-
*/
|
|
148
|
-
sendFilter(filterRequest, streamId = null) {
|
|
149
|
-
if (streamId !== null) {
|
|
150
|
-
this._sendFilter(filterRequest, streamId);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
for (let streamId in this._streamSources) {
|
|
154
|
-
if (this._streamSources.hasOwnProperty(streamId)) {
|
|
155
|
-
this._sendFilter(filterRequest, streamId);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
_sendFilter(filterRequest, streamId) {
|
|
161
|
-
let filterData = filterRequest.getFilterData();
|
|
162
|
-
let mw = null;
|
|
163
|
-
if (filterData != null) {
|
|
164
|
-
mw = new D.MessageWrapper(filterRequest, this._sportsMsgGrp.FILTER_SET());
|
|
165
|
-
console.log("Sending FILTER_SET to stream: '" + streamId + "' with filter data: " + JSON.stringify(filterData));
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
mw = new D.MessageWrapper(filterRequest.getRequestId().toString(), this._sportsMsgGrp.FILTER_REMOVE());
|
|
169
|
-
console.log("Sending FILTER_REMOVE to stream: '" + streamId + "'");
|
|
170
|
-
}
|
|
171
|
-
this.sendMessage(streamId, mw);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
InEndPointEventHandler = __decorate([
|
|
175
|
-
(0, injection_js_1.Injectable)(),
|
|
176
|
-
__metadata("design:paramtypes", [message_class_1.StartSubscribeFeed, message_class_1.SportsFeedMessageGroup, D.StreamNameCode])
|
|
177
|
-
], InEndPointEventHandler);
|
|
178
|
-
exports.InEndPointEventHandler = InEndPointEventHandler;
|
|
179
|
-
let StreamCommandProcessor = class StreamCommandProcessor {
|
|
180
|
-
constructor(_fsRepo, _sportsGrp) {
|
|
181
|
-
this._fsRepo = _fsRepo;
|
|
182
|
-
this._sportsGrp = _sportsGrp;
|
|
183
|
-
this.messageClassName = {
|
|
184
|
-
0: 'DATA_RESET',
|
|
185
|
-
1: 'DATA_INSERT_ODD',
|
|
186
|
-
2: 'DATA_UPDATE_ODD',
|
|
187
|
-
3: 'DATA_DELETE_ODD',
|
|
188
|
-
4: 'DATA_INSERT_EVENT',
|
|
189
|
-
5: 'DATA_UPDATE_EVENT',
|
|
190
|
-
6: 'DATA_DELETE_EVENT',
|
|
191
|
-
7: 'DATA_INSERT_MATCH',
|
|
192
|
-
8: 'DATA_UPDATE_MATCH',
|
|
193
|
-
9: 'DATA_DELETE_MATCH',
|
|
194
|
-
10: 'TTL_REMOVE',
|
|
195
|
-
11: 'TTL_RESTORE',
|
|
196
|
-
13: 'FILTER_REMOVE',
|
|
197
|
-
14: 'FILTER_SET',
|
|
198
|
-
16: 'ADMIN_START_SUBSCRIBE_FEED',
|
|
199
|
-
17: 'ADMIN_REFRESH'
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
//bypass the append snapshot call if overwrite is provided
|
|
203
|
-
process(stream, input, overwrite = null) {
|
|
204
|
-
//see what message
|
|
205
|
-
if (input != null && input instanceof data_structure_1.Incoming) {
|
|
206
|
-
let ss = input;
|
|
207
|
-
let className = this.messageClassName[ss.msgType().id()];
|
|
208
|
-
console.debug("SCP processing: " + className);
|
|
209
|
-
}
|
|
210
|
-
if (overwrite == null) {
|
|
211
|
-
let outgoing = this._fsRepo.appendSnapshot(stream, input);
|
|
212
|
-
for (let o of outgoing) {
|
|
213
|
-
//this.printMessage(o);
|
|
214
|
-
this._fsRepo.push(o);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
//bypass appending to snapshot
|
|
219
|
-
this._fsRepo.push(overwrite);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
fsRepo() {
|
|
223
|
-
return this._fsRepo;
|
|
224
|
-
}
|
|
225
|
-
sportsGrp() {
|
|
226
|
-
return this._sportsGrp;
|
|
227
|
-
}
|
|
228
|
-
printMessage(outgoing) {
|
|
229
|
-
//print partition keys
|
|
230
|
-
let className = this.getClassName(outgoing);
|
|
231
|
-
let snapshot = outgoing.delta();
|
|
232
|
-
this.printPartitionKeys(className, snapshot);
|
|
233
|
-
//print contents
|
|
234
|
-
let id = outgoing.msgType().id();
|
|
235
|
-
switch (id) {
|
|
236
|
-
case this._sportsGrp.DATA_INSERT_MATCH().id():
|
|
237
|
-
case this._sportsGrp.DATA_UPDATE_MATCH().id():
|
|
238
|
-
case this._sportsGrp.DATA_DELETE_MATCH().id():
|
|
239
|
-
this.printMatch(className, snapshot);
|
|
240
|
-
break;
|
|
241
|
-
case this._sportsGrp.DATA_INSERT_ODD().id():
|
|
242
|
-
case this._sportsGrp.DATA_UPDATE_ODD().id():
|
|
243
|
-
case this._sportsGrp.DATA_DELETE_ODD().id():
|
|
244
|
-
this.printRecord(className, snapshot);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
getClassName(outgoing) {
|
|
249
|
-
if (!(outgoing instanceof core_1.TTLOutgoing)) {
|
|
250
|
-
return this.messageClassName[outgoing.msgType().id()];
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
let TTLOutgoing = outgoing;
|
|
254
|
-
if (TTLOutgoing.getTtlType() == core_1.TTLType.REMOVE) {
|
|
255
|
-
return "TTL_REM";
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
return "TTL_RES";
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
printMatch(identifier, snapshot) {
|
|
263
|
-
let matches = snapshot.matches();
|
|
264
|
-
for (let i = 0; i < matches.length; i++) {
|
|
265
|
-
console.log(`[${identifier}] ${matches[i].id()}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
printRecord(identifier, snapshot) {
|
|
269
|
-
let matches = snapshot.matches();
|
|
270
|
-
for (let i = 0; i < matches.length; i++) {
|
|
271
|
-
let events = matches[i].events();
|
|
272
|
-
for (let j = 0; j < events.length; j++) {
|
|
273
|
-
let records = events[j].records();
|
|
274
|
-
for (let k = 0; k < records.length; k++) {
|
|
275
|
-
let rec = records[k];
|
|
276
|
-
console.log(`[${identifier}] ${rec.matchId()}_${rec.eventId()}_${rec.id()}_${rec.source()}_${rec.oddType()}_${rec.oddFormat()}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
printPartitionKeys(identifier, snapshot) {
|
|
282
|
-
let partitionsString = snapshot.getPartitions().toString();
|
|
283
|
-
console.log(`[${identifier}][PK]${partitionsString}`);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
StreamCommandProcessor = __decorate([
|
|
287
|
-
(0, injection_js_1.Injectable)(),
|
|
288
|
-
__param(0, (0, injection_js_1.Inject)(core_1.FSREPO_IMPL)),
|
|
289
|
-
__metadata("design:paramtypes", [Object, message_class_1.SportsFeedMessageGroup])
|
|
290
|
-
], StreamCommandProcessor);
|
|
291
|
-
exports.StreamCommandProcessor = StreamCommandProcessor;
|
|
292
|
-
let SportsFeedInProcessor = class SportsFeedInProcessor extends D.IMessageGroupProcessor {
|
|
293
|
-
constructor(scp, sportsFeedMsgGroup, snCode, recycleBin) {
|
|
294
|
-
super(sportsFeedMsgGroup);
|
|
295
|
-
this.scp = scp;
|
|
296
|
-
this.sportsFeedMsgGroup = sportsFeedMsgGroup;
|
|
297
|
-
this.snCode = snCode;
|
|
298
|
-
this.recycleBin = recycleBin;
|
|
299
|
-
}
|
|
300
|
-
process(mw) {
|
|
301
|
-
//validate stream name
|
|
302
|
-
let streamName = mw.getMetaInfo(this.snCode.code());
|
|
303
|
-
if (streamName == null || streamName === "") {
|
|
304
|
-
console.log("SportsFeedInProcessor received messagewrapper with no StreamName. Ignoring.");
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
if (!this.isFeedMessage(mw)) {
|
|
308
|
-
console.log("SportsFeedInProcessor received unknown messageclass: " + circular.stringify(mw.messageClass) + ". Ignoring");
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
if (this.sportsFeedMsgGroup.isIndicatorMessage(mw.messageClass)) {
|
|
312
|
-
let outgoing = this.processIndicatorMessage(mw);
|
|
313
|
-
this.scp.process(streamName, null, outgoing);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
let incoming = new MergeableIncoming(this.sportsFeedMsgGroup, mw.messageClass, streamName, mw.message, this.recycleBin);
|
|
317
|
-
this.triggerTtlRestoreIfApplicable(incoming);
|
|
318
|
-
this.scp.process(incoming.stream(), incoming);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
processIndicatorMessage(mw) {
|
|
322
|
-
//clear RecycleBin for TTL_RESTORE_START
|
|
323
|
-
if (mw.messageClass == this.sportsFeedMsgGroup.TTL_RESTORE_START()) {
|
|
324
|
-
mw.message.getPartitions().forEach(partitionKey => {
|
|
325
|
-
this.recycleBin.clearBin(partitionKey);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
//generate outgoing message
|
|
329
|
-
let outgoing = new data_structure_1.OutgoingImpl(mw.messageClass, mw.message);
|
|
330
|
-
return outgoing;
|
|
331
|
-
}
|
|
332
|
-
triggerTtlRestoreIfApplicable(incomingMsg) {
|
|
333
|
-
if (this.getRecycleBin() != null) {
|
|
334
|
-
if (this.getRecycleBin().getTtlConfig() != null && this.getRecycleBin().getTtlConfig().isEnableTtl()) {
|
|
335
|
-
//check if TTLRestore is triggered for the incoming set of partition keys
|
|
336
|
-
let ttlRestore = this.getRecycleBin().getTtlRestoreSnapshot(incomingMsg);
|
|
337
|
-
//pass to SCP if there is TTLRestore
|
|
338
|
-
if (ttlRestore != null) {
|
|
339
|
-
this.scp.process(ttlRestore.getStream(), ttlRestore);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
triggerTtlRemove() {
|
|
345
|
-
if (this.getRecycleBin() != null) {
|
|
346
|
-
let removeSnapshotList = this.getRecycleBin().getTtlRemoveSnapshot();
|
|
347
|
-
removeSnapshotList.forEach(removeSS => {
|
|
348
|
-
this.scp.process(removeSS.getStream(), removeSS);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
startTtlVerification() {
|
|
353
|
-
if (this.getRecycleBin() != null) {
|
|
354
|
-
let ttlConfig = this.getRecycleBin().getTtlConfig();
|
|
355
|
-
if (ttlConfig != null && ttlConfig.isEnableTtl()) {
|
|
356
|
-
let runInterval = ttlConfig.getRunInterval();
|
|
357
|
-
setInterval(() => this.triggerTtlRemove(), runInterval);
|
|
358
|
-
console.log("Scheduled TTLCheck with interval of " + runInterval);
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
console.log("No TTL set. Not scheduling any TTL.");
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
isFeedMessage(mw) {
|
|
366
|
-
let msgCls = mw.messageClass;
|
|
367
|
-
if (msgCls instanceof message_class_1.InsertOddMessageClass || msgCls instanceof message_class_1.UpdateOddMessageClass
|
|
368
|
-
|| msgCls instanceof message_class_1.DeleteOddMessageClass || msgCls instanceof message_class_1.InsertEventMessageClass
|
|
369
|
-
|| msgCls instanceof message_class_1.UpdateEventMessageClass || msgCls instanceof message_class_1.DeleteEventMessageClass
|
|
370
|
-
|| msgCls instanceof message_class_1.InsertMatchMessageClass || msgCls instanceof message_class_1.UpdateMatchMessageClass
|
|
371
|
-
|| msgCls instanceof message_class_1.DeleteMatchMessageClass || msgCls instanceof message_class_1.RefreshMessageClass
|
|
372
|
-
|| msgCls instanceof message_class_1.TTLRemoveMessageClass || msgCls instanceof message_class_1.TTLRestoreMessageClass
|
|
373
|
-
|| msgCls instanceof message_class_1.ResetMessageClass || msgCls instanceof message_class_1.SwitchFilterStartMessageClass
|
|
374
|
-
|| msgCls instanceof message_class_1.SwitchFilterFailMessageClass
|
|
375
|
-
|| msgCls == this.sportsFeedMsgGroup.SWITCH_FILTER_START() || msgCls == this.sportsFeedMsgGroup.SWITCH_FILTER_END()
|
|
376
|
-
|| msgCls == this.sportsFeedMsgGroup.FULLSNAPSHOT_START() || msgCls == this.sportsFeedMsgGroup.FULLSNAPSHOT_END()
|
|
377
|
-
|| msgCls == this.sportsFeedMsgGroup.SWITCH_FILTER_FAIL()
|
|
378
|
-
|| msgCls == this.sportsFeedMsgGroup.TTL_RESTORE_START() || msgCls == this.sportsFeedMsgGroup.TTL_RESTORE_END()) {
|
|
379
|
-
return true;
|
|
380
|
-
}
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
getScp() {
|
|
384
|
-
return this.scp;
|
|
385
|
-
}
|
|
386
|
-
getRecycleBin() {
|
|
387
|
-
return this.recycleBin;
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
SportsFeedInProcessor = __decorate([
|
|
391
|
-
(0, injection_js_1.Injectable)(),
|
|
392
|
-
__metadata("design:paramtypes", [StreamCommandProcessor, message_class_1.SportsFeedMessageGroup, D.StreamNameCode, core_1.RecycleBin])
|
|
393
|
-
], SportsFeedInProcessor);
|
|
394
|
-
exports.SportsFeedInProcessor = SportsFeedInProcessor;
|
|
395
|
-
class MergeableIncoming extends data_structure_1.Incoming {
|
|
396
|
-
constructor(sportsGrp, snapshotType, streamName, data, bin) {
|
|
397
|
-
super(snapshotType, streamName, data);
|
|
398
|
-
this.sportsGrp = sportsGrp;
|
|
399
|
-
this.bin = bin;
|
|
400
|
-
}
|
|
401
|
-
apply(before) {
|
|
402
|
-
if (before == null) {
|
|
403
|
-
before = data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
|
|
404
|
-
}
|
|
405
|
-
let outgoCol = [];
|
|
406
|
-
this.beforeSnap = before;
|
|
407
|
-
let wrap = new data_structure_1.MergeableWrapper();
|
|
408
|
-
if (this.msgType() instanceof message_class_1.InsertMatchMessageClass || this.msgType() instanceof message_class_1.InsertEventMessageClass || this.msgType() instanceof message_class_1.DeleteMatchMessageClass || this.msgType() instanceof message_class_1.DeleteEventMessageClass || this.msgType() instanceof message_class_1.UpdateEventMessageClass) {
|
|
409
|
-
let msgBefore = merge_1.SnapshotUtil.combineSnapshots(this.msgType(), this.data(), before);
|
|
410
|
-
let incomeCol = merge_1.DeltaTransformingLogicImpl.transform(this.sportsGrp, this.stream(), this.msgType(), this.data(), msgBefore);
|
|
411
|
-
for (let i of incomeCol) {
|
|
412
|
-
let iDelta = new core_1.Delta(i, msgBefore.getAfterSs(), this.beforeSnap);
|
|
413
|
-
outgoCol.push(iDelta);
|
|
414
|
-
this.beforeSnap = msgBefore.getAfterSs();
|
|
415
|
-
}
|
|
416
|
-
wrap.setAfter(msgBefore.getAfterSs());
|
|
417
|
-
wrap.setDeltaOut(outgoCol);
|
|
418
|
-
}
|
|
419
|
-
else if (this.msgType() instanceof message_class_1.TTLRemoveMessageClass) {
|
|
420
|
-
let ttlWrapper = null;
|
|
421
|
-
let snapshot = before;
|
|
422
|
-
let keyRemoved = new Collections.Dictionary();
|
|
423
|
-
let ttlRemoveList = [];
|
|
424
|
-
let atleastOneKeyRemoved = false;
|
|
425
|
-
let allKeys = before.getPartitionMap();
|
|
426
|
-
for (let key of this.data().getPartitions().toArray()) {
|
|
427
|
-
console.log("removing keys from upstream " + JSON.stringify(key));
|
|
428
|
-
if (!allKeys.containsKey(key)) {
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
atleastOneKeyRemoved = true;
|
|
432
|
-
keyRemoved.setValue(key, allKeys.getValue(key));
|
|
433
|
-
ttlWrapper = this.bin.removeData(new data_structure_1.TTLWrapper(), snapshot, key);
|
|
434
|
-
snapshot = ttlWrapper.getRemainingSs();
|
|
435
|
-
ttlRemoveList.push(ttlWrapper.getRemovedSs());
|
|
436
|
-
}
|
|
437
|
-
if (atleastOneKeyRemoved) {
|
|
438
|
-
console.log("reseting ----->" + JSON.stringify(keyRemoved.keys()));
|
|
439
|
-
wrap = merge_1.DeltaTransformingLogicImpl.transformTTLRemove(ttlRemoveList, this.bin.getGrp(), this.stream(), before, snapshot, keyRemoved);
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
wrap.setDeltaOut([]);
|
|
443
|
-
wrap.setAfter(before);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
else if (this.msgType() instanceof message_class_1.TTLRestoreMessageClass) {
|
|
447
|
-
let ttlWrapper = null;
|
|
448
|
-
let snapshot = before;
|
|
449
|
-
let restoredKeys = new Collections.Dictionary();
|
|
450
|
-
let atleastOneKeyRestored = false;
|
|
451
|
-
let matches = {};
|
|
452
|
-
let ttlRestoreList = [];
|
|
453
|
-
for (let key of this.data().getPartitions().toArray()) {
|
|
454
|
-
console.log("restoring keys from upstream " + JSON.stringify(key));
|
|
455
|
-
if (this.bin.containData(key)) {
|
|
456
|
-
atleastOneKeyRestored = true;
|
|
457
|
-
let restoredTime = new Date().getTime();
|
|
458
|
-
restoredKeys.setValue(key, restoredTime);
|
|
459
|
-
matches = this.bin.copyData(key, matches);
|
|
460
|
-
ttlWrapper = this.bin.restoreData(new data_structure_1.TTLWrapper, snapshot, key, restoredTime);
|
|
461
|
-
snapshot = ttlWrapper.getRemainingSs();
|
|
462
|
-
ttlRestoreList.push(ttlWrapper.getRestoredSs());
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (atleastOneKeyRestored) {
|
|
466
|
-
console.log("restoring ----->" + JSON.stringify(restoredKeys.keys()));
|
|
467
|
-
wrap = merge_1.DeltaTransformingLogicImpl.transformTTLRestore(ttlRestoreList, this.bin.getGrp(), this.stream(), before, snapshot, matches, restoredKeys);
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
wrap.setAfter(before);
|
|
471
|
-
wrap.setDeltaOut([]);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
let msgBefore = merge_1.SnapshotUtil.combineSnapshots(this.msgType(), this.data(), before);
|
|
476
|
-
let iDelta = new core_1.Delta(this, msgBefore.getAfterSs(), before);
|
|
477
|
-
outgoCol.push(iDelta);
|
|
478
|
-
wrap.setDeltaOut(outgoCol);
|
|
479
|
-
wrap.setAfter(msgBefore.getAfterSs());
|
|
480
|
-
}
|
|
481
|
-
return wrap;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
exports.MergeableIncoming = MergeableIncoming;
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,s,t,r){void 0===r&&(r=t);var a=Object.getOwnPropertyDescriptor(s,t);a&&("get"in a?s.__esModule:!a.writable&&!a.configurable)||(a={enumerable:!0,get:function(){return s[t]}}),Object.defineProperty(e,r,a)}:function(e,s,t,r){e[r=void 0===r?t:r]=s[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,s){Object.defineProperty(e,"default",{enumerable:!0,value:s})}:function(e,s){e.default=s}),__decorate=this&&this.__decorate||function(e,s,t,r){var a,o=arguments.length,n=o<3?s:null===r?r=Object.getOwnPropertyDescriptor(s,t):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,s,t,r);else for(var i=e.length-1;0<=i;i--)(a=e[i])&&(n=(o<3?a(n):3<o?a(s,t,n):a(s,t))||n);return 3<o&&n&&Object.defineProperty(s,t,n),n},__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var s={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&__createBinding(s,e,t);return __setModuleDefault(s,e),s},__metadata=this&&this.__metadata||function(e,s){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,s)},__param=this&&this.__param||function(t,r){return function(e,s){r(e,s,t)}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MergeableIncoming=exports.SportsFeedInProcessor=exports.StreamCommandProcessor=exports.InEndPointEventHandler=void 0;let D=__importStar(require("@jayesol/jayeson.lib.delivery")),Collections=__importStar(require("typescript-collections")),core_1=require("./core"),message_class_1=require("./message_class"),merge_1=require("./merge"),data_structure_1=require("./data_structure"),circular=require("circular-json"),injection_js_1=(require("reflect-metadata"),require("injection-js")),codec_1=require("./codec"),InEndPointEventHandler=class{constructor(e,s,t){this._streamSources={},this._filterData=null,this._startMessage=e,this._sportsMsgGrp=s,this._streamNameCode=t,this._exclude=e.exclude,this._wireFormat=e.wireFormat}setfilterData(e){this._filterData=e}streamSources(){return this._streamSources}exclude(){return this._exclude}wireFormat(){return this._wireFormat}startMessage(){return this._startMessage}sportsMsgGrp(){return this._sportsMsgGrp}streamNameCode(){return this._streamNameCode}filterData(){return this._filterData}onEvent(t){if(t instanceof D.Subscriber.Event.ConsumptionStart){for(var s in t.streams)if(t.streams.hasOwnProperty(s))for(let e=0;e<t.streams[s].length;e++){var r,a;parseInt(s)==this.sportsMsgGrp().id()&&(r=t.streams[s][e],this._streamSources[r]=t.endPoint,a=new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID,this.filterData()),this.sendFilter(a,r),console.log("Sending Start Message to stream : '"+r+"'"),a=new D.MessageWrapper(this._startMessage,this._sportsMsgGrp.ADMIN_START_SUBSCRIBE_FEED()),this.sendMessage(r,a))}}else if(t instanceof D.Subscriber.Event.ConsumptionError){let s=t.client.config.url+" has errors on consumption: ";for(var o in t.streams)if(t.streams.hasOwnProperty(o)){s+="\n"+o+":[";for(let e=0;e<t.streams[o].length;e++)s+=t.streams[o][e]+",";s=s.substring(1,s.length-1),s+="]"}console.log(s)}else console.log("Unidentified event received by onEvent: "+circular.stringify(t))}sendMessage(e,s){s.addMetaInfo(this._streamNameCode.code(),e);var t=this._streamSources[e];null==t?console.log("No Endpoint present corresponding to stream '"+e+"'. Unable to send message"):t.send(s)}updateFilter(e){this._filterData=e.getFilterData(),this.sendFilter(e)}sendFilter(e,s=null){if(null!==s)this._sendFilter(e,s);else for(var t in this._streamSources)this._streamSources.hasOwnProperty(t)&&this._sendFilter(e,t)}_sendFilter(e,s){var t=e.getFilterData();let r=null;null!=t?(r=new D.MessageWrapper(e,this._sportsMsgGrp.FILTER_SET()),console.log("Sending FILTER_SET to stream: '"+s+"' with filter data: "+JSON.stringify(t))):(r=new D.MessageWrapper(e.getRequestId().toString(),this._sportsMsgGrp.FILTER_REMOVE()),console.log("Sending FILTER_REMOVE to stream: '"+s+"'")),this.sendMessage(s,r)}},StreamCommandProcessor=(InEndPointEventHandler=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[message_class_1.StartSubscribeFeed,message_class_1.SportsFeedMessageGroup,D.StreamNameCode])],InEndPointEventHandler),exports.InEndPointEventHandler=InEndPointEventHandler,class{constructor(e,s){this._fsRepo=e,this._sportsGrp=s,this.messageClassName={0:"DATA_RESET",1:"DATA_INSERT_ODD",2:"DATA_UPDATE_ODD",3:"DATA_DELETE_ODD",4:"DATA_INSERT_EVENT",5:"DATA_UPDATE_EVENT",6:"DATA_DELETE_EVENT",7:"DATA_INSERT_MATCH",8:"DATA_UPDATE_MATCH",9:"DATA_DELETE_MATCH",10:"TTL_REMOVE",11:"TTL_RESTORE",13:"FILTER_REMOVE",14:"FILTER_SET",16:"ADMIN_START_SUBSCRIBE_FEED",17:"ADMIN_REFRESH"}}process(e,s,t=null){var r,a;if(null!=s&&s instanceof data_structure_1.Incoming&&(r=this.messageClassName[s.msgType().id()],console.debug("SCP processing: "+r)),null==t)for(a of this._fsRepo.appendSnapshot(e,s))this._fsRepo.push(a);else this._fsRepo.push(t)}fsRepo(){return this._fsRepo}sportsGrp(){return this._sportsGrp}printMessage(e){var s=this.getClassName(e),t=e.delta(),e=(this.printPartitionKeys(s,t),e.msgType().id());switch(e){case this._sportsGrp.DATA_INSERT_MATCH().id():case this._sportsGrp.DATA_UPDATE_MATCH().id():case this._sportsGrp.DATA_DELETE_MATCH().id():this.printMatch(s,t);break;case this._sportsGrp.DATA_INSERT_ODD().id():case this._sportsGrp.DATA_UPDATE_ODD().id():case this._sportsGrp.DATA_DELETE_ODD().id():this.printRecord(s,t)}}getClassName(e){return e instanceof core_1.TTLOutgoing?e.getTtlType()==core_1.TTLType.REMOVE?"TTL_REM":"TTL_RES":this.messageClassName[e.msgType().id()]}printMatch(s,e){var t=e.matches();for(let e=0;e<t.length;e++)console.log(`[${s}] `+t[e].id())}printRecord(s,e){var t=e.matches();for(let e=0;e<t.length;e++){var r=t[e].events();for(let e=0;e<r.length;e++){var a=r[e].records();for(let e=0;e<a.length;e++){var o=a[e];console.log(`[${s}] ${o.matchId()}_${o.eventId()}_${o.id()}_${o.source()}_${o.oddType()}_`+o.oddFormat())}}}}printPartitionKeys(e,s){s=s.getPartitions().toString();console.log(`[${e}][PK]`+s)}}),SportsFeedInProcessor=(StreamCommandProcessor=__decorate([(0,injection_js_1.Injectable)(),__param(0,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup])],StreamCommandProcessor),exports.StreamCommandProcessor=StreamCommandProcessor,class extends D.IMessageGroupProcessor{constructor(e,s,t,r){super(s),this.scp=e,this.sportsFeedMsgGroup=s,this.snCode=t,this.recycleBin=r}process(e){var s,t=e.getMetaInfo(this.snCode.code());null==t||""===t?console.log("SportsFeedInProcessor received messagewrapper with no StreamName. Ignoring."):this.isFeedMessage(e)?this.sportsFeedMsgGroup.isIndicatorMessage(e.messageClass)?(s=this.processIndicatorMessage(e),this.scp.process(t,null,s)):(s=new MergeableIncoming(this.sportsFeedMsgGroup,e.messageClass,t,e.message,this.recycleBin),this.triggerTtlRestoreIfApplicable(s),this.scp.process(s.stream(),s)):console.log("SportsFeedInProcessor received unknown messageclass: "+circular.stringify(e.messageClass)+". Ignoring")}processIndicatorMessage(e){return e.messageClass==this.sportsFeedMsgGroup.TTL_RESTORE_START()&&e.message.getPartitions().forEach(e=>{this.recycleBin.clearBin(e)}),new data_structure_1.OutgoingImpl(e.messageClass,e.message)}triggerTtlRestoreIfApplicable(e){null!=this.getRecycleBin()&&null!=this.getRecycleBin().getTtlConfig()&&this.getRecycleBin().getTtlConfig().isEnableTtl()&&null!=(e=this.getRecycleBin().getTtlRestoreSnapshot(e))&&this.scp.process(e.getStream(),e)}triggerTtlRemove(){null!=this.getRecycleBin()&&this.getRecycleBin().getTtlRemoveSnapshot().forEach(e=>{this.scp.process(e.getStream(),e)})}startTtlVerification(){var e;null!=this.getRecycleBin()&&(null!=(e=this.getRecycleBin().getTtlConfig())&&e.isEnableTtl()?(e=e.getRunInterval(),setInterval(()=>this.triggerTtlRemove(),e),console.log("Scheduled TTLCheck with interval of "+e)):console.log("No TTL set. Not scheduling any TTL."))}isFeedMessage(e){e=e.messageClass;return e instanceof message_class_1.InsertOddMessageClass||e instanceof message_class_1.UpdateOddMessageClass||e instanceof message_class_1.DeleteOddMessageClass||e instanceof message_class_1.InsertEventMessageClass||e instanceof message_class_1.UpdateEventMessageClass||e instanceof message_class_1.DeleteEventMessageClass||e instanceof message_class_1.InsertMatchMessageClass||e instanceof message_class_1.UpdateMatchMessageClass||e instanceof message_class_1.DeleteMatchMessageClass||e instanceof message_class_1.RefreshMessageClass||e instanceof message_class_1.TTLRemoveMessageClass||e instanceof message_class_1.TTLRestoreMessageClass||e instanceof message_class_1.ResetMessageClass||e instanceof message_class_1.SwitchFilterStartMessageClass||e instanceof message_class_1.SwitchFilterFailMessageClass||e==this.sportsFeedMsgGroup.SWITCH_FILTER_START()||e==this.sportsFeedMsgGroup.SWITCH_FILTER_END()||e==this.sportsFeedMsgGroup.FULLSNAPSHOT_START()||e==this.sportsFeedMsgGroup.FULLSNAPSHOT_END()||e==this.sportsFeedMsgGroup.SWITCH_FILTER_FAIL()||e==this.sportsFeedMsgGroup.TTL_RESTORE_START()||e==this.sportsFeedMsgGroup.TTL_RESTORE_END()}getScp(){return this.scp}getRecycleBin(){return this.recycleBin}});SportsFeedInProcessor=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[StreamCommandProcessor,message_class_1.SportsFeedMessageGroup,D.StreamNameCode,core_1.RecycleBin])],SportsFeedInProcessor),exports.SportsFeedInProcessor=SportsFeedInProcessor;class MergeableIncoming extends data_structure_1.Incoming{constructor(e,s,t,r,a){super(s,t,r),this.sportsGrp=e,this.bin=a}apply(r){null==r&&(r=data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);var e=[];this.beforeSnap=r;let a=new data_structure_1.MergeableWrapper;if(this.msgType()instanceof message_class_1.InsertMatchMessageClass||this.msgType()instanceof message_class_1.InsertEventMessageClass||this.msgType()instanceof message_class_1.DeleteMatchMessageClass||this.msgType()instanceof message_class_1.DeleteEventMessageClass||this.msgType()instanceof message_class_1.UpdateEventMessageClass){var s,t=merge_1.SnapshotUtil.combineSnapshots(this.msgType(),this.data(),r);for(s of merge_1.DeltaTransformingLogicImpl.transform(this.sportsGrp,this.stream(),this.msgType(),this.data(),t)){var o=new core_1.Delta(s,t.getAfterSs(),this.beforeSnap);e.push(o),this.beforeSnap=t.getAfterSs()}a.setAfter(t.getAfterSs()),a.setDeltaOut(e)}else if(this.msgType()instanceof message_class_1.TTLRemoveMessageClass){var n=null;let e=r;var i=new Collections.Dictionary,l=[];let s=!1;var c,g=r.getPartitionMap();for(c of this.data().getPartitions().toArray())console.log("removing keys from upstream "+JSON.stringify(c)),g.containsKey(c)&&(s=!0,i.setValue(c,g.getValue(c)),n=this.bin.removeData(new data_structure_1.TTLWrapper,e,c),e=n.getRemainingSs(),l.push(n.getRemovedSs()));s?(console.log("reseting -----\x3e"+JSON.stringify(i.keys())),a=merge_1.DeltaTransformingLogicImpl.transformTTLRemove(l,this.bin.getGrp(),this.stream(),r,e,i)):(a.setDeltaOut([]),a.setAfter(r))}else if(this.msgType()instanceof message_class_1.TTLRestoreMessageClass){var _=null;let e=r;var p=new Collections.Dictionary;let s=!1,t={};var m,d,h=[];for(m of this.data().getPartitions().toArray())console.log("restoring keys from upstream "+JSON.stringify(m)),this.bin.containData(m)&&(s=!0,d=(new Date).getTime(),p.setValue(m,d),t=this.bin.copyData(m,t),_=this.bin.restoreData(new data_structure_1.TTLWrapper,e,m,d),e=_.getRemainingSs(),h.push(_.getRestoredSs()));s?(console.log("restoring -----\x3e"+JSON.stringify(p.keys())),a=merge_1.DeltaTransformingLogicImpl.transformTTLRestore(h,this.bin.getGrp(),this.stream(),r,e,t,p)):(a.setAfter(r),a.setDeltaOut([]))}else{var u=merge_1.SnapshotUtil.combineSnapshots(this.msgType(),this.data(),r),r=new core_1.Delta(this,u.getAfterSs(),r);e.push(r),a.setDeltaOut(e),a.setAfter(u.getAfterSs())}return a}}exports.MergeableIncoming=MergeableIncoming;
|