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.provider.transform;
 
 import java.util.List;
 
 
An internal service provider implementation for an DyanmoDB specific request metric transformer. This class is loaded only if there are Amazon DyanmoDB specific predefined metrics to be processed.

 
     @Override
     public List<MetricDatumtoMetricData(MetricType metricType,
             Request<?> requestResponse<?> response) {
         try {
             return toMetricData0(metricTyperequestresponse);
         } catch (SecurityException e) {
         } catch (NoSuchMethodException e) {
         } catch (IllegalAccessException e) {
         } catch (InvocationTargetException e) {
             LogFactory.getLog(getClass()).debug(""e.getCause());
         } catch (Exception e) {
             LogFactory.getLog(getClass()).debug(""e);
         }
         return null;
     }
 
     private List<MetricDatumtoMetricData0(MetricType metricType,
             Request<?> reqResponse<?> responsethrows SecurityException,
             NoSuchMethodExceptionIllegalAccessException,
             InvocationTargetException {
         if (!(metricType instanceof DynamoDBRequestMetric))
             return null;
         // Predefined metrics across all aws http clients
         DynamoDBRequestMetric predefined = (DynamoDBRequestMetricmetricType;
         switch(predefined) {
             case :
                 if (response == null)
                     return Collections.emptyList();
                 Object awsResponse = response.getAwsResponse();
                 Method method = awsResponse.getClass().getMethod("getConsumedCapacity");
                 Object value = method.invoke(awsResponse);
                 if (!(value instanceof ConsumedCapacity))
                     return Collections.emptyList();
                 ConsumedCapacity consumedCapacity = (ConsumedCapacityvalue;
                 Double units = consumedCapacity.getCapacityUnits();
                 if (units == null)
                     return Collections.emptyList();
                 String tableName = consumedCapacity.getTableName();
                 List<Dimensiondims = new ArrayList<Dimension>();
                 dims.add(new Dimension()
                         .withName(..name())
                         .withValue(metricType.name()));
                 // request type specific
                 dims.add(new Dimension()
                         .withName(..name())
                         .withValue(requestType(req)));
                 // table specific
                 dims.add(new Dimension()
                         .withName(..name())
                         .withValue(tableName));
                MetricDatum datum = new MetricDatum()
                    .withMetricName(req.getServiceName())
                    .withDimensions(dims)
                    .withUnit(.)
                    .withValue(units);
                return Collections.singletonList(datum);
            default:
                return Collections.emptyList();
        }
    }

    
Returns the name of the type of request.
    private String requestType(Request<?> req) {
        return req.getOriginalRequest().getClass().getSimpleName();
    }
New to GrepCode? Check out our FAQ X