UNPKG

vulcain-corejs

Version:
111 lines (109 loc) 3.88 kB
"use strict"; var EventType; (function (EventType) { EventType[EventType["SUCCESS"] = 0] = "SUCCESS"; EventType[EventType["SHORT_CIRCUITED"] = 1] = "SHORT_CIRCUITED"; EventType[EventType["SEMAPHORE_REJECTED"] = 2] = "SEMAPHORE_REJECTED"; EventType[EventType["TIMEOUT"] = 3] = "TIMEOUT"; EventType[EventType["FAILURE"] = 4] = "FAILURE"; EventType[EventType["FALLBACK_REJECTION"] = 5] = "FALLBACK_REJECTION"; EventType[EventType["FALLBACK_SUCCESS"] = 6] = "FALLBACK_SUCCESS"; EventType[EventType["FALLBACK_FAILURE"] = 7] = "FALLBACK_FAILURE"; EventType[EventType["RESPONSE_FROM_CACHE"] = 8] = "RESPONSE_FROM_CACHE"; })(EventType = exports.EventType || (exports.EventType = {})); var FailureType; (function (FailureType) { FailureType[FailureType["SHORTCIRCUIT"] = 0] = "SHORTCIRCUIT"; FailureType[FailureType["REJECTED_SEMAPHORE_EXECUTION"] = 1] = "REJECTED_SEMAPHORE_EXECUTION"; FailureType[FailureType["TIMEOUT"] = 2] = "TIMEOUT"; FailureType[FailureType["COMMAND_EXCEPTION"] = 3] = "COMMAND_EXCEPTION"; FailureType[FailureType["REJECTED_SEMAPHORE_FALLBACK"] = 4] = "REJECTED_SEMAPHORE_FALLBACK"; })(FailureType = exports.FailureType || (exports.FailureType = {})); class ExecutionResult { constructor() { this.events = new Array(); /** * If this command has completed execution either successfully, via fallback or failure. * */ this.isExecutionComplete = false; } /** * Whether the response was returned successfully either by executing <code>run()</code> or from cache. * * @return bool */ get isSuccessfulExecution() { return this.eventExists(EventType.SUCCESS); } /** * Whether the <code>run()</code> resulted in a failure (exception). * * @return bool */ get isFailedExecution() { return this.eventExists(EventType.FAILURE); } /** * Whether the response received from was the result of some type of failure * and <code>Fallback { get</code> being called. * * @return bool */ get isResponseFromFallback() { return this.eventExists(EventType.FALLBACK_SUCCESS); } /** * Whether the response received was the result of a timeout * and <code>Fallback { get</code> being called. * * @return bool */ get isResponseTimedOut() { return this.eventExists(EventType.TIMEOUT); } /** * Whether the response received was a fallback as result of being * short-circuited (meaning <code>IsCircuitBreakerOpen { get == true</code>) and <code>Fallback { get</code> being called. * * @return bool */ get isResponseShortCircuited() { return this.eventExists(EventType.SHORT_CIRCUITED); } /** * Whether the response is from cache and <code>run()</code> was not invoked. * * @return bool */ get isResponseFromCache() { return this.eventExists(EventType.RESPONSE_FROM_CACHE); } /** * Whether the response received was a fallback as result of being * rejected (from thread-pool or semaphore) and <code>Fallback { get</code> being called. * * @return bool */ get isResponseRejected() { return this.eventExists(EventType.SEMAPHORE_REJECTED); } /** * List of CommandEventType enums representing events that occurred during execution. * <p> * Examples of events are SUCCESS, FAILURE, TIMEOUT, and SHORT_CIRCUITED * * @return {@code List<EventType>} */ get executionEvents() { return this.events; } addEvent(evt) { this.events.push(evt); } eventExists(evt) { return this.events.indexOf(evt) >= 0; } } exports.ExecutionResult = ExecutionResult; //# sourceMappingURL=executionResult.js.map