Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.
/*
* 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.cassandra.utils.concurrent;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.GlobalEventExecutor;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import com.google.common.base.Preconditions;
/**
* Netty's PromiseCombiner is not threadsafe, and we combine futures from multiple event executors.
*
* This class groups a number of Future into a single logical Future, by registering a listener to each that
* decrements a shared counter; if any of them fail, the FutureCombiner is completed with the first cause,
* but in all scenario only completes when all underlying future have completed (exceptionally or otherwise)
*
* This Future is always uncancellable.
*
* We extend AsyncFuture, and simply provide it an uncancellable Promise that will be completed by the listeners
* registered to the input futures.
*/
public class FutureCombiner extends AsyncFuture
{
private interface ListenerFactory
{
Listener create(int count, Supplier onSuccess, FutureCombiner complete);
}
/**
* Tracks completion; once all futures have completed, invokes {@link Listener#complete#trySuccess(Object)} with {@link Listener#onSuccess}.
* Never invokes failure on {@link Listener#complete}.
*/
private static class Listener extends AtomicInteger implements GenericFutureListener>
{
Supplier onSuccess; // non-final so we can release resources immediately when failing fast
final FutureCombiner complete;
Listener(int count, Supplier onSuccess, FutureCombiner complete)
{
super(count);
Preconditions.checkNotNull(onSuccess);
this.onSuccess = onSuccess;
this.complete = complete;
}
@Override
public void operationComplete(io.netty.util.concurrent.Future