event_handler

/*! $FileVersion=1.0.127 */ var event_handler_fileVersion = “1.0.127”;
function CreateEventHandler(){function b(e){logError(“Failed to process event: “+e);return{status:”failed”,reason:e}}var c={handleEvent:function(f){if(!f){return b(“Invalid (null) event received; ignored”)}logDebug(“received event ‘”+JSON.stringify(f)+”‘”);var h=this._resolveOriginator(f);logInformation(“Event Received from ‘”+h.name+”‘, version ‘”+h.version+”‘”);var e=f.event.name;var g=f.event.params;return this._handleKnownEvents(e,g)},_resolveOriginator:function(f){try{return{name:f.source.name,version:f.source.version}}catch(g){logWarning(“Failed to determine originator from incoming event; will try to process the payload anyway: exception is ‘”+g.message+”‘”);return{name:”[unspecified]”,version:”[unspecified]”}}},_handleKnownEvents:function(f,g){logInformation(“Processing ‘”+f+”‘ event with parameters ‘”+JSON.stringify(g)+”‘”);switch(f){case”DynamicUpdate.ProcessConfiguration”:var e=this._processOneConfiguration(g);break;case”DynamicUpdate.ProcessAllConfigurations”:e=this._processAllConfigurations();break;default:e={status:”failed”,reason:”Unrecognized message ‘”+f+”‘ will be ignored.”};break}this._decrementWorkload();return e},_processOneConfiguration:function(k){logInformation(“Processing One Configuration (params = ‘”+JSON.stringify(k)+”‘)”);var j=k;if(!j){return b(“Event parameters missing”)}var i=j.config;if(!i){return b(“Config name missing”)}try{this._incrementWorkload();var g=this._getUpdateManager();return g.updateOneProduct(i)}catch(h){logError(“Failed to process Configuration ‘”+i+”‘: exception is ‘”+h.message+”‘”);var f={status:”failed”,exception:h.message};return f}},_processAllConfigurations:function(){logInformation(“Processing All Configurations”);try{this._incrementWorkload();var f=this._getUpdateManager();f.updateAllProducts()}catch(g){logError(“Failed to process All Configurations: exception is ‘”+g.message+”‘”)}},_parseParameters:function(f){try{return JSON.parse(f)}catch(g){logWarning(“Failed to parse parameter values: exception is ‘”+g.message+”‘”)}return null},_getUpdateManager:function(){var e=ModuleManager.create(“update_manager”);return e},_incrementWorkload:function(){this._workloadCount++},_decrementWorkload:function(){if(0==this._workloadCount){return}this._workloadCount–;if(0==this._workloadCount){try{getMessageBus().Publish(“DynamicUpdate.Updates.Completed”)}catch(f){logError(“Failed to publish Updates.Completed event: exception is: ‘”+f.message+”‘”)}}},_workloadCount:0};try{var a=getMessageBus();if(a){a.Subscribe(“DynamicUpdate.ProcessConfiguration”,function(g){var f={};if(g){try{f=JSON.stringify(g)}catch(h){logWarning(“Unable to parse the event data: ‘”+g+”‘: exception is ‘”+h.message+”‘”)}}c.handleEvent(f)})}}catch(d){logError(“MessageBusHandler subscription problem: exception is ‘”+d.message+”‘”)}return c}ModuleManager.registerFactory(“event_handler”,CreateEventHandler);
//919680A459939AA8ACB0DBEBBF57BFEE5D12F93A5CA993E8651CD7F0D1C7622794CD5617F1AFCE0F8E1939A2C606CB3E3D433D32521D556F9BC12E415B8802D5++