Java Code Examples for com.nike.internal.util.Pair#getRight()

The following examples show how to use com.nike.internal.util.Pair#getRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncWingtipsHelperJava7.java    From wingtips with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method for calling {@link #unlinkTracingFromCurrentThread(Deque, Map)} that
 * gracefully handles the case where the pair you pass in is null - if the pair you pass in is null then {@link
 * #unlinkTracingFromCurrentThread(Deque, Map)} will be called with both arguments null. You can pass in a {@link
 * TracingState} for clearer less verbose code since it extends {@code Pair<Deque<Span>, Map<String, String>>}.
 *
 * @deprecated Please move to the Java 8 version of this class and method ({@code AsyncWingtipsHelper} or the static
 * {@code AsyncWingtipsHelperStatic}) whenever possible.
 */
@Deprecated
public static void unlinkTracingFromCurrentThread(
    Pair<Deque<Span>, Map<String, String>> threadInfoToResetFor
) {
    Deque<Span> spanStackToResetFor = (threadInfoToResetFor == null) ? null : threadInfoToResetFor.getLeft();
    Map<String, String> mdcContextMapToResetFor = (threadInfoToResetFor == null)
                                                  ? null
                                                  : threadInfoToResetFor.getRight();

    unlinkTracingFromCurrentThread(spanStackToResetFor, mdcContextMapToResetFor);
}
 
Example 2
Source File: VerifyBasicAuthIsConfiguredCorrectlyComponentTest.java    From riposte-microservice-template with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
    Pair<Server, TestUtils.AppServerConfigForTesting> serverAndConfigPair = TestUtils.createServerForTesting();
    serverConfig = serverAndConfigPair.getRight();
    realRunningServer = serverAndConfigPair.getLeft();
    realRunningServer.startup();

    String basicAuthUsername = serverConfig.getTestingAppConfig().getString("exampleBasicAuth.username");
    String basicAuthPassword = serverConfig.getTestingAppConfig().getString("exampleBasicAuth.password");
    basicAuthHeaderValueRequired = "Basic " + Base64.getEncoder().encodeToString(
        (basicAuthUsername + ":" + basicAuthPassword).getBytes(CharsetUtil.UTF_8)
    );
}
 
Example 3
Source File: RequestFilterHandler.java    From riposte with Apache License 2.0 4 votes vote down vote up
protected PipelineContinuationBehavior handleFilterLogic(
    ChannelHandlerContext ctx,
    Object msg,
    HttpProcessingState state,
    BiFunction<RequestAndResponseFilter, RequestInfo, RequestInfo> normalFilterCall,
    BiFunction<RequestAndResponseFilter, RequestInfo, Pair<RequestInfo, Optional<ResponseInfo<?>>>> shortCircuitFilterCall
) {
    RequestInfo<?> currentReqInfo = state.getRequestInfo();

    // Run through each filter.
    for (RequestAndResponseFilter filter : filters) {
        try {
            // See if we're supposed to do short circuit call or not
            if (filter.isShortCircuitRequestFilter()) {
                Pair<RequestInfo, Optional<ResponseInfo<?>>> result =
                    shortCircuitFilterCall.apply(filter, currentReqInfo);

                if (result != null) {
                    currentReqInfo = requestInfoUpdateNoNulls(currentReqInfo, result.getLeft());
                    // See if we need to short circuit.
                    ResponseInfo<?> responseInfo = (result.getRight() == null)
                                                   ? null
                                                   : result.getRight().orElse(null);
                    if (responseInfo != null) {
                        // Yep, short circuit. Set the request and response on the state based on the results, fire
                        //      a short circuit "we're all done" event down the pipeline, and return
                        //      "do not continue" for *this* event. Also make sure the ResponseInfo we got back was
                        //      full, not chunked.
                        if (responseInfo.isChunkedResponse()) {
                            throw new IllegalStateException("RequestAndResponseFilter should never return a "
                                                            + "chunked ResponseInfo when short circuiting.");
                        }

                        state.setRequestInfo(currentReqInfo);
                        state.setResponseInfo(responseInfo, null);

                        // Fire the short-circuit event that will get the desired response info sent to the caller.
                        ctx.fireChannelRead(LastOutboundMessageSendFullResponseInfo.INSTANCE);

                        // Tell this event to stop where it is.
                        return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT;
                    }
                }
            }
            else {
                currentReqInfo =
                    requestInfoUpdateNoNulls(currentReqInfo, normalFilterCall.apply(filter, currentReqInfo));
            }
        }
        catch (Throwable ex) {
            logger.error(
                "An error occurred while processing a request filter. This error will be ignored and the "
                + "filtering/processing will continue normally, however this error should be fixed (filters should "
                + "never throw errors). filter_class={}", filter.getClass().getName(), ex
            );
        }
    }

    // All the filters have been processed, so set the state to whatever the current request info says.
    state.setRequestInfo(currentReqInfo);

    // No short circuit if we reach here, so continue normally.
    return PipelineContinuationBehavior.CONTINUE;
}
 
