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

io.prediction.FutureAPIResponse Maven / Gradle / Ivy

package io.prediction;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * TappingStone implementation of Java Utility Concurrent Future
 *
 * @author The PredictionIO Team (http://prediction.io)
 * @version 0.2
 * @since 0.2
 */

public class FutureAPIResponse implements Future {
    private Future apiResponse;

    public FutureAPIResponse(Future apiResponse) {
        this.apiResponse = apiResponse;
    }

    public boolean cancel(boolean mayInterruptIfRunning) {
        return this.apiResponse.cancel(mayInterruptIfRunning);
    }

    public APIResponse get() throws ExecutionException, InterruptedException {
        return this.apiResponse.get();
    }

    public APIResponse get(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException {
        return this.apiResponse.get(timeout, unit);
    }

    public boolean isCancelled() {
        return this.apiResponse.isCancelled();
    }

    public boolean isDone() {
        return this.apiResponse.isDone();
    }

    public int getStatus() {
        try {
            return this.apiResponse.get().getStatus();
        } catch (InterruptedException e) {
            return 0;
        } catch (ExecutionException e) {
            return 0;
        }
    }

    public String getMessage() {
        try {
            return this.apiResponse.get().getMessage();
        } catch (InterruptedException e) {
            return e.getMessage();
        } catch (ExecutionException e) {
            return e.getMessage();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy