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 java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.cassandra.utils.concurrent.BlockingQueues.newBlockingQueue;
import static org.apache.cassandra.utils.concurrent.Semaphore.newSemaphore;
/**
* Weighted queue is a wrapper around any blocking queue that turns it into a blocking weighted queue. The queue
* will weigh each element being added and removed. Adding to the queue is blocked if adding would violate
* the weight bound.
*
* If an element weighs in at larger than the capacity of the queue then exactly one such element will be allowed
* into the queue at a time.
*
* If the weight of an object changes after it is added you are going to have a bad time. Checking weight should be
* cheap so memoize expensive to compute weights. If weight throws that can also result in leaked permits so it's
* always a good idea to memoize weight so it doesn't throw.
*
* In the interests of not writing unit tests for methods no one uses there is a lot of UnsupportedOperationException.
* If you need them then add them and add proper unit tests to WeightedQueueTest. "Good" tests. 100% coverage including
* exception paths and resource leaks.
**/
public class WeightedQueue implements BlockingQueue
{
private static final Logger logger = LoggerFactory.getLogger(WeightedQueue.class);
public static final Weigher NATURAL_WEIGHER = (Weigher