Example 4
Source File: AsyncNettyHelperTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "false  |   true",
    "true   |   false",
    "false  |   false",
}, splitBy = "\\|")
@Test
public void unlinkTracingAndMdcFromCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack,
                                                                                 boolean useNullMdcInfo) {
    // given
    Pair<Deque<Span>, Map<String, String>> info = setupStateWithTracingAndMdcInfo();
    info.getRight().put("fooMdcKey", UUID.randomUUID().toString());
    Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft();
    Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight();
    // Setup the current thread with something that is not ultimately what we expect so that our assertions are
    //      verifying that the unlinkTracingAndMdcFromCurrentThread method actually did something.
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());

    Map<String, String> expectedMdcInfo;
    // The expected MDC info will vary depending on combinations.
    if (useNullMdcInfo) {
        // MDC may still be populated after the call if the span stack is not empty
        if (useNullSpanStack)
            expectedMdcInfo = Collections.emptyMap();
        else {
            // MDC will have been populated with tracing info.
            expectedMdcInfo = new HashMap<>();
            Span expectedSpan = spanStackForLinking.peek();
            expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId());
        }
    }
    else {
        // Not null MDC. Since unlinkTracingAndMdcFromCurrentThread doesn't call registerWithThread when
        //      the span stack is null we don't need to worry about trace ID and span JSON being removed from MDC.
        //      Therefore it should match mdcInfoForLinking exactly.
        expectedMdcInfo = new HashMap<>(mdcInfoForLinking);
    }

    // when
    AsyncNettyHelper.unlinkTracingAndMdcFromCurrentThread(spanStackForLinking, mdcInfoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking);
    assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo);
}
 
Example 5
Source File: AsyncNettyHelperTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "false  |   true",
    "true   |   false",
    "false  |   false",
}, splitBy = "\\|")
@Test
public void linkTracingAndMdcToCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack,
                                                                             boolean useNullMdcInfo) {
    // given
    Pair<Deque<Span>, Map<String, String>> info = setupStateWithTracingAndMdcInfo();
    info.getRight().put("fooMdcKey", UUID.randomUUID().toString());
    Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft();
    Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight();
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());
    Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    Map<String, String> expectedMdcInfo;
    // The expected MDC info will vary depending on combinations.
    if (useNullMdcInfo) {
        // MDC may still be populated after the call if the span stack is not empty
        if (useNullSpanStack)
            expectedMdcInfo = Collections.emptyMap();
        else {
            // MDC will have been populated with tracing info.
            expectedMdcInfo = new HashMap<>();
            Span expectedSpan = spanStackForLinking.peek();
            expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId());
        }
    }
    else {
        // Not null MDC. Start with the MDC info for linking.
        expectedMdcInfo = new HashMap<>(mdcInfoForLinking);
        if (useNullSpanStack) {
            // In the case of a null span stack, the trace info would be removed from the MDC.
            expectedMdcInfo.remove(SpanFieldForLoggerMdc.TRACE_ID.mdcKey);
        }
    }

    // when
    Pair<Deque<Span>, Map<String, String>> preCallInfo =
        AsyncNettyHelper.linkTracingAndMdcToCurrentThread(spanStackForLinking, mdcInfoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(preCallInfo).isEqualTo(expectedPreCallInfo);
    assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking);
    assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo);
}
 
