use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultXmlAsyncClient method eventStreamOperation.
/**
* Invokes the EventStreamOperation operation asynchronously.
*
* @param eventStreamOperationRequest
* @return A Java Future containing the result of the EventStreamOperation operation returned by the service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample XmlAsyncClient.EventStreamOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/EventStreamOperation"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<Void> eventStreamOperation(EventStreamOperationRequest eventStreamOperationRequest, EventStreamOperationResponseHandler asyncResponseHandler) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperation");
HttpResponseHandler<EventStreamOperationResponse> responseHandler = protocolFactory.createResponseHandler(EventStreamOperationResponse::builder, XmlOperationMetadata.builder().hasStreamingSuccessResponse(true).build());
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
HttpResponseHandler<? extends EventStream> eventResponseHandler = protocolFactory.createResponseHandler(EventStreamTaggedUnionPojoSupplier.builder().putSdkPojoSupplier("EventPayloadEvent", EventStream::eventPayloadEventBuilder).putSdkPojoSupplier("NonEventPayloadEvent", EventStream::nonEventPayloadEventBuilder).putSdkPojoSupplier("SecondEventPayloadEvent", EventStream::secondEventPayloadEventBuilder).defaultSdkPojoSupplier(() -> new SdkPojoBuilder(EventStream.UNKNOWN)).build(), XmlOperationMetadata.builder().hasStreamingSuccessResponse(false).build());
CompletableFuture<Void> eventStreamTransformFuture = new CompletableFuture<>();
EventStreamAsyncResponseTransformer<EventStreamOperationResponse, EventStream> asyncResponseTransformer = EventStreamAsyncResponseTransformer.<EventStreamOperationResponse, EventStream>builder().eventStreamResponseHandler(asyncResponseHandler).eventResponseHandler(eventResponseHandler).initialResponseHandler(responseHandler).exceptionResponseHandler(errorResponseHandler).future(eventStreamTransformFuture).executor(executor).serviceName(serviceName()).build();
RestEventStreamAsyncResponseTransformer<EventStreamOperationResponse, EventStream> restAsyncResponseTransformer = RestEventStreamAsyncResponseTransformer.<EventStreamOperationResponse, EventStream>builder().eventStreamAsyncResponseTransformer(asyncResponseTransformer).eventStreamResponseHandler(asyncResponseHandler).build();
CompletableFuture<Void> executeFuture = clientHandler.execute(new ClientExecutionParams<EventStreamOperationRequest, EventStreamOperationResponse>().withOperationName("EventStreamOperation").withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationRequest), restAsyncResponseTransformer);
CompletableFuture<Void> whenCompleteFuture = null;
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
if (e != null) {
runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", () -> asyncResponseHandler.exceptionOccurred(e));
eventStreamTransformFuture.completeExceptionally(e);
}
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
return CompletableFutureUtils.forwardExceptionTo(eventStreamTransformFuture, executeFuture);
} catch (Throwable t) {
runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", () -> asyncResponseHandler.exceptionOccurred(t));
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultXmlAsyncClient method streamingInputOperation.
/**
* Some operation with a streaming input
*
* @param streamingInputOperationRequest
* @param requestBody
* Functional interface that can be implemented to produce the request content in a non-blocking manner. The
* size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on
* implementing this interface as well as links to precanned implementations for common scenarios like
* uploading from a file. The service documentation for the request content is as follows 'This be a stream'
* @return A Java Future containing the result of the StreamingInputOperation operation returned by the service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample XmlAsyncClient.StreamingInputOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/StreamingInputOperation"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<StreamingInputOperationResponse> streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
if (!isSignerOverridden(clientConfiguration)) {
streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create());
}
HttpResponseHandler<Response<StreamingInputOperationResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(StreamingInputOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
CompletableFuture<StreamingInputOperationResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>().withOperationName("StreamingInputOperation").withMarshaller(AsyncStreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)).asyncRequestBody(requestBody).build()).withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody).withInput(streamingInputOperationRequest));
CompletableFuture<StreamingInputOperationResponse> whenCompleteFuture = null;
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
return whenCompleteFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultXmlAsyncClient method getOperationWithChecksum.
/**
* Invokes the GetOperationWithChecksum operation asynchronously.
*
* @param getOperationWithChecksumRequest
* @return A Java Future containing the result of the GetOperationWithChecksum operation returned by the service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample XmlAsyncClient.GetOperationWithChecksum
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/GetOperationWithChecksum"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<GetOperationWithChecksumResponse> getOperationWithChecksum(GetOperationWithChecksumRequest getOperationWithChecksumRequest) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetOperationWithChecksum");
HttpResponseHandler<Response<GetOperationWithChecksumResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(GetOperationWithChecksumResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
CompletableFuture<GetOperationWithChecksumResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<GetOperationWithChecksumRequest, GetOperationWithChecksumResponse>().withOperationName("GetOperationWithChecksum").withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)).withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM, HttpChecksum.builder().requestChecksumRequired(true).requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()).isRequestStreaming(false).build()).withInput(getOperationWithChecksumRequest));
CompletableFuture<GetOperationWithChecksumResponse> whenCompleteFuture = null;
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
return whenCompleteFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultXmlAsyncClient method operationWithChecksumRequired.
/**
* Invokes the OperationWithChecksumRequired operation asynchronously.
*
* @param operationWithChecksumRequiredRequest
* @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the
* service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>XmlException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample XmlAsyncClient.OperationWithChecksumRequired
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/OperationWithChecksumRequired"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChecksumRequired(OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired");
HttpResponseHandler<Response<OperationWithChecksumRequiredResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(OperationWithChecksumRequiredResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
CompletableFuture<OperationWithChecksumRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<OperationWithChecksumRequiredRequest, OperationWithChecksumRequiredResponse>().withOperationName("OperationWithChecksumRequired").withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)).withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest));
CompletableFuture<OperationWithChecksumRequiredResponse> whenCompleteFuture = null;
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
return whenCompleteFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class DefaultJsonAsyncClient method operationWithChecksumRequired.
/**
* Invokes the OperationWithChecksumRequired operation asynchronously.
*
* @param operationWithChecksumRequiredRequest
* @return A Java Future containing the result of the OperationWithChecksumRequired operation returned by the
* service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample JsonAsyncClient.OperationWithChecksumRequired
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/OperationWithChecksumRequired"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChecksumRequired(OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
HttpResponseHandler<OperationWithChecksumRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, OperationWithChecksumRequiredResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
CompletableFuture<OperationWithChecksumRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<OperationWithChecksumRequiredRequest, OperationWithChecksumRequiredResponse>().withOperationName("OperationWithChecksumRequired").withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest));
CompletableFuture<OperationWithChecksumRequiredResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
Aggregations