Search in sources :

Example 1 with SyncHttpClient

use of com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient 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)

Example 2 with SyncHttpClient

use of com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient in project vespa by vespa-engine.

the class ApacheAsyncHttpClient method close.

@Override
public void close() {
    synchronized (apacheInstances) {
        closed = true;
        for (LinkedList<SyncHttpClient> list : apacheInstances.values()) {
            for (SyncHttpClient instance : list) {
                instance.close();
            }
        }
        apacheInstances.clear();
    }
}
Also used : SyncHttpClient(com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)

Aggregations

SyncHttpClient (com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)2 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