// Path: src/main/java/org/wildfly/metrics/scheduler/config/Configuration.java
// public interface Configuration {
// 
//     public enum Diagnostics {STORAGE, CONSOLE};
//     public enum Storage {RHQ, INFLUX}
// 
//     /**
//      * The host controller host.
//      * @return
//      */
//     String getHost();
// 
//     /**
//      * The host controller port.
//      *
//      * @return
//      */
//     int getPort();
// 
//     /**
//      * Host controller user
//      * @return
//      */
//     String getUsername();
// 
//     /**
//      * Host controller password
//      * @return
//      */
//     String getPassword();
// 
//     /**
//      * Number of threads the scheduler uses to poll for new data.
//      *
//      * @return
//      */
//     int getSchedulerThreads();
// 
//     /**
//      * The resources that are to be monitored.
//      * {@link org.wildfly.metrics.scheduler.config.ResourceRef}'s use relative addresses.
//      * The core {@link org.wildfly.metrics.scheduler.Service} will resolve it against absolute address within a Wildfly domain.
//      *
//      * @return
//      */
//     List<ResourceRef> getResourceRefs();
// 
//     Storage getStorageAdapter();
// 
//     String getStorageUrl();
// 
//     String getStorageUser();
// 
//     String getStoragePassword();
// 
//     String getStorageDBName();
// 
//     String getStorageToken();
// 
//     Diagnostics getDiagnostics();
// 
// }
// 
// Path: src/main/java/org/wildfly/metrics/scheduler/diagnose/Diagnostics.java
// public interface Diagnostics {
//     Timer getRequestTimer();
//     Meter getErrorRate();
//     Meter getDelayedRate();
// 
//     Meter getStorageErrorRate();
//     Counter getStorageBufferSize();
// }
// 
// Path: src/main/java/org/wildfly/metrics/scheduler/polling/Task.java
// public class Task {
// 
//     private final String host;
//     private final String server;
//     private final Address address;
//     private final String attribute;
//     private final String subref;
//     private final Interval interval;
// 
//     public Task(
//             String host, String server,
//             Address address,
//             String attribute,
//             String subref,
//             Interval interval
//     ) {
//         this.host = host;
//         this.server = server;
//         this.address = address;
//         this.attribute = attribute;
//         this.subref = subref;
//         this.interval = interval;
//     }
// 
//     public Address getAddress() {
//         return address;
//     }
// 
//     public String getAttribute() {
//         return attribute;
//     }
// 
//     public Interval getInterval() {
//         return interval;
//     }
// 
//     public String getSubref() {
//         return subref;
//     }
// 
//     public String getHost() {
//         return host;
//     }
// 
//     public String getServer() {
//         return server;
//     }
// 
//     @Override
//     public String toString() {
//         return "Task{" +
//                 "address=" + address +
//                 ", attribute='" + attribute + '\'' +
//                 '}';
//     }
// }


import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.rhq.metrics.client.common.Batcher;
import org.rhq.metrics.client.common.SingleMetric;
import org.wildfly.metrics.scheduler.config.Configuration;
import org.wildfly.metrics.scheduler.diagnose.Diagnostics;
import org.wildfly.metrics.scheduler.polling.Task;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
package org.wildfly.metrics.scheduler.storage;



/**
 * Pushes the data to RHQ metrics.
 *
 * @author Heiko Braun
 * @since 13/10/14
 */
public class RHQStorageAdapter implements StorageAdapter {

    private Configuration config;
    private Diagnostics diagnostics;
    private final HttpClient httpclient;
    private final DefaultKeyResolution keyResolution;

    public RHQStorageAdapter() {
        this.httpclient = new DefaultHttpClient();
        this.keyResolution = new DefaultKeyResolution();
    }

    @Override
    public void setConfiguration(Configuration config) {
        this.config = config;
    }

    @Override
    public void setDiagnostics(Diagnostics diag) {
        this.diagnostics = diag;
    }

