ptlrs commented on code in PR #8498: URL: https://github.com/apache/ozone/pull/8498#discussion_r2216924506
########## hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/SlidingWindow.java: ########## @@ -0,0 +1,162 @@ +/* + * 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.hadoop.hdds.utils; + +import java.time.Clock; +import java.time.Duration; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.concurrent.TimeUnit; + +/** + * + * A sliding window implementation that combines time-based expiry with a + * maximum size constraint. The window tracks event timestamps and maintains two + * limits: + * <ul> + * <li>Time-based: Events older than the specified expiry duration are + * automatically removed + * <li>Size-based: The window maintains at most windowSize latest events, removing + * older events when this limit is exceeded + * </ul> + * + * The window is considered full when the number of non-expired events exceeds + * the specified window size. Events are automatically pruned based on both + * their age and the maximum size constraint. + */ +public class SlidingWindow { + private final Object lock = new Object(); Review Comment: The implementation suggestion as per the [safety guidelines](https://wiki.sei.cmu.edu/confluence/display/java/LCK00-J.+Use+private+final+lock+objects+to+synchronize+classes+that+may+interact+with+untrusted+code) is to initialize the lock as a field. Field initializing the lock will create the object before the constructor runs. While that is likely not a concern for this class, we should perhaps follow the standard implementation guideline. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org