ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/util/ExactRateLimiter.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/util/ExactRateLimiter.java
Status
scanned
Type
file
Name
ExactRateLimiter.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
2403 (2.3 KB)
MD5
6f120e54e166376bd0649d6ffbdc3cde
SHA1
f1d5bb3eb9c5fe4966da0846e79efc1420100337
SHA256
e0bb8bf1204e6f543aca3c4ee2e27f0b385dca6bf9fa00a2f72c9fb98afdf86a
SHA512

      
    
SHA1_git
caf10056b3faa0455a6d2a8806112892315b7f7a
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ExactRateLimiter.java | 2.3 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.util; import java.util.concurrent.ScheduledExecutorService; /** * A RateLimiter that compromises efficiency for accuracy in order to provide exact rate limiting. */ public class ExactRateLimiter extends RateLimiterBase { @Override protected String getDefaultPolicyName() { return "exact"; } @Override protected TimeBucketCounterBase newCounterInstance(int duration, ScheduledExecutorService executorService) { return new ExactTimeBucketCounter(duration, executorService); } /** * An accurate counter with exact bucket index, but slightly less efficient than another fast counter provided with * the {@link FastRateLimiter}. */ static class ExactTimeBucketCounter extends TimeBucketCounterBase { ExactTimeBucketCounter(int bucketDuration, ScheduledExecutorService executorService) { super(bucketDuration, executorService); } @Override public long getBucketIndex(long timestamp) { return (timestamp / 1000) / getBucketDuration(); } @Override public double getRatio() { // Actual value is exactly the same as declared return 1.0d; } @Override public long getMillisUntilNextBucket() { long millis = System.currentTimeMillis(); long nextTimeBucketMillis = (getBucketIndex(millis) + 1) * getBucketDuration() * 1000; return nextTimeBucketMillis - millis; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
49.58
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9