View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.openr66.protocol.networkhandler;
21  
22  import io.netty.handler.traffic.GlobalTrafficShapingHandler;
23  import org.waarp.common.cpu.WaarpConstraintLimitHandler;
24  import org.waarp.openr66.protocol.configuration.Configuration;
25  
26  /**
27   * R66 Constraint Limit Handler
28   * <p>
29   * Constraint Limit (CPU and connection - network and local -) handler, only for
30   * server side (requested or
31   * requester).
32   */
33  public class R66ConstraintLimitHandler extends WaarpConstraintLimitHandler {
34    public R66ConstraintLimitHandler() {
35    }
36  
37    /**
38     * @param useJdKCpuLimit True to use JDK Cpu native or False for
39     *     JavaSysMon
40     * @param lowcpuLimit for proactive cpu limitation (throttling
41     *     bandwidth)
42     *     (0<= x < 1 & highcpulimit)
43     * @param highcpuLimit for proactive cpu limitation (throttling
44     *     bandwidth)
45     *     (0<= x <= 1) 0 meaning no
46     *     throttle activated
47     * @param percentageDecrease for proactive cpu limitation,
48     *     throttling
49     *     bandwidth reduction (0 < x < 1) as 0.25
50     *     for 25% of reduction
51     * @param handler the GlobalTrafficShapingHandler associated (null
52     *     to have
53     *     no proactive cpu
54     *     limitation)
55     * @param delay the delay between 2 tests for proactive cpu
56     *     limitation
57     * @param limitLowBandwidth the minimal bandwidth (read or write) to
58     *     apply
59     *     when decreasing bandwidth (low
60     *     limit = 4096)
61     */
62    public R66ConstraintLimitHandler(final boolean useJdKCpuLimit,
63                                     final double lowcpuLimit,
64                                     final double highcpuLimit,
65                                     final double percentageDecrease,
66                                     final GlobalTrafficShapingHandler handler,
67                                     final long delay,
68                                     final long limitLowBandwidth) {
69      super(1000, Configuration.configuration != null?
70                Configuration.configuration.getTimeoutCon() : 30000, useJdKCpuLimit,
71            lowcpuLimit, highcpuLimit, percentageDecrease, handler, delay,
72            limitLowBandwidth);
73    }
74  
75    /**
76     * @param useCpuLimit True to enable cpuLimit on connection check
77     * @param useJdKCpuLimit True to use JDK Cpu native or False for
78     *     JavaSysMon
79     * @param cpulimit high cpu limit (0<= x < 1) to refuse new
80     *     connections
81     * @param channellimit number of connection limit (0<= x)
82     */
83    public R66ConstraintLimitHandler(final boolean useCpuLimit,
84                                     final boolean useJdKCpuLimit,
85                                     final double cpulimit,
86                                     final int channellimit) {
87      super(1000, Configuration.configuration != null?
88                Configuration.configuration.getTimeoutCon() : 30000, useCpuLimit,
89            useJdKCpuLimit, cpulimit, channellimit);
90    }
91  
92    /**
93     * @param useCpuLimit True to enable cpuLimit on connection check
94     * @param useJdKCpuLimit True to use JDK Cpu native or False for
95     *     JavaSysMon
96     * @param cpulimit high cpu limit (0<= x < 1) to refuse new
97     *     connections
98     * @param channellimit number of connection limit (0<= x)
99     * @param lowcpuLimit for proactive cpu limitation (throttling
100    *     bandwidth)
101    *     (0<= x < 1 & highcpulimit)
102    * @param highcpuLimit for proactive cpu limitation (throttling
103    *     bandwidth)
104    *     (0<= x <= 1) 0 meaning no
105    *     throttle activated
106    * @param percentageDecrease for proactive cpu limitation,
107    *     throttling
108    *     bandwidth reduction (0 < x < 1) as 0.25
109    *     for 25% of reduction
110    * @param handler the GlobalTrafficShapingHandler associated (null
111    *     to have
112    *     no proactive cpu
113    *     limitation)
114    * @param delay the delay between 2 tests for proactive cpu
115    *     limitation
116    * @param limitLowBandwidth the minimal bandwidth (read or write) to
117    *     apply
118    *     when decreasing bandwidth (low
119    *     limit = 4096)
120    */
121   public R66ConstraintLimitHandler(final boolean useCpuLimit,
122                                    final boolean useJdKCpuLimit,
123                                    final double cpulimit,
124                                    final int channellimit,
125                                    final double lowcpuLimit,
126                                    final double highcpuLimit,
127                                    final double percentageDecrease,
128                                    final GlobalTrafficShapingHandler handler,
129                                    final long delay,
130                                    final long limitLowBandwidth) {
131     super(1000, Configuration.configuration != null?
132               Configuration.configuration.getTimeoutCon() : 30000, useCpuLimit,
133           useJdKCpuLimit, cpulimit, channellimit, lowcpuLimit, highcpuLimit,
134           percentageDecrease, handler, delay, limitLowBandwidth);
135   }
136 
137   @Override
138   protected final int getNumberLocalChannel() {
139     if (Configuration.configuration.getLocalTransaction() != null) {
140       return Configuration.configuration.getLocalTransaction()
141                                         .getNumberLocalChannel();
142     }
143     return 0;
144   }
145 
146   @Override
147   protected final long getReadLimit() {
148     return Configuration.configuration.getServerGlobalReadLimit();
149   }
150 
151   @Override
152   protected final long getWriteLimit() {
153     return Configuration.configuration.getServerGlobalWriteLimit();
154   }
155 
156 }