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

com.applitools.connectivity.api.AbstractAsyncCallback Maven / Gradle / Ivy

There is a newer version: 5.66.0
Show newest version
package com.applitools.connectivity.api;

import com.applitools.eyes.Logger;
import com.applitools.eyes.TaskListener;
import com.applitools.eyes.logging.Stage;
import com.applitools.utils.GeneralUtils;

public abstract class AbstractAsyncCallback implements AsyncRequestCallback {

    private final Logger logger;
    private final TaskListener listener;

    public AbstractAsyncCallback(Logger logger, TaskListener listener) {
        this.logger = logger;
        this.listener = listener;
    }

    protected abstract T onCompleteInner(Response response);

    @Override
    public void onComplete(Response response) {
        try {
            listener.onComplete(onCompleteInner(response));
        } catch (Throwable t) {
            onFail(t);
        } finally {
            response.close();
        }
    }

    @Override
    public void onFail(Throwable throwable) {
        GeneralUtils.logExceptionStackTrace(logger, Stage.GENERAL, throwable);
        listener.onFail();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy