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
8 package org.opendaylight.netconf.test.tool.client.http.perf;
10 import java.net.Authenticator;
11 import java.net.PasswordAuthentication;
12 import java.net.http.HttpClient;
13 import java.net.http.HttpClient.Builder;
14 import java.util.concurrent.Callable;
15 import org.opendaylight.netconf.test.tool.client.http.perf.RestPerfClient.RequestData;
16 import org.opendaylight.netconf.test.tool.client.stress.ExecutionStrategy;
18 public class PerfClientCallable implements Callable<Void> {
19 private final ExecutionStrategy executionStrategy;
21 public PerfClientCallable(final Parameters params, final RequestData payloads) {
22 final Builder builder = HttpClient.newBuilder();
23 if (params.auth != null) {
24 builder.authenticator(new Authenticator() {
26 protected PasswordAuthentication getPasswordAuthentication() {
27 return new PasswordAuthentication(params.auth.get(0), params.auth.get(1).toCharArray());
32 this.executionStrategy = params.async
33 ? new AsyncExecutionStrategy(params, builder.build(), payloads)
34 : new SyncExecutionStrategy(builder.build(), payloads);
39 executionStrategy.invoke();