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.controller.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.controller.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, final ArrayList<Request> payloads) {
31 this.asyncHttpClient = asyncHttpClient;
32 this.payloads = payloads;
36 public void invoke() {
38 LOG.info("Begin sending sync requests");
39 for (Request request : payloads) {
41 Response response = asyncHttpClient.executeRequest(request).get();
42 if (response.getStatusCode() != 200 && response.getStatusCode() != 204) {
43 LOG.warn("Status code: {}", response.getStatusCode());
44 LOG.warn("url: {}", request.getUrl());
45 LOG.warn(response.getResponseBody());
47 } catch (InterruptedException | ExecutionException | IOException e) {
48 LOG.warn(e.toString());
51 LOG.info("End sending sync requests");