b59df5495b3752e70792724e117ce8bdf5cbac07
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / client / stress / AbstractExecutionStrategy.java
1 /*
2  * Copyright (c) 2016 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.stress;
10
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import org.opendaylight.netconf.api.NetconfMessage;
14 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
15
16 abstract class AbstractExecutionStrategy implements ExecutionStrategy {
17     private final Parameters params;
18     private final List<NetconfMessage> preparedMessages;
19     private final NetconfDeviceCommunicator sessionListener;
20     private final List<Integer> editBatches;
21     private final int editAmount;
22
23     AbstractExecutionStrategy(final Parameters params, final List<NetconfMessage> editConfigMsgs,
24                               final NetconfDeviceCommunicator sessionListener) {
25         editAmount = editConfigMsgs.size();
26         this.params = params;
27         this.preparedMessages = editConfigMsgs;
28         this.sessionListener = sessionListener;
29         this.editBatches = countEditBatchSizes(params, editConfigMsgs.size());
30     }
31
32     private static List<Integer> countEditBatchSizes(final Parameters params, final int amount) {
33         final List<Integer> editBatches = Lists.newArrayList();
34         if (params.editBatchSize != amount) {
35             final int fullBatches = amount / params.editBatchSize;
36             for (int i = 0; i < fullBatches; i++) {
37                 editBatches.add(params.editBatchSize);
38             }
39
40             if (amount % params.editBatchSize != 0) {
41                 editBatches.add(amount % params.editBatchSize);
42             }
43         } else {
44             editBatches.add(params.editBatchSize);
45         }
46         return editBatches;
47     }
48
49
50     protected Parameters getParams() {
51         return params;
52     }
53
54     protected List<NetconfMessage> getPreparedMessages() {
55         return preparedMessages;
56     }
57
58     protected NetconfDeviceCommunicator getSessionListener() {
59         return sessionListener;
60     }
61
62     protected List<Integer> getEditBatches() {
63         return editBatches;
64     }
65
66     protected int getEditAmount() {
67         return editAmount;
68     }
69 }