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