Example 6
Source File: AsyncWingtipsHelperTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true   |   true    |   true",
    "false  |   true    |   true",
    "true   |   false   |   true",
    "false  |   false   |   true",
    "true   |   true    |   false",
    "false  |   true    |   false",
    "true   |   false   |   false",
    "false  |   false   |   false",
}, splitBy = "\\|")
@Test
public void unlinkTracingFromCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack,
                                                                                 boolean useNullMdcInfo,
                                                                                 boolean useStaticMethod) {
    // given
    Pair<Deque<Span>, Map<String, String>> info = generateTracingInfo();
    info.getRight().put("fooMdcKey", UUID.randomUUID().toString());
    Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft();
    Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight();
    // Setup the current thread with something that is not ultimately what we expect so that our assertions are
    //      verifying that the unlinkTracingFromCurrentThread method actually did something.
    resetTracing();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());

    Map<String, String> expectedMdcInfo;
    // The expected MDC info will vary depending on combinations.
    if (useNullMdcInfo) {
        // MDC may still be populated after the call if the span stack is not empty
        if (useNullSpanStack)
            expectedMdcInfo = Collections.emptyMap();
        else {
            // MDC will have been populated with tracing info.
            expectedMdcInfo = new HashMap<>();
            Span expectedSpan = spanStackForLinking.peek();
            expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId());
        }
    }
    else {
        // Not null MDC. Since unlinkTracingFromCurrentThread doesn't call registerWithThread when
        //      the span stack is null we don't need to worry about trace ID being removed from MDC.
        //      Therefore it should match mdcInfoForLinking exactly.
        expectedMdcInfo = new HashMap<>(mdcInfoForLinking);
    }

    // when
    if (useStaticMethod) {
        unlinkTracingFromCurrentThread(spanStackForLinking, mdcInfoForLinking);
    }
    else {
        DEFAULT_IMPL.unlinkTracingFromCurrentThread(spanStackForLinking, mdcInfoForLinking);
    }
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking);
    if (expectedMdcInfo.isEmpty()) {
        assertThat(postCallInfo.getRight()).isNullOrEmpty();
    }
    else {
        assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo);
    }
}
 
