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

com.eg.agent.android.instrumentation.okhttp3.CallExtension Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.instrumentation.okhttp3;

/*import com.newrelic.agent.android.TaskQueue;
import com.newrelic.agent.android.api.common.TransactionData;
import com.newrelic.agent.android.instrumentation.TransactionState;
import com.newrelic.agent.android.instrumentation.TransactionStateUtil;
import com.newrelic.agent.android.logging.AgentLog;
import com.newrelic.agent.android.logging.AgentLogManager;
import com.newrelic.agent.android.measurement.http.HttpTransactionMeasurement;*/

import com.eg.agent.android.common.TransactionData;
import com.eg.agent.android.TaskQueue;
import com.eg.agent.android.instrumentation.TransactionState;
import com.eg.agent.android.instrumentation.TransactionStateUtil;
import com.eg.agent.android.logging.AgentLog;
import com.eg.agent.android.logging.AgentLogManager;
import com.eg.agent.android.measurement.http.HttpTransactionMeasurement;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public  class CallExtension implements Call {
    private static final AgentLog log = AgentLogManager.getAgentLog();
    private OkHttpClient client;
    private Call impl;
    private Request request;
    private TransactionState transactionState;

    CallExtension(OkHttpClient client, Request request, Call impl) {
        this.client = client;
        this.request = request;
        this.impl = impl;
    }

    public Request request() {
        return this.impl.request();
    }

    public Response execute() throws IOException {
        getTransactionState();
        try {
            return checkResponse(this.impl.execute());
        } catch (IOException e) {
            error(e);
            throw e;
        }
    }

    public void enqueue(Callback responseCallback) {
        getTransactionState();
        this.impl.enqueue(new CallbackExtension(responseCallback, this.transactionState));
    }

    public void cancel() {
        this.impl.cancel();
    }

    public boolean isExecuted() {
        return false;
    }

    public boolean isCanceled() {
        return this.impl.isCanceled();
    }

    @Override
    public Call clone() {
        return null;
    }

    private Response checkResponse(Response response) {
        if (getTransactionState().isComplete()) {
            return response;
        }
        return OkHttp3TransactionStateUtil.inspectAndInstrumentResponse(getTransactionState(), response);
    }

    private TransactionState getTransactionState() {
        if (this.transactionState == null) {
            this.transactionState = new TransactionState();
            OkHttp3TransactionStateUtil.inspectAndInstrument(this.transactionState, this.request);
        }
        return this.transactionState;
    }

    private void error(Exception e) {
        TransactionState transactionState = getTransactionState();
        TransactionStateUtil.setErrorCodeFromException(transactionState, e);
        if (!transactionState.isComplete()) {
            TransactionData transactionData = transactionState.end();
            if (transactionData != null) {
                TaskQueue.queue(new HttpTransactionMeasurement(transactionData.getUrl(), transactionData.getHttpMethod(), transactionData.getStatusCode(), transactionData.getErrorCode(), transactionData.getTimestamp(), (double) transactionData.getTime(), transactionData.getBytesSent(), transactionData.getBytesReceived(), transactionData.getAppData()));
            }
        }
    }

    public Call getImpl() {
        return this.impl;
    }
}


/*
package com.eg.agent.android.instrumentation.okhttp3;

*/
/*import com.newrelic.agent.android.TaskQueue;
import com.newrelic.agent.android.api.common.TransactionData;
import com.newrelic.agent.android.instrumentation.TransactionState;
import com.newrelic.agent.android.instrumentation.TransactionStateUtil;
import com.newrelic.agent.android.logging.AgentLog;
import com.newrelic.agent.android.logging.AgentLogManager;
import com.newrelic.agent.android.measurement.http.HttpTransactionMeasurement;*//*


import com.eg.agent.android.common.TransactionData;
import com.eg.agent.android.instrumentation.TaskQueue;
import com.eg.agent.android.instrumentation.TransactionState;
import com.eg.agent.android.instrumentation.TransactionStateUtil;
import com.eg.agent.android.logging.AgentLog;
import com.eg.agent.android.logging.AgentLogManager;
import com.eg.agent.android.measurement.http.HttpTransactionMeasurement;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class CallExtension implements Call {
    private static final AgentLog log = AgentLogManager.getAgentLog();
    private OkHttpClient client;
    private Call impl;
    private Request request;
    private TransactionState transactionState;

    CallExtension(OkHttpClient client, Request request, Call impl) {
        this.client = client;
        this.request = request;
        this.impl = impl;
    }

    public Request request() {
        return this.impl.request();
    }

    public Response execute() throws IOException {
        getTransactionState();
        try {
            return checkResponse(this.impl.execute());
        } catch (IOException e) {
            error(e);
            throw e;
        }
    }

    public void enqueue(Callback responseCallback) {
        getTransactionState();
        this.impl.enqueue(new CallbackExtension(responseCallback, this.transactionState));
    }

    public void cancel() {
        this.impl.cancel();
    }

    public boolean isExecuted() {
        return false;
    }

    public boolean isCanceled() {
        return this.impl.isCanceled();
    }

    @Override
    public Call clone() {
        return null;
    }

    private Response checkResponse(Response response) {
        if (getTransactionState().isComplete()) {
            return response;
        }
        return OkHttp3TransactionStateUtil.inspectAndInstrumentResponse(getTransactionState(), response);
    }

    private TransactionState getTransactionState() {
        if (this.transactionState == null) {
            this.transactionState = new TransactionState();
            OkHttp3TransactionStateUtil.inspectAndInstrument(this.transactionState, this.request);
        }
        return this.transactionState;
    }

    private void error(Exception e) {
        TransactionState transactionState = getTransactionState();
        TransactionStateUtil.setErrorCodeFromException(transactionState, e);
        if (!transactionState.isComplete()) {
            TransactionData transactionData = transactionState.end();
            if (transactionData != null) {
                TaskQueue.queue(new HttpTransactionMeasurement(transactionData.getUrl(), transactionData.getHttpMethod(), transactionData.getStatusCode(), transactionData.getErrorCode(), transactionData.getTimestamp(), (double) transactionData.getTime(), transactionData.getBytesSent(), transactionData.getBytesReceived(), transactionData.getAppData()));
            }
        }
    }

    public Call getImpl() {
        return this.impl;
    }
}
*/




© 2015 - 2024 Weber Informatics LLC | Privacy Policy