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.gateway.ftp.control; 21 22 import io.netty.handler.traffic.GlobalTrafficShapingHandler; 23 import org.waarp.common.cpu.WaarpConstraintLimitHandler; 24 import org.waarp.gateway.ftp.config.FileBasedConfiguration; 25 26 /** 27 * Constraint Limit (CPU and connection - network and local -) handler. 28 */ 29 public class FtpConstraintLimitHandler extends WaarpConstraintLimitHandler { 30 31 /** 32 * @param useJdkCpuLimit True to use JDK Cpu native or False for 33 * JavaSysMon 34 * @param lowcpuLimit for proactive cpu limitation (throttling 35 * bandwidth) 36 * (0<= x < 1 & highcpulimit) 37 * @param highcpuLimit for proactive cpu limitation (throttling 38 * bandwidth) 39 * (0<= x <= 1) 0 meaning no 40 * throttle activated 41 * @param percentageDecrease for proactive cpu limitation, 42 * throttling 43 * bandwidth reduction (0 < x < 1) as 0.25 44 * for 25% of reduction 45 * @param handler the GlobalTrafficShapingHandler associated (null 46 * to have 47 * no proactive cpu 48 * limitation) 49 * @param delay the delay between 2 tests for proactive cpu 50 * limitation 51 * @param limitLowBandwidth the minimal bandwidth (read or write) to 52 * apply 53 * when decreasing bandwidth (low 54 * limit = 4096) 55 */ 56 public FtpConstraintLimitHandler(final long timeoutcon, 57 final boolean useJdkCpuLimit, 58 final double lowcpuLimit, 59 final double highcpuLimit, 60 final double percentageDecrease, 61 final GlobalTrafficShapingHandler handler, 62 final long delay, 63 final long limitLowBandwidth) { 64 super(1000, timeoutcon, useJdkCpuLimit, lowcpuLimit, highcpuLimit, 65 percentageDecrease, handler, delay, limitLowBandwidth); 66 } 67 68 /** 69 * @param useCpuLimit True to enable cpuLimit on connection check 70 * @param useJdKCpuLimit True to use JDK Cpu native or False for 71 * JavaSysMon 72 * @param cpulimit high cpu limit (0<= x < 1) to refuse new 73 * connections 74 * @param channellimit number of connection limit (0<= x) 75 */ 76 public FtpConstraintLimitHandler(final long timeoutcon, 77 final boolean useCpuLimit, 78 final boolean useJdKCpuLimit, 79 final double cpulimit, 80 final int channellimit) { 81 super(1000, timeoutcon, useCpuLimit, useJdKCpuLimit, cpulimit, 82 channellimit); 83 } 84 85 /** 86 * @param useCpuLimit True to enable cpuLimit on connection check 87 * @param useJdKCpuLimit True to use JDK Cpu native or False for 88 * JavaSysMon 89 * @param cpulimit high cpu limit (0<= x < 1) to refuse new 90 * connections 91 * @param channellimit number of connection limit (0<= x) 92 * @param lowcpuLimit for proactive cpu limitation (throttling 93 * bandwidth) 94 * (0<= x < 1 & highcpulimit) 95 * @param highcpuLimit for proactive cpu limitation (throttling 96 * bandwidth) 97 * (0<= x <= 1) 0 meaning no 98 * throttle activated 99 * @param percentageDecrease for proactive cpu limitation, 100 * throttling 101 * bandwidth reduction (0 < x < 1) as 0.25 102 * for 25% of reduction 103 * @param handler the GlobalTrafficShapingHandler associated (null 104 * to have 105 * no proactive cpu 106 * limitation) 107 * @param delay the delay between 2 tests for proactive cpu 108 * limitation 109 * @param limitLowBandwidth the minimal bandwidth (read or write) to 110 * apply 111 * when decreasing bandwidth (low 112 * limit = 4096) 113 */ 114 public FtpConstraintLimitHandler(final long timeoutcon, 115 final boolean useCpuLimit, 116 final boolean useJdKCpuLimit, 117 final double cpulimit, 118 final int channellimit, 119 final double lowcpuLimit, 120 final double highcpuLimit, 121 final double percentageDecrease, 122 final GlobalTrafficShapingHandler handler, 123 final long delay, 124 final long limitLowBandwidth) { 125 super(1000, timeoutcon, useCpuLimit, useJdKCpuLimit, cpulimit, channellimit, 126 lowcpuLimit, highcpuLimit, percentageDecrease, handler, delay, 127 limitLowBandwidth); 128 } 129 130 @Override 131 protected final int getNumberLocalChannel() { 132 return FileBasedConfiguration.fileBasedConfiguration.getFtpInternalConfiguration() 133 .getNumberSessions(); 134 } 135 136 @Override 137 protected final long getReadLimit() { 138 return FileBasedConfiguration.fileBasedConfiguration.getServerGlobalReadLimit(); 139 } 140 141 @Override 142 protected final long getWriteLimit() { 143 return FileBasedConfiguration.fileBasedConfiguration.getServerGlobalWriteLimit(); 144 } 145 146 }