UNPKG

8.28 kBJavaScriptView Raw
1"use strict";var __extends=this&&this.__extends||function(){var s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__decorate=this&&this.__decorate||function(t,e,r,s){var o,n=arguments.length,p=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(t,e,r,s);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(p=(n<3?o(p):3<n?o(e,r,p):o(e,r))||p);return 3<n&&p&&Object.defineProperty(e,r,p),p},__metadata=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},__param=this&&this.__param||function(r,s){return function(t,e){s(t,e,r)}};Object.defineProperty(exports,"__esModule",{value:!0});var data_structure_1=require("./data_structure"),core_1=require("./core"),message_class_1=require("./message_class"),injection_js_1=require("injection-js");exports.EPGM_IMPL=new injection_js_1.InjectionToken("EpgmInstance");var WrapperImpl=function(){function t(t,e){this.__epg=t,this.__stream=e}return t.prototype.epg=function(){return this.__epg},t.prototype.stream=function(){return this.__stream},t}(),FullSnapshotWrapper=function(n){function t(t,e,r,s){var o=n.call(this,t,e)||this;return o._epg=t,o._stream=e,o._epd=r,o.fullSnapshot=s,o}return __extends(t,n),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.epd=function(){return this._epd},t.prototype.process=function(){this._epd.readyToDispatch();var t=this._epg.generateFull(this);if(null!=t)for(var e=0;e<t.length;e++){var r=t[e];this._epd.submit(r)}},t.prototype.getFullSnapshot=function(){return this.fullSnapshot},t.prototype.setFullSnapshot=function(t){this.fullSnapshot=t},t}(exports.WrapperImpl=WrapperImpl);exports.FullSnapshotWrapper=FullSnapshotWrapper;var PartialSnapshotWrapper=function(o){function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.delta=function(){return this._delta},t.prototype.process=function(){for(var t=this._epg.generatePartial(this),e=this._epg.getEPDs(this._stream),r=0;r<e.length;r++)for(var s=e[r],o=0;o<t.length;o++)if(s.isReadyToDispatch()){var n=t[o];s.submit(n)}},t}(WrapperImpl);exports.PartialSnapshotWrapper=PartialSnapshotWrapper;var IndicatorWrapper=function(o){function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.process=function(){for(var t=this._epg.getEPDs(this._stream),e=0;e<t.length;e++){t[e].submit(this._delta)}},t}(WrapperImpl);exports.IndicatorWrapper=IndicatorWrapper;var EPDispatcherException=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t}(Error);exports.EPDispatcherException=EPDispatcherException;var EndPointGroupManager=function(){function t(t,e){this._fsRepo=t,this._grp=e,this.relayEPG=new RelayEPG(e),this.relayEPG.startGetingDeltaSnapshot(t)}return t.prototype.fsRepo=function(){return this._fsRepo},t.prototype.grp=function(){return this._grp},t.prototype.pushFullSnapshotWrapper=function(s,o){var n=this,p=o.stream();o.isInitialized().then(function(t){if(t){var e=n._fsRepo.getSnapshot(p),r=new FullSnapshotWrapper(s,p,o,e);s.submitForProcess(r)}})},t.prototype.registerEPD=function(t){if(this.relayEPG.hasEPD(t.stream(),t.id()))throw new EPDispatcherException("EPD already exists in a group.Id: "+t.id+" Stream: "+t.stream);this.relayEPG.addEPD(t),this.pushFullSnapshotWrapper(this.relayEPG,t)},t.prototype.deregisterEPD=function(t){this.relayEPG.removeEPD(t)},t=__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup])],t)}();exports.EndPointGroupManager=EndPointGroupManager;var DispatchersGroup=function(){function t(t){this.streamName=t,this.dispatchers={}}return t.prototype.addEpd=function(t){this.dispatchers[t.id()]=t},t.prototype.removeEpd=function(t){var e=this.dispatchers[t.id()];return delete this.dispatchers[t.id()],e},t.prototype.get=function(t){return this.dispatchers[t]},t.prototype.getAll=function(){var e=this;return Object.keys(this.dispatchers).map(function(t){return e.dispatchers[t]})},t.prototype.isEmpty=function(){return 0==Object.keys(this.dispatchers).length},t}();exports.DispatchersGroup=DispatchersGroup;var AbstractEPG=function(){function t(t){this.sportsFeedGroup=t,this.dispatchers={}}return t.prototype.hasEPD=function(t,e){var r=this.dispatchers[t];return void 0!==r&&void 0!==r.get(e)},t.prototype.addEPD=function(t){void 0===this.dispatchers[t.stream()]&&(this.dispatchers[t.stream()]=new DispatchersGroup(t.stream())),this.dispatchers[t.stream()].addEpd(t)},t.prototype.removeEPD=function(t){var e=this.dispatchers[t.stream()];void 0!==e&&(e.removeEpd(t),e.isEmpty()&&delete this.dispatchers[t.stream()])},t.prototype.isEmpty=function(){return 0==Object.keys(this.dispatchers).length},t.prototype.getEPDs=function(t){var e=this.dispatchers[t];return void 0!==e?e.getAll():[]},t.prototype.getStreams=function(){return Object.keys(this.dispatchers)},t.prototype.startGetingDeltaSnapshot=function(t){t.registerSnapshotHandler(this)},t.prototype.stopGetingDeltaSnapshot=function(t){t.deRegisterSnapshotHandler(this)},t.prototype.process=function(t,e){if(this.sportsFeedGroup.isIndicatorMessage(e.msgType())){var r=new IndicatorWrapper(e,this,t);this.submitForProcess(r)}else{var s=new PartialSnapshotWrapper(e,this,t);this.submitForProcess(s)}},t.prototype.getSportsFeedGrp=function(){return this.sportsFeedGroup},t.prototype.generateFull=function(t){throw new Error("Method not implemented.")},t.prototype.generatePartial=function(t){throw new Error("Method not implemented.")},t}(),RelayEPG=function(r){function t(t){var e=r.call(this,t)||this;return e._sportsFeedGroup=t,e}return __extends(t,r),t.prototype.submitForProcess=function(t){t.process()},t.prototype.onException=function(t){return console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ",t),null},t.prototype.generateFull=function(t){var e=t.getFullSnapshot();return[new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_START(),new Object),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_RESET(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_END(),new Object)]},t.prototype.generatePartial=function(t){var e=t.delta();return"TTLOutgoing"==e.constructor.name?this.generateTtl(e):[e]},t.prototype.generateTtl=function(t){return this.isSameFormat(t.msgType(),this._sportsFeedGroup.ADMIN_REFRESH())?[]:t.getTtlType()==core_1.TTLType.REMOVE?[t]:this.generateTtlRestore(t)},t.prototype.generateTtlRestore=function(t){return[new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT)]},t.prototype.isSameFormat=function(t,e){return t.instanceClass()==e.instanceClass()&&t.constructor.name==e.constructor.name},t=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup])],t)}(exports.AbstractEPG=AbstractEPG);exports.RelayEPG=RelayEPG;
\No newline at end of file