Bug 8153: enforce check-style rules for netconf
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / client / http / perf / SyncExecutionStrategy.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.test.tool.client.http.perf;
10
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;
20
21 public class SyncExecutionStrategy implements ExecutionStrategy {
22
23     private static final Logger LOG = LoggerFactory.getLogger(SyncExecutionStrategy.class);
24
25     private final Parameters params;
26     private final ArrayList<Request> payloads;
27     private final AsyncHttpClient asyncHttpClient;
28
29     SyncExecutionStrategy(final Parameters params, final AsyncHttpClient asyncHttpClient,
30                           final ArrayList<Request> payloads) {
31         this.params = params;
32         this.asyncHttpClient = asyncHttpClient;
33         this.payloads = payloads;
34     }
35
36     @Override
37     public void invoke() {
38
39         LOG.info("Begin sending sync requests");
40         for (Request request : payloads) {
41             try {
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());
47                 }
48             } catch (InterruptedException | ExecutionException | IOException e) {
49                 LOG.warn(e.toString());
50             }
51         }
52         LOG.info("End sending sync requests");
53
54     }
55 }