Search in sources :

Example 1 with AsyncOperationImpl

use of com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl in project vespa by vespa-engine.

the class ApacheAsyncHttpClient method execute.

@Override
public AsyncOperation<HttpResult> execute(HttpRequest r) {
    // Gonna modify it to extract proxy information
    final HttpRequest request = r.clone();
    final Settings settings = new Settings(request);
    final SyncHttpClient instance = getFittingInstance(settings);
    final AsyncOperationImpl<HttpResult> op = new AsyncOperationImpl<>(r.toString(), r.toString(true));
    executor.execute(new Runnable() {

        @Override
        public void run() {
            HttpResult result;
            Exception failure = null;
            try {
                result = instance.execute(request);
            } catch (Exception e) {
                result = new HttpResult().setHttpCode(500, "Apache client failed to execute request.");
                failure = e;
            }
            insertInstance(settings, instance);
            // call can reuse same instance
            if (failure != null) {
                op.setFailure(failure, result);
            } else {
                op.setResult(result);
            }
        }
    });
    return op;
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) AsyncOperationImpl(com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) SyncHttpClient(com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)

Aggregations

AsyncOperationImpl (com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl)1 HttpRequest (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest)1 HttpResult (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)1 SyncHttpClient (com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)1