All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.signalfx.metrics.connection.AbstractHttpEventProtobufReceiverConnection Maven / Gradle / Ivy

The newest version!
package com.signalfx.metrics.connection;

import java.io.IOException;
import java.util.List;

import com.signalfx.shaded.apache.http.HttpEntity;
import com.signalfx.shaded.apache.http.client.methods.CloseableHttpResponse;
import com.signalfx.shaded.apache.http.conn.HttpClientConnectionManager;
import com.signalfx.shaded.apache.http.entity.ContentType;

import com.signalfx.connection.AbstractHttpReceiverConnection;
import com.signalfx.endpoint.SignalFxReceiverEndpoint;
import com.signalfx.metrics.SignalFxMetricsException;
import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;

public abstract class AbstractHttpEventProtobufReceiverConnection extends AbstractHttpReceiverConnection implements EventReceiver {

    protected static final ContentType PROTO_TYPE = ContentType.create("application/x-protobuf");

    public AbstractHttpEventProtobufReceiverConnection(
            SignalFxReceiverEndpoint endpoint,
            int timeoutMs, HttpClientConnectionManager httpClientConnectionManager) {
        super(endpoint, timeoutMs, httpClientConnectionManager);
    }

    public AbstractHttpEventProtobufReceiverConnection(
            SignalFxReceiverEndpoint endpoint,
            int timeoutMs, int maxRetries, HttpClientConnectionManager httpClientConnectionManager) {
        super(endpoint, timeoutMs, maxRetries, httpClientConnectionManager);
    }

    @Override
    public void addEvents(String auth, List events)
            throws SignalFxMetricsException {
        if (events.isEmpty()) {
            return;
        }
        try {
            CloseableHttpResponse resp = null;
            try {
                resp = postToEndpoint(auth,
                        getEntityForVersion(events),
                        getEndpointForAddEvents(),
                        false);
                checkHttpResponse(resp);
            } finally {
                if (resp != null) {
                    resp.close();
                }
            }
        } catch (IOException e) {
            throw new SignalFxMetricsException("Exception posting to addEvents", e);
        }
    }

    protected abstract String getEndpointForAddEvents();

    protected abstract HttpEntity getEntityForVersion(
            List events);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy