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;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import org.cliffc.high_scale_lib.NonBlockingHashMap;
import org.slf4j.Logger;
import com.google.common.annotations.VisibleForTesting;
import static org.apache.cassandra.utils.Clock.Global;
/**
* Logging that limits each log statement to firing based on time since the statement last fired.
*
* Every logger has a unique timer per statement. Minimum time between logging is set for each statement
* the first time it is used and a subsequent attempt to request that statement with a different minimum time will
* result in the original time being used. No warning is provided if there is a mismatch.
*
* If the statement is cached and used to log directly then only a volatile read will be required in the common case.
* If the Logger is cached then there is a single concurrent hash map lookup + the volatile read.
* If neither the logger nor the statement is cached then it is two concurrent hash map lookups + the volatile read.
*
*/
public class NoSpamLogger
{
/**
* Levels for programmatically specifying the severity of a log statement
*/
public enum Level
{
INFO, WARN, ERROR
}
@VisibleForTesting
static interface Clock
{
long nanoTime();
}
@VisibleForTesting
static Clock CLOCK = new Clock()
{
public long nanoTime()
{
return Global.nanoTime();
}
};
public class NoSpamLogStatement extends AtomicLong
{
private static final long serialVersionUID = 1L;
private final String statement;
private final long minIntervalNanos;
public NoSpamLogStatement(String statement, long minIntervalNanos)
{
super(Long.MIN_VALUE);
this.statement = statement;
this.minIntervalNanos = minIntervalNanos;
}
private boolean shouldLog(long nowNanos)
{
long expected = get();
return nowNanos >= expected && compareAndSet(expected, nowNanos + minIntervalNanos);
}
public boolean log(Level l, long nowNanos, Supplier