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.

 
 public class MetricCollectorSupport extends MetricCollector {
     protected final static Log log = LogFactory.getLog(MetricCollectorSupport.class);
     private static volatile MetricCollectorSupport singleton;
    
    
Returns the singleton instance; or null if there isn't one.
 
     static MetricCollectorSupport getInstance() {
         return ;
     }

    
Starts a new CloudWatch collector if it's not already started.

Returns:
true if it is successfully started by this call; false if the collector is already running or if there is failure in trying to start the collector for the first time.
 
     static synchronized boolean startSingleton(CloudWatchMetricConfig config) {
         if ( != null) {
             return false;
         }
         .info("Initializing " + MetricCollectorSupport.class.getSimpleName());
         return createAndStartCollector(config);
     }

    
Retarts with a new CloudWatch collector.
 
     static synchronized boolean restartSingleton(CloudWatchMetricConfig config) {
         if ( == null) {
             throw new IllegalStateException(MetricCollectorSupport.class.getSimpleName()
                 + " has neven been initialized");
         }
         .info("Re-initializing " + MetricCollectorSupport.class.getSimpleName());
         .stop();
         // singleton is set to null at this point via the stop method
         return createAndStartCollector(config);
     }

    
Returns true if the collector is successfully created and started; false otherwise.
 
     private static boolean createAndStartCollector(CloudWatchMetricConfig config) {
         MetricCollectorSupport collector = new MetricCollectorSupport(config);
         if (collector.start()) {
              = collector;
             return true;
         }
         return false;
     }
 
 
     private final BlockingQueue<MetricDatumqueue;
 //    private final PredefinedMetricTransformer transformer = new PredefinedMetricTransformer();
     private final CloudWatchMetricConfig config;
 
     protected MetricCollectorSupport(CloudWatchMetricConfig config) {
         if (config == null) {
             throw new IllegalArgumentException();
         }
         this. = config;
         this. = new LinkedBlockingQueue<MetricDatum>(config.getMetricQueueSize());
    }
    @Override
    public boolean start() {
        synchronized(MetricCollectorSupport.class) {
            if ( != null) {
                return false;   // already started
            }
             = new MetricUploaderThread();
            .start();
        }
        return true;
    }

    
Stops this collector immediately, dropping all pending metrics in memory.
    @Override
    public boolean stop() {
        synchronized(MetricCollectorSupport.class) {
            if ( != null) {
                .cancel();
                .interrupt();
                 = null;
                if ( == this) { // defensive check
                     = null;
                }
                return true;
            }
        }
        return false;
    }

    
Returns the configuration.
    public CloudWatchMetricConfig getConfig() { return ; }
        return  == null ? null : .getCloudwatchClient();
    }
    
Always returns true.
    @Override public final boolean isEnabled() { return true; }
    @Override
        return ;
    }
    @Override 
        return ;
    }
New to GrepCode? Check out our FAQ X