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