Search in sources :

Example 41 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class PathTemplateTest method fill.

private static String fill(PathTemplate template, Map<String, String> params) {
    try {
        BaseUrl.DefaultUrlBuilder url = BaseUrl.DefaultUrlBuilder.from(new URL("http://unused:1"));
        template.fill(params, url);
        return url.build().getPath();
    } catch (IOException e) {
        throw new SafeRuntimeException("failed to construct url", e);
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) IOException(java.io.IOException) URL(java.net.URL)

Example 42 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class QueuedChannel method scheduleNextTask.

/**
 * Get the next call and attempt to execute it. If it is runnable, wire up the underlying future to the one
 * previously returned to the caller. If it is not runnable, add it back into the queue. Returns true if more
 * tasks may be able to be scheduled, and false otherwise.
 */
private boolean scheduleNextTask() {
    DeferredCall queueHead = queuedCalls.poll();
    if (queueHead == null) {
        return false;
    }
    SettableFuture<Response> queuedResponse = queueHead.response();
    // request will be quickly cancelled in that case.
    if (queuedResponse.isDone()) {
        decrementQueueSize();
        queueHead.span().complete();
        queueHead.timer().stop();
        return true;
    }
    try (CloseableSpan ignored = queueHead.span().attach()) {
        Endpoint endpoint = queueHead.endpoint();
        Optional<ListenableFuture<Response>> maybeResponse = delegate.maybeExecute(endpoint, queueHead.request(), DO_NOT_SKIP_LIMITS);
        if (maybeResponse.isPresent()) {
            decrementQueueSize();
            ListenableFuture<Response> response = maybeResponse.get();
            queueHead.span().complete();
            queueHead.timer().stop();
            DialogueFutures.addDirectCallback(response, new ForwardAndSchedule(queuedResponse));
            DialogueFutures.addDirectListener(queuedResponse, () -> {
                if (queuedResponse.isCancelled()) {
                    // Currently cancel(false) will be converted to cancel(true)
                    if (!response.cancel(true) && log.isDebugEnabled()) {
                        log.debug("Failed to cancel delegate response, it should be reported by ForwardAndSchedule " + "logging", SafeArg.of("channel", channelName), SafeArg.of("service", endpoint.serviceName()), SafeArg.of("endpoint", endpoint.endpointName()));
                    }
                }
            });
            return true;
        } else {
            if (!queuedCalls.offerFirst(queueHead)) {
                // Should never happen, ConcurrentLinkedDeque has no maximum size
                log.error("Failed to add an attempted call back to the deque", SafeArg.of("channel", channelName), SafeArg.of("service", endpoint.serviceName()), SafeArg.of("endpoint", endpoint.endpointName()));
                decrementQueueSize();
                queueHead.timer().stop();
                if (!queuedResponse.setException(new SafeRuntimeException("Failed to req-queue request", SafeArg.of("channel", channelName), SafeArg.of("service", endpoint.serviceName()), SafeArg.of("endpoint", endpoint.endpointName())))) {
                    if (log.isDebugEnabled()) {
                        log.debug("Queued response has already been completed", SafeArg.of("channel", channelName), SafeArg.of("service", endpoint.serviceName()), SafeArg.of("endpoint", endpoint.endpointName()));
                    }
                }
            }
            return false;
        }
    }
}
Also used : Response(com.palantir.dialogue.Response) Endpoint(com.palantir.dialogue.Endpoint) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) CloseableSpan(com.palantir.tracing.CloseableSpan) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 43 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class TestResponse method close.

@Override
public void close() {
    checkNotClosed();
    try {
        closeCalled = true;
        inputStream.close();
    } catch (IOException e) {
        throw new SafeRuntimeException("Failed to close", e);
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) IOException(java.io.IOException)

Aggregations

SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)43 IOException (java.io.IOException)13 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)6 Response (com.palantir.dialogue.Response)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 TestResponse (com.palantir.dialogue.TestResponse)3 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)3 InvocationContext (com.palantir.tritium.event.InvocationContext)3 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Value (com.palantir.atlasdb.keyvalue.api.Value)2 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)2 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)2 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)2 Channel (com.palantir.dialogue.Channel)2