Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.metrics.internal.cloudwatch;
 
 
 
This is the default implementation of an AWS SDK request metric collection system.

 
 {
     protected final static Log log = LogFactory.getLog(RequestMetricCollectorSupport.class);
     private final BlockingQueue<MetricDatumqueue;
 
         this. = queue;
     }

    
Collects the metrics at the end of a request/response cycle, transforms the metric data points into a cloud watch metric datum representation, and then adds it to a memory queue so it will get summarized into the necessary statistics and uploaded to Amazon CloudWatch.
 
     @Override
     public void collectMetrics(Request<?> requestResponse<?> response) {
         try {
             collectMetrics0(requestresponse);
         } catch(Exception ex) { // defensive code
             if (.isDebugEnabled()) {
                 .debug("Ignoring unexpected failure"ex);
             }
         }
     }
     private void collectMetrics0(Request<?> requestResponse<?> response) {
         AWSRequestMetrics arm = request.getAWSRequestMetrics();
         if (arm == null || !arm.isEnabled()) {
             return;
         }
         for (MetricType type: AwsSdkMetrics.getPredefinedMetrics()) {
             if (!(type instanceof RequestMetricType))
                 continue;
             PredefinedMetricTransformer transformer = getTransformer();
             for (MetricDatum datum : transformer.toMetricData(typerequestresponse)) {
                 try {
                     if (!addMetricsToQueue(datum)) {
                         if (.isDebugEnabled()) {
                             .debug("Failed to add to the metrics queue (due to no space available) for "
                                     + type.name()
                                     + ":"
                                     + request.getServiceName());
                         }
                     }
                 } catch(RuntimeException ex) {
                     .warn("Failed to add to the metrics queue for "
                         + type.name() + ":" + request.getServiceName(),
                         ex);
                 }
             }
         }
     }

    
Adds the given metric to the queue, returning true if successful or false if no space available.
 
     protected boolean addMetricsToQueue(MetricDatum metric) {
         return .offer(metric); 
     }
    
Returns the predefined metrics transformer.
    protected PredefinedMetricTransformer getTransformer() { return ; }
New to GrepCode? Check out our FAQ X