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.Request;
13 import com.ning.http.client.Response;
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.concurrent.ExecutionException;
17 import org.opendaylight.netconf.test.tool.client.stress.ExecutionStrategy;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class SyncExecutionStrategy implements ExecutionStrategy {
23 private static final Logger LOG = LoggerFactory.getLogger(SyncExecutionStrategy.class);
25 private final Parameters params;
26 private final ArrayList<Request> payloads;
27 private final AsyncHttpClient asyncHttpClient;
29 SyncExecutionStrategy(final Parameters params, final AsyncHttpClient asyncHttpClient,
30 final ArrayList<Request> payloads) {
32 this.asyncHttpClient = asyncHttpClient;
33 this.payloads = payloads;
37 public void invoke() {
39 LOG.info("Begin sending sync requests");
40 for (Request request : payloads) {
42 Response response = asyncHttpClient.executeRequest(request).get();
43 if (response.getStatusCode() != 200 && response.getStatusCode() != 204) {
44 LOG.warn("Status code: {}", response.getStatusCode());
45 LOG.warn("url: {}", request.getUrl());
46 LOG.warn(response.getResponseBody());
48 } catch (InterruptedException | ExecutionException | IOException e) {
49 LOG.warn(e.toString());
52 LOG.info("End sending sync requests");