    @Override
    public void store(Set<DataPoint> datapoints) {
        HttpPost post = new HttpPost(config.getStorageUrl());
        try {
            List<SingleMetric> metrics = new ArrayList<>();

            for (DataPoint datapoint : datapoints) {
// Path: src/main/java/org/wildfly/metrics/scheduler/config/Configuration.java
// public interface Configuration {
// 
//     public enum Diagnostics {STORAGE, CONSOLE};
//     public enum Storage {RHQ, INFLUX}
// 
//     /**
//      * The host controller host.
//      * @return
//      */
//     String getHost();
// 
//     /**
//      * The host controller port.
//      *
//      * @return
//      */
//     int getPort();
// 
//     /**
//      * Host controller user
//      * @return
//      */
//     String getUsername();
// 
//     /**
//      * Host controller password
//      * @return
//      */
//     String getPassword();
// 
//     /**
//      * Number of threads the scheduler uses to poll for new data.
//      *
//      * @return
//      */
//     int getSchedulerThreads();
// 
//     /**
//      * The resources that are to be monitored.
//      * {@link org.wildfly.metrics.scheduler.config.ResourceRef}'s use relative addresses.
//      * The core {@link org.wildfly.metrics.scheduler.Service} will resolve it against absolute address within a Wildfly domain.
//      *
//      * @return
//      */
//     List<ResourceRef> getResourceRefs();
// 
//     Storage getStorageAdapter();
// 
//     String getStorageUrl();
// 
//     String getStorageUser();
// 
//     String getStoragePassword();
// 
//     String getStorageDBName();
// 
//     String getStorageToken();
// 
//     Diagnostics getDiagnostics();
// 
// }
// 
// Path: src/main/java/org/wildfly/metrics/scheduler/diagnose/Diagnostics.java
// public interface Diagnostics {
//     Timer getRequestTimer();
//     Meter getErrorRate();
//     Meter getDelayedRate();
// 
//     Meter getStorageErrorRate();
//     Counter getStorageBufferSize();
// }
// 
// Path: src/main/java/org/wildfly/metrics/scheduler/polling/Task.java
// public class Task {
// 
//     private final String host;
//     private final String server;
//     private final Address address;
//     private final String attribute;
//     private final String subref;
//     private final Interval interval;
// 
//     public Task(
//             String host, String server,
//             Address address,
//             String attribute,
//             String subref,
//             Interval interval
//     ) {
//         this.host = host;
//         this.server = server;
//         this.address = address;
//         this.attribute = attribute;
//         this.subref = subref;
//         this.interval = interval;
//     }
// 
//     public Address getAddress() {
//         return address;
//     }
// 
//     public String getAttribute() {
//         return attribute;
//     }
// 
//     public Interval getInterval() {
//         return interval;
//     }
// 
//     public String getSubref() {
//         return subref;
//     }
// 
//     public String getHost() {
//         return host;
//     }
// 
//     public String getServer() {
//         return server;
//     }
// 
//     @Override
//     public String toString() {
//         return "Task{" +
//                 "address=" + address +
//                 ", attribute='" + attribute + '\'' +
//                 '}';
//     }
// }


// Path: src/main/java/org/wildfly/metrics/scheduler/storage/RHQStorageAdapter.java
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.rhq.metrics.client.common.Batcher;
import org.rhq.metrics.client.common.SingleMetric;
import org.wildfly.metrics.scheduler.config.Configuration;
import org.wildfly.metrics.scheduler.diagnose.Diagnostics;
import org.wildfly.metrics.scheduler.polling.Task;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

package org.wildfly.metrics.scheduler.storage;



/**
 * Pushes the data to RHQ metrics.
 *
 * @author Heiko Braun
 * @since 13/10/14
 */
public class RHQStorageAdapter implements StorageAdapter {

    private Configuration config;
    private Diagnostics diagnostics;
    private final HttpClient httpclient;
    private final DefaultKeyResolution keyResolution;

    public RHQStorageAdapter() {
        this.httpclient = new DefaultHttpClient();
        this.keyResolution = new DefaultKeyResolution();
    }

    @Override
    public void setConfiguration(Configuration config) {
        this.config = config;
    }

    @Override
    public void setDiagnostics(Diagnostics diag) {
        this.diagnostics = diag;
    }

    @Override
    public void store(Set<DataPoint> datapoints) {
        HttpPost post = new HttpPost(config.getStorageUrl());
        try {
            List<SingleMetric> metrics = new ArrayList<>();

            for (DataPoint datapoint : datapoints) {
                Task task = datapoint.getTask();