XComp commented on a change in pull request #15049: URL: https://github.com/apache/flink/pull/15049#discussion_r590525413
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/util/BoundedFIFOQueue.java ########## @@ -0,0 +1,141 @@ +/* + * 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.flink.runtime.util; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.util.Preconditions; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; + +/** + * {@code BoundedFIFOQueue} collects elements up to given amount. Reaching this limit will result in + * removing the oldest element from this queue (First-In/First-Out; FIFO). + * + * @param <T> The type of elements collected. + */ +public class BoundedFIFOQueue<T> implements Iterable<T>, Serializable { + + private static final long serialVersionUID = -890727339944580409L; + + private final int maxSize; + private final Queue<T> elements; + + private int elementCount; + + /** + * Creates an immutable copy of the passed {@code BoundedFIFOQueue}. + * + * @param boundedFIFOQueue The queue for which an immutable copy shall be created. + * @param <E> The type this queue collects. + * @return An immutable copy of the passed {@code BoundedFIFOQueue}. + */ + public static <E> BoundedFIFOQueue<E> immutableCopy(BoundedFIFOQueue<E> boundedFIFOQueue) { + return new BoundedFIFOQueue<E>( + boundedFIFOQueue.maxSize, + boundedFIFOQueue.elements, + boundedFIFOQueue.elementCount) { + private static final long serialVersionUID = -2763611608109517436L; + + @Override + public void add(E element) { Review comment: You're right. Returning an `Iterable` would be the easiest solution if we decide that the total exception value returned as part of the exception history is not a feature we want. Otherwise, we would have to introduce an interface. I will wait with the resolution after [the `total` discussion](https://github.com/apache/flink/pull/15049#discussion_r590203591) is sorted. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
