import { Incoming, IndexedSnapshot, DeltaOutgoing, Outgoing } from "./data_structure"; import * as D from "@jayesol/jayeson.lib.delivery"; import * as Collections from 'typescript-collections'; import * as T from 'ts-promise'; import 'reflect-metadata'; import { InjectionToken } from 'injection-js'; import { PartitionKey, IBetMatch } from "@jayesol/jayeson.lib.record"; import { SportsFeedMessageGroup } from "./message_class"; import { MergeableWrapper, TTLWrapper } from "./data_structure"; export interface ISnapshotHandler { process(streamName: string, snapshot: Outgoing): void; toString(): string; } export interface FSRepo { appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[]; getSnapshot(streamName: string): IndexedSnapshot; registerSnapshotHandler(ssHandler: ISnapshotHandler): void; deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void; getRegisteredHandlers(): ISnapshotHandler[]; push(outgoing: Outgoing): void; isReady(stream: string): T.Promise; } export declare const FSREPO_IMPL: InjectionToken; export declare abstract class AbstractFSRepo implements FSRepo { abstract getTtlRemoveSnapshot(): TTLRemoveCheck[]; protected _handlers: Collections.Set; constructor(); handlers(): Collections.Set; appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[]; getSnapshot(streamName: string): IndexedSnapshot; registerSnapshotHandler(ssHandler: ISnapshotHandler): void; deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void; getRegisteredHandlers(): ISnapshotHandler[]; push(outgoing: Outgoing): void; isReady(stream: string): T.Promise; } export declare class FSRepoImpl extends AbstractFSRepo implements FSRepo { outputStreamName: string; private sportsGroup; private _head; static outputStream: InjectionToken; private fssEndReceived; private result; private promiseResolver; private promiseRejector; constructor(outputStreamName: string, sportsGroup: SportsFeedMessageGroup); head(): IndexedSnapshot; appendSnapshot(stream: string, logic: Mergeable): DeltaOutgoing[]; getSnapshot(streamName?: string): IndexedSnapshot; getTtlRemoveSnapshot(): TTLRemoveCheck[]; push(outgoing: Outgoing): void; isReady(stream: string): T.Promise; } export declare class Delta implements DeltaOutgoing { private _incoming; private _after; private _before; constructor(_incoming: Incoming, _after: IndexedSnapshot, _before: IndexedSnapshot); incoming(): Incoming; msgType(): D.IMessageClass; after(): IndexedSnapshot; delta(): IndexedSnapshot; before(): IndexedSnapshot; } export interface Mergeable { apply(before: IndexedSnapshot): MergeableWrapper; } export declare class TTLConfig { private livettl; private todayttl; private earlyttl; private enableTtl; getLivettl(): number; setLivettl(livettl: number): void; getTodayttl(): number; setTodayttl(todayttl: number): void; getEarlyttl(): number; setEarlyttl(earlyttl: number): void; getRunInterval(): number; isEnableTtl(): boolean; setEnableTtl(enableTtl: boolean): void; } export declare enum TTLType { REMOVE = 0, RESTORE = 1 } export declare class TTLOutgoing extends Delta implements DeltaOutgoing { private readonly ttlType; constructor(ttlType: TTLType, incoming: Incoming, after: IndexedSnapshot, before: IndexedSnapshot); getTtlType(): TTLType; } export declare abstract class TTLCheck implements Mergeable { private readonly ttlType; private recycleBin; private readonly keys; private readonly stream; constructor(ttlType: TTLType, recycleBin: RecycleBin, keys: PartitionKey[], stream: string); getKeys(): PartitionKey[]; getKeysMapping(): Collections.Dictionary; getTtlType(): TTLType; getRecycleBin(): RecycleBin; setRecycleBin(recycleBin: RecycleBin): void; getStream(): string; abstract apply(before: IndexedSnapshot): MergeableWrapper; } export declare class TTLRestoreCheck extends TTLCheck { private ttlRestoreWrapper; private transformingLogic; constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string); apply(before: IndexedSnapshot): MergeableWrapper; } export declare class TTLRemoveCheck extends TTLCheck { private ttlRemoveWrapper; constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string); apply(before: IndexedSnapshot): MergeableWrapper; } export declare class RecycleBin { private ttlConfig; private grp; private fsRepo; private expiredMatches; private ttlStatus; constructor(ttlConfig: TTLConfig, grp: SportsFeedMessageGroup, fsRepo: AbstractFSRepo); /** * Remove the data for a given PartitionKey from a snapshot and return the * modified snapshot. The removed data will be stored in this recycle bin. * * @param snapshot * @param key */ removeData(ttlRemoveWrapper: TTLWrapper, snapshot: IndexedSnapshot, key: PartitionKey): TTLWrapper; /** * Retrieves the data in this bin with given PartitionKey and combine it with * the given snapshot. * * @param parent * @param key */ restoreData(ttlRestore: TTLWrapper, parent: IndexedSnapshot, key: PartitionKey, restoreTime: number): TTLWrapper; clearBin(key: PartitionKey): void; containData(key: PartitionKey): boolean; getTtlConfig(): TTLConfig; getFsRepo(): AbstractFSRepo; getTtlRestoreSnapshot(incoming: Incoming): TTLRestoreCheck; getTtlRemoveSnapshot(): TTLRemoveCheck[]; /** * Copies the data in this RecycleBin related to the given PartitionKey into the * list of matches. * * @param key * @param matches */ copyData(key: PartitionKey, matches: { [sport: number]: IBetMatch[]; }): { [sport: number]: IBetMatch[]; }; getGrp(): SportsFeedMessageGroup; }