X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2Fclient%2Fhttp%2Fperf%2FPerfClientCallable.java;fp=opendaylight%2Fnetconf%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2Fclient%2Fhttp%2Fperf%2FPerfClientCallable.java;h=fa444d9b0cc73e59abc49587ed992770df40c287;hb=841c95ad7b9284ca17738cfd3b60001af06674a8;hp=0000000000000000000000000000000000000000;hpb=41a04c117375a7d81b85b4a59198c3b7b633c12f;p=controller.git diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/http/perf/PerfClientCallable.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/http/perf/PerfClientCallable.java new file mode 100644 index 0000000000..fa444d9b0c --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/http/perf/PerfClientCallable.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.test.tool.client.http.perf; + +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.AsyncHttpClientConfig; +import com.ning.http.client.Request; +import java.util.ArrayList; +import java.util.concurrent.Callable; +import org.opendaylight.controller.netconf.test.tool.client.http.perf.RestPerfClient.DestToPayload; +import org.opendaylight.controller.netconf.test.tool.client.stress.ExecutionStrategy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PerfClientCallable implements Callable{ + + private static final Logger LOG = LoggerFactory.getLogger(PerfClientCallable.class); + + private final Parameters params; + private final ArrayList payloads; + private final AsyncHttpClient asyncHttpClient; + private ExecutionStrategy executionStrategy; + + public PerfClientCallable(Parameters params, ArrayList payloads) { + this.params = params; + this.asyncHttpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder() + .setConnectTimeout(Integer.MAX_VALUE) + .setRequestTimeout(Integer.MAX_VALUE) + .setAllowPoolingConnections(true) + .build()); + this.payloads = new ArrayList<>(); + for (DestToPayload payload : payloads) { + this.payloads.add(asyncHttpClient.preparePost(payload.getDestination()) + .addHeader("content-type", "application/json") + .addHeader("Accept", "application/xml") + .setBody(payload.getPayload()) + .setRequestTimeout(Integer.MAX_VALUE) + .build()); + } + executionStrategy = getExecutionStrategy(); + } + + private ExecutionStrategy getExecutionStrategy() { + return params.async + ? new AsyncExecutionStrategy(params, asyncHttpClient, payloads) + : new SyncExecutionStrategy(params, asyncHttpClient, payloads); + } + + @Override + public Void call() throws Exception{ + + executionStrategy.invoke(); + asyncHttpClient.closeAsynchronously(); + return null; + } +}