1 | import { Incoming, IndexedSnapshot, DeltaOutgoing, Outgoing } from "./data_structure";
|
2 | import * as D from "@jayesol/jayeson.lib.delivery";
|
3 | import * as Collections from 'typescript-collections';
|
4 | import * as T from 'ts-promise';
|
5 | import 'reflect-metadata';
|
6 | import { InjectionToken } from 'injection-js';
|
7 | import { PartitionKey, IBetMatch } from "@jayesol/jayeson.lib.record";
|
8 | import { SportsFeedMessageGroup } from "./message_class";
|
9 | import { MergeableWrapper, TTLWrapper } from "./data_structure";
|
10 | export interface ISnapshotHandler {
|
11 | process(streamName: string, snapshot: Outgoing): void;
|
12 | toString(): string;
|
13 | }
|
14 | export interface FSRepo {
|
15 | appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[];
|
16 | getSnapshot(streamName: string): IndexedSnapshot;
|
17 | registerSnapshotHandler(ssHandler: ISnapshotHandler): void;
|
18 | deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void;
|
19 | getRegisteredHandlers(): ISnapshotHandler[];
|
20 | push(outgoing: Outgoing): void;
|
21 | isReady(stream: string): T.Promise<Boolean>;
|
22 | }
|
23 | export declare const FSREPO_IMPL: InjectionToken<FSRepo>;
|
24 | export declare abstract class AbstractFSRepo implements FSRepo {
|
25 | abstract getTtlRemoveSnapshot(): TTLRemoveCheck[];
|
26 | protected _handlers: Collections.Set<ISnapshotHandler>;
|
27 | constructor();
|
28 | handlers(): Collections.Set<ISnapshotHandler>;
|
29 | appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[];
|
30 | getSnapshot(streamName: string): IndexedSnapshot;
|
31 | registerSnapshotHandler(ssHandler: ISnapshotHandler): void;
|
32 | deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void;
|
33 | getRegisteredHandlers(): ISnapshotHandler[];
|
34 | push(outgoing: Outgoing): void;
|
35 | isReady(stream: string): T.Promise<Boolean>;
|
36 | }
|
37 | export declare class FSRepoImpl extends AbstractFSRepo implements FSRepo {
|
38 | outputStreamName: string;
|
39 | private sportsGroup;
|
40 | private _head;
|
41 | static outputStream: InjectionToken<string>;
|
42 | private fssEndReceived;
|
43 | private result;
|
44 | private promiseResolver;
|
45 | private promiseRejector;
|
46 | constructor(outputStreamName: string, sportsGroup: SportsFeedMessageGroup);
|
47 | head(): IndexedSnapshot;
|
48 | appendSnapshot(stream: string, logic: Mergeable): DeltaOutgoing[];
|
49 | getSnapshot(streamName?: string): IndexedSnapshot;
|
50 | getTtlRemoveSnapshot(): TTLRemoveCheck[];
|
51 | push(outgoing: Outgoing): void;
|
52 | isReady(stream: string): T.Promise<Boolean>;
|
53 | }
|
54 | export declare class Delta implements DeltaOutgoing {
|
55 | private _incoming;
|
56 | private _after;
|
57 | private _before;
|
58 | constructor(_incoming: Incoming, _after: IndexedSnapshot, _before: IndexedSnapshot);
|
59 | incoming(): Incoming;
|
60 | msgType(): D.IMessageClass;
|
61 | after(): IndexedSnapshot;
|
62 | delta(): IndexedSnapshot;
|
63 | before(): IndexedSnapshot;
|
64 | }
|
65 | export interface Mergeable {
|
66 | apply(before: IndexedSnapshot): MergeableWrapper;
|
67 | }
|
68 | export declare class TTLConfig {
|
69 | private livettl;
|
70 | private todayttl;
|
71 | private earlyttl;
|
72 | private enableTtl;
|
73 | getLivettl(): number;
|
74 | setLivettl(livettl: number): void;
|
75 | getTodayttl(): number;
|
76 | setTodayttl(todayttl: number): void;
|
77 | getEarlyttl(): number;
|
78 | setEarlyttl(earlyttl: number): void;
|
79 | getRunInterval(): number;
|
80 | isEnableTtl(): boolean;
|
81 | setEnableTtl(enableTtl: boolean): void;
|
82 | }
|
83 | export declare enum TTLType {
|
84 | REMOVE = 0,
|
85 | RESTORE = 1
|
86 | }
|
87 | export declare class TTLOutgoing extends Delta implements DeltaOutgoing {
|
88 | private readonly ttlType;
|
89 | constructor(ttlType: TTLType, incoming: Incoming, after: IndexedSnapshot, before: IndexedSnapshot);
|
90 | getTtlType(): TTLType;
|
91 | }
|
92 | export declare abstract class TTLCheck implements Mergeable {
|
93 | private readonly ttlType;
|
94 | private recycleBin;
|
95 | private readonly keys;
|
96 | private readonly stream;
|
97 | constructor(ttlType: TTLType, recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
|
98 | getKeys(): PartitionKey[];
|
99 | getKeysMapping(): Collections.Dictionary<PartitionKey, number>;
|
100 | getTtlType(): TTLType;
|
101 | getRecycleBin(): RecycleBin;
|
102 | setRecycleBin(recycleBin: RecycleBin): void;
|
103 | getStream(): string;
|
104 | abstract apply(before: IndexedSnapshot): MergeableWrapper;
|
105 | }
|
106 | export declare class TTLRestoreCheck extends TTLCheck {
|
107 | private ttlRestoreWrapper;
|
108 | private transformingLogic;
|
109 | constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
|
110 | apply(before: IndexedSnapshot): MergeableWrapper;
|
111 | }
|
112 | export declare class TTLRemoveCheck extends TTLCheck {
|
113 | private ttlRemoveWrapper;
|
114 | constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
|
115 | apply(before: IndexedSnapshot): MergeableWrapper;
|
116 | }
|
117 | export declare class RecycleBin {
|
118 | private ttlConfig;
|
119 | private grp;
|
120 | private fsRepo;
|
121 | private expiredMatches;
|
122 | private ttlStatus;
|
123 | constructor(ttlConfig: TTLConfig, grp: SportsFeedMessageGroup, fsRepo: AbstractFSRepo);
|
124 | /**
|
125 | * Remove the data for a given PartitionKey from a snapshot and return the
|
126 | * modified snapshot. The removed data will be stored in this recycle bin.
|
127 | *
|
128 | * @param snapshot
|
129 | * @param key
|
130 | */
|
131 | removeData(ttlRemoveWrapper: TTLWrapper, snapshot: IndexedSnapshot, key: PartitionKey): TTLWrapper;
|
132 | /**
|
133 | * Retrieves the data in this bin with given PartitionKey and combine it with
|
134 | * the given snapshot.
|
135 | *
|
136 | * @param parent
|
137 | * @param key
|
138 | */
|
139 | restoreData(ttlRestore: TTLWrapper, parent: IndexedSnapshot, key: PartitionKey, restoreTime: number): TTLWrapper;
|
140 | clearBin(key: PartitionKey): void;
|
141 | containData(key: PartitionKey): boolean;
|
142 | getTtlConfig(): TTLConfig;
|
143 | getFsRepo(): AbstractFSRepo;
|
144 | getTtlRestoreSnapshot(incoming: Incoming): TTLRestoreCheck;
|
145 | getTtlRemoveSnapshot(): TTLRemoveCheck[];
|
146 | /**
|
147 | * Copies the data in this RecycleBin related to the given PartitionKey into the
|
148 | * list of matches.
|
149 | *
|
150 | * @param key
|
151 | * @param matches
|
152 | */
|
153 | copyData(key: PartitionKey, matches: {
|
154 | [sport: number]: IBetMatch[];
|
155 | }): {
|
156 | [sport: number]: IBetMatch[];
|
157 | };
|
158 | getGrp(): SportsFeedMessageGroup;
|
159 | }
|