Example 7
Source File: FailureCallbackWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                  Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origFailureCallback,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 8
Source File: ConsumerWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public ConsumerWithTracing(Consumer<T> origConsumer,
                           Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origConsumer,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 9
Source File: SupplierWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public SupplierWithTracing(Supplier<U> origSupplier,
                           Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origSupplier,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 10
Source File: RunnableWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public RunnableWithTracing(Runnable origRunnable,
                           Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origRunnable,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 11
Source File: BiFunctionWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public BiFunctionWithTracing(BiFunction<T, U, R> origBiFunction,
                             Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origBiFunction,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 12
Source File: CallableWithTracingAndMdcSupport.java    From riposte with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 * <p/>
 * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null
 * for the operation).
 * <p/>
 * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will
 * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread
 * when the operation is executed however.
 */
public CallableWithTracingAndMdcSupport(Callable<U> origCallable,
                                        Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origCallable,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 13
Source File: BiFunctionWithTracingAndMdcSupport.java    From riposte with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 * <p/>
 * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null
 * for the operation).
 * <p/>
 * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will
 * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread
 * when the operation is executed however.
 */
public BiFunctionWithTracingAndMdcSupport(BiFunction<T, U, R> origBiFunction,
                                          Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origBiFunction,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 14
Source File: BiConsumerWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public BiConsumerWithTracing(BiConsumer<T, U> origBiConsumer,
                             Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origBiConsumer,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 15
Source File: FunctionWithTracingAndMdcSupport.java    From riposte with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 * <p/>
 * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null
 * for the operation).
 * <p/>
 * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will
 * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread
 * when the operation is executed however.
 */
public FunctionWithTracingAndMdcSupport(Function<T, U> origFunction,
                                        Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origFunction,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 16
Source File: AsyncWingtipsHelperJava7.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Links the given distributed tracing and logging MDC info to the current thread. Any existing tracing and MDC info
 * on the current thread will be wiped out and overridden, so if you need to go back to them in the future you'll
 * need to store the copy info returned by this method for later.
 *
 * @param threadInfoToLink
 *     A {@link Pair} containing the span stack and MDC info you want to link to the current thread.
 *     This argument can be null - if it is null then {@link Tracer} will be setup with an empty span stack (wiping
 *     out any existing in-progress traces) *and* {@link MDC#clear()} will be called (wiping out any
 *     existing MDC info). The left and/or right portion of the pair can also be null, with any null portion of the
 *     pair causing the corresponding portion to be emptied/cleared while letting any non-null portion link to the
 *     thread as expected. You can pass in a {@link TracingState} for clearer less verbose code since it extends
 *     {@code Pair<Deque<Span>, Map<String, String>>}.
 *
 * @return A *COPY* of the original span stack and MDC info on the thread when this method was called (before being
 * replaced with the given arguments). The returned {@link TracingState} object will never be null, but the values
 * it contains may be null. A copy is returned rather than the original to prevent undesired behavior (storing the
 * return value and then passing it in to {@link #unlinkTracingFromCurrentThread(Pair)} later should *guarantee*
 * that after calling that unlink method the thread state is exactly as it was right *before* calling this link
 * method. If we returned the original span stack this contract guarantee could be violated).
 *
 * @deprecated Please move to the Java 8 version of this class and method ({@code AsyncWingtipsHelper} or the static
 * {@code AsyncWingtipsHelperStatic}) whenever possible.
 */
@Deprecated
public static TracingState linkTracingToCurrentThread(
    Pair<Deque<Span>, Map<String, String>> threadInfoToLink
) {
    Deque<Span> spanStack = (threadInfoToLink == null) ? null : threadInfoToLink.getLeft();
    Map<String, String> mdcContextMap = (threadInfoToLink == null) ? null : threadInfoToLink.getRight();

    return linkTracingToCurrentThread(spanStack, mdcContextMap);
}
 
Example 17
Source File: ConsumerWithTracingAndMdcSupport.java    From riposte with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 * <p/>
 * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null
 * for the operation).
 * <p/>
 * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will
 * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread
 * when the operation is executed however.
 */
public ConsumerWithTracingAndMdcSupport(Consumer<T> origConsumer,
                                        Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origConsumer,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 18
Source File: BiConsumerWithTracingAndMdcSupport.java    From riposte with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 * <p/>
 * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null
 * for the operation).
 * <p/>
 * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will
 * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread
 * when the operation is executed however.
 */
public BiConsumerWithTracingAndMdcSupport(BiConsumer<T, U> origBiConsumer,
                                          Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origBiConsumer,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 19
Source File: ListenableFutureCallbackWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                           Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origListenableFutureCallback,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}
 
Example 20
Source File: PredicateWithTracing.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that uses the given trace and MDC information, which will be associated with the thread when the
 * given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
public PredicateWithTracing(Predicate<T> origPredicate,
                            Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
    this(
        origPredicate,
        (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(),
        (originalThreadInfo == null) ? null : originalThreadInfo.getRight()
    );
}