// Path: src/main/java/com/metamx/common/IAE.java
// public class IAE extends IllegalArgumentException
// {
//   public IAE(String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments));
//   }
// 
//   public IAE(Throwable cause, String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments), cause);
//   }
// }
// 
// Path: src/main/java/com/metamx/common/ISE.java
// public class ISE extends IllegalStateException
// {
//   public ISE(String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments));
//   }
// 
//   public ISE(Throwable cause, String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments), cause);
//   }
// }
// 
// Path: src/main/java/com/metamx/emitter/core/factory/EmitterFactory.java
// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
// @JsonSubTypes(value = {
//     @JsonSubTypes.Type(name = "http", value = HttpEmitterFactory.class),
//     @JsonSubTypes.Type(name = "statsd", value = StatsDEmitterFactory.class),
//     @JsonSubTypes.Type(name = "logging", value = LoggingEmitterFactory.class),
//     @JsonSubTypes.Type(name = "parametrized", value = ParametrizedUriEmitterFactory.class),
//     @JsonSubTypes.Type(name = "composing", value = ComposingEmitterFactory.class),
//     @JsonSubTypes.Type(name = "noop", value = NoopEmiterFactory.class)
// })
// public interface EmitterFactory
// {
//   Emitter makeEmitter(ObjectMapper objectMapper, AsyncHttpClient httpClient, Lifecycle lifecycle);
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import com.metamx.common.IAE;
import com.metamx.common.ISE;
import com.metamx.common.lifecycle.Lifecycle;
import com.metamx.common.logger.Logger;
import com.metamx.emitter.core.factory.EmitterFactory;
import org.asynchttpclient.AsyncHttpClient;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/*
 * Copyright 2012 Metamarkets Group Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.metamx.emitter.core;



public class Emitters
{
  private static final Logger log = new Logger(Emitters.class);

  private static final String LOG_EMITTER_PROP = "com.metamx.emitter.logging";
  private static final String HTTP_EMITTER_PROP = "com.metamx.emitter.http";
  private static final String CUSTOM_EMITTER_TYPE_PROP = "com.metamx.emitter.type";

  public static Emitter create(Properties props, AsyncHttpClient httpClient, Lifecycle lifecycle)
  {
    return create(props, httpClient, new ObjectMapper(), lifecycle);
  }

  public static Emitter create(Properties props, AsyncHttpClient httpClient, ObjectMapper jsonMapper, Lifecycle lifecycle)
  {
    Map<String, Object> jsonified = Maps.newHashMap();
    if (props.getProperty(LOG_EMITTER_PROP) != null) {
      jsonified = makeLoggingMap(props);
      jsonified.put("type", "logging");
    }
    else if (props.getProperty(HTTP_EMITTER_PROP) != null) {
      jsonified = makeHttpMap(props);
      jsonified.put("type", "http");
    }
    else if (props.getProperty(CUSTOM_EMITTER_TYPE_PROP) !=null) {
      jsonified = makeCustomFactoryMap(props);
    }
    else {
      throw new ISE(
          "Unknown type of emitter. Please set [%s], [%s] or provide registered subtype of com.metamx.emitter.core.factory.EmitterFactory via [%s]",
          LOG_EMITTER_PROP,
          HTTP_EMITTER_PROP,
// Path: src/main/java/com/metamx/common/IAE.java
// public class IAE extends IllegalArgumentException
// {
//   public IAE(String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments));
//   }
// 
//   public IAE(Throwable cause, String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments), cause);
//   }
// }
// 
// Path: src/main/java/com/metamx/common/ISE.java
// public class ISE extends IllegalStateException
// {
//   public ISE(String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments));
//   }
// 
//   public ISE(Throwable cause, String formatText, Object... arguments)
//   {
//     super(StringUtils.safeFormat(formatText, arguments), cause);
//   }
// }
// 
// Path: src/main/java/com/metamx/emitter/core/factory/EmitterFactory.java
// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
// @JsonSubTypes(value = {
//     @JsonSubTypes.Type(name = "http", value = HttpEmitterFactory.class),
//     @JsonSubTypes.Type(name = "statsd", value = StatsDEmitterFactory.class),
//     @JsonSubTypes.Type(name = "logging", value = LoggingEmitterFactory.class),
//     @JsonSubTypes.Type(name = "parametrized", value = ParametrizedUriEmitterFactory.class),
//     @JsonSubTypes.Type(name = "composing", value = ComposingEmitterFactory.class),
//     @JsonSubTypes.Type(name = "noop", value = NoopEmiterFactory.class)
// })
// public interface EmitterFactory
// {
//   Emitter makeEmitter(ObjectMapper objectMapper, AsyncHttpClient httpClient, Lifecycle lifecycle);
// }


// Path: src/main/java/com/metamx/emitter/core/Emitters.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import com.metamx.common.IAE;
import com.metamx.common.ISE;
import com.metamx.common.lifecycle.Lifecycle;
import com.metamx.common.logger.Logger;
import com.metamx.emitter.core.factory.EmitterFactory;
import org.asynchttpclient.AsyncHttpClient;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/*
 * Copyright 2012 Metamarkets Group Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.metamx.emitter.core;



public class Emitters
{
  private static final Logger log = new Logger(Emitters.class);

  private static final String LOG_EMITTER_PROP = "com.metamx.emitter.logging";
  private static final String HTTP_EMITTER_PROP = "com.metamx.emitter.http";
  private static final String CUSTOM_EMITTER_TYPE_PROP = "com.metamx.emitter.type";

  public static Emitter create(Properties props, AsyncHttpClient httpClient, Lifecycle lifecycle)
  {
    return create(props, httpClient, new ObjectMapper(), lifecycle);
  }

  public static Emitter create(Properties props, AsyncHttpClient httpClient, ObjectMapper jsonMapper, Lifecycle lifecycle)
  {
    Map<String, Object> jsonified = Maps.newHashMap();
    if (props.getProperty(LOG_EMITTER_PROP) != null) {
      jsonified = makeLoggingMap(props);
      jsonified.put("type", "logging");
    }
    else if (props.getProperty(HTTP_EMITTER_PROP) != null) {
      jsonified = makeHttpMap(props);
      jsonified.put("type", "http");
    }
    else if (props.getProperty(CUSTOM_EMITTER_TYPE_PROP) !=null) {
      jsonified = makeCustomFactoryMap(props);
    }
    else {
      throw new ISE(
          "Unknown type of emitter. Please set [%s], [%s] or provide registered subtype of com.metamx.emitter.core.factory.EmitterFactory via [%s]",
          LOG_EMITTER_PROP,
          HTTP_EMITTER_PROP,
          CUSTOM_EMITTER_TYPE_PROP