eolivelli commented on a change in pull request #510: Issue-605 BP-15 New CreateLedger API URL: https://github.com/apache/bookkeeper/pull/510#discussion_r140967850
########## File path: bookkeeper-common/src/main/java/org/apache/bookkeeper/util/OrderedScheduler.java ########## @@ -0,0 +1,346 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.bookkeeper.util; + +import com.google.common.base.Objects; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.bookkeeper.common.concurrent.FutureUtils; + +/** + * Ordered Scheduler. It is thread pool based {@link ScheduledExecutorService}, additionally providing the ability to + * execute/schedule tasks by <code>key</code>. Hence the tasks submitted by same <i>key</i> + * will be executed in order. + * + * <p>The scheduler is comprised of multiple {@link ScheduledExecutorService}s. Each {@link ScheduledExecutorService} + * is a single thread executor. Normal task submissions will be submitted to executors in a random manner to guarantee + * load balancing. Keyed task submissions (e.g {@link OrderedScheduler#submit(Object, Runnable)} will be submitted to a + * dedicated executor based on the hash value of submit <i>key</i>. + */ +public class OrderedScheduler implements ScheduledExecutorService { Review comment: @reddycharan I have ported the full package from DistributedLog, I think the soon these classes will be dropped from DL. I think that a good step in the future will be to move our (BK) OrderedSafeExecutor in this new bookkeeper commons module and merge the two classes. By now it is just a "move class" from DL. I hope it is OK for you to keep this now here /cc @sijie ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
