Java Code Examples for com.netflix.hystrix.ExecutionResult

Following code examples demonstrate how to use com.netflix.hystrix.ExecutionResult from netflix-hystrix. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.netflix.hystrix.ExecutionResult and various code implementation of this class.
Example 1
Project : netflix-hystrix Source File : SerialHystrixRequestEvents.java View Source Code on GitHub

    private static void convertExecutionToJson(JsonGenerator json, HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies) throws IOException {
        json.writeStartObject();
        json.writeStringField("name", executionSignature.getCommandName());
        json.writeArrayFieldStart("events");
        ExecutionResult.EventCounts eventCounts = executionSignature.getEventCounts();
        for (HystrixEventType eventType: HystrixEventType.values()) {
            if (!eventType.equals(HystrixEventType.COLLAPSED)) {
                if (eventCounts.contains(eventType)) {
                    int eventCount = eventCounts.getCount(eventType);
                    if (eventCount > 1) {
                        json.writeStartObject();
                        json.writeStringField("name", eventType.name());
                        json.writeNumberField("count", eventCount);
                        json.writeEndObject();
                    } else {
                        json.writeString(eventType.name());
                    }
                }
            }
        }
        json.writeEndArray();
        json.writeArrayFieldStart("latencies");
        for (int latency: latencies) {
            json.writeNumber(latency);
        }
        json.writeEndArray();
        if (executionSignature.getCachedCount() > 0) {
            json.writeNumberField("cached", executionSignature.getCachedCount());
        }
        if (executionSignature.getEventCounts().contains(HystrixEventType.COLLAPSED)) {
            json.writeObjectFieldStart("collapsed");
            json.writeStringField("name", executionSignature.getCollapserKey().name());
            json.writeNumberField("count", executionSignature.getCollapserBatchSize());
            json.writeEndObject();
        }
        json.writeEndObject();
    }
			
Example 2
Project : netflix-hystrix Source File : HystrixRequestEventsJsonStream.java View Source Code on GitHub

    private static void convertExecutionToJson(JsonGenerator json, HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies) throws IOException {
        json.writeStartObject();
        json.writeStringField("name", executionSignature.getCommandName());
        json.writeArrayFieldStart("events");
        ExecutionResult.EventCounts eventCounts = executionSignature.getEventCounts();
        for (HystrixEventType eventType: HystrixEventType.values()) {
            if (eventType != HystrixEventType.COLLAPSED) {
                if (eventCounts.contains(eventType)) {
                    int eventCount = eventCounts.getCount(eventType);
                    if (eventCount > 1) {
                        json.writeStartObject();
                        json.writeStringField("name", eventType.name());
                        json.writeNumberField("count", eventCount);
                        json.writeEndObject();
                    } else {
                        json.writeString(eventType.name());
                    }
                }
            }
        }
        json.writeEndArray();
        json.writeArrayFieldStart("latencies");
        for (int latency: latencies) {
            json.writeNumber(latency);
        }
        json.writeEndArray();
        if (executionSignature.getCachedCount() > 0) {
            json.writeNumberField("cached", executionSignature.getCachedCount());
        }
        if (executionSignature.getEventCounts().contains(HystrixEventType.COLLAPSED)) {
            json.writeObjectFieldStart("collapsed");
            json.writeStringField("name", executionSignature.getCollapserKey().name());
            json.writeNumberField("count", executionSignature.getCollapserBatchSize());
            json.writeEndObject();
        }
        json.writeEndObject();
    }
			
Example 3
Project : netflix-hystrix Source File : HystrixCommandCompletionStreamTest.java View Source Code on GitHub

    public void testSingleWriteSingleSubscriber() throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);
        Subscriber<HystrixCommandCompletion> subscriber = getLatchedSubscriber(latch);

        commandStream.observe().take(1).subscribe(subscriber);

        ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
        HystrixCommandCompletion event = HystrixCommandCompletion.from(result, commandKey, threadPoolKey);
        commandStream.write(event);

        assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
    }
			
Example 4
Project : netflix-hystrix Source File : HystrixCommandCompletionStreamTest.java View Source Code on GitHub

    public void testSingleWriteMultipleSubscribers() throws InterruptedException {
        CountDownLatch latch1 = new CountDownLatch(1);
        Subscriber<HystrixCommandCompletion> subscriber1 = getLatchedSubscriber(latch1);

        CountDownLatch latch2 = new CountDownLatch(1);
        Subscriber<HystrixCommandCompletion> subscriber2 = getLatchedSubscriber(latch2);

        commandStream.observe().take(1).subscribe(subscriber1);
        commandStream.observe().take(1).subscribe(subscriber2);

        ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
        HystrixCommandCompletion event = HystrixCommandCompletion.from(result, commandKey, threadPoolKey);
        commandStream.write(event);

        assertTrue(latch1.await(1000, TimeUnit.MILLISECONDS));
        assertTrue(latch2.await(10, TimeUnit.MILLISECONDS));
    }