2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.test.tool.client.http.perf;
11 import com.ning.http.client.AsyncHttpClient;
12 import com.ning.http.client.AsyncHttpClientConfig;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.netconf.test.tool.client.http.perf.RestPerfClient.RequestData;
15 import org.opendaylight.netconf.test.tool.client.stress.ExecutionStrategy;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class PerfClientCallable implements Callable<Void> {
20 private static final Logger LOG = LoggerFactory.getLogger(PerfClientCallable.class);
22 private final Parameters params;
23 private final AsyncHttpClient asyncHttpClient;
24 private ExecutionStrategy executionStrategy;
25 private RequestData payloads;
27 public PerfClientCallable(Parameters params, RequestData payloads) {
29 this.payloads = payloads;
30 this.asyncHttpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder()
31 .setConnectTimeout(Integer.MAX_VALUE)
32 .setRequestTimeout(Integer.MAX_VALUE)
33 .setAllowPoolingConnections(true)
35 executionStrategy = getExecutionStrategy();
38 private ExecutionStrategy getExecutionStrategy() {
40 ? new AsyncExecutionStrategy(params, asyncHttpClient, payloads)
41 : new SyncExecutionStrategy(params, asyncHttpClient, payloads);
46 executionStrategy.invoke();
47 asyncHttpClient.closeAsynchronously();