org.apache.cassandra.cql3.QueryEvents Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-all Show documentation
Show all versions of cassandra-all Show documentation
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.cql3;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.cql3.statements.AuthenticationStatement;
import org.apache.cassandra.cql3.statements.BatchStatement;
import org.apache.cassandra.service.QueryState;
import org.apache.cassandra.transport.Message;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.JVMStabilityInspector;
import org.apache.cassandra.utils.NoSpamLogger;
public class QueryEvents
{
private static final Logger logger = LoggerFactory.getLogger(QueryEvents.class);
private static final NoSpamLogger noSpam1m = NoSpamLogger.getLogger(logger, 1, TimeUnit.MINUTES);
public static final QueryEvents instance = new QueryEvents();
private final Set listeners = new CopyOnWriteArraySet<>();
@VisibleForTesting
public int listenerCount()
{
return listeners.size();
}
public void registerListener(Listener listener)
{
listeners.add(listener);
}
public void unregisterListener(Listener listener)
{
listeners.remove(listener);
}
public void notifyQuerySuccess(CQLStatement statement,
String query,
QueryOptions options,
QueryState state,
long queryTime,
Message.Response response)
{
try
{
final String maybeObfuscatedQuery = listeners.size() > 0 ? maybeObfuscatePassword(statement, query) : query;
for (Listener listener : listeners)
listener.querySuccess(statement, maybeObfuscatedQuery, options, state, queryTime, response);
}
catch (Throwable t)
{
noSpam1m.error("Failed notifying listeners", t);
JVMStabilityInspector.inspectThrowable(t);
}
}
public void notifyQueryFailure(CQLStatement statement,
String query,
QueryOptions options,
QueryState state,
Exception cause)
{
try
{
final String maybeObfuscatedQuery = listeners.size() > 0 ? maybeObfuscatePassword(statement, query) : query;
for (Listener listener : listeners)
listener.queryFailure(statement, maybeObfuscatedQuery, options, state, cause);
}
catch (Throwable t)
{
noSpam1m.error("Failed notifying listeners", t);
JVMStabilityInspector.inspectThrowable(t);
}
}
public void notifyExecuteSuccess(CQLStatement statement,
String query,
QueryOptions options,
QueryState state,
long queryTime,
Message.Response response)
{
try
{
final String maybeObfuscatedQuery = listeners.size() > 0 ? maybeObfuscatePassword(statement, query) : query;
for (Listener listener : listeners)
listener.executeSuccess(statement, maybeObfuscatedQuery, options, state, queryTime, response);
}
catch (Throwable t)
{
noSpam1m.error("Failed notifying listeners", t);
JVMStabilityInspector.inspectThrowable(t);
}
}
public void notifyExecuteFailure(QueryHandler.Prepared prepared,
QueryOptions options,
QueryState state,
Exception cause)
{
CQLStatement statement = prepared != null ? prepared.statement : null;
String query = prepared != null ? prepared.rawCQLStatement : null;
try
{
final String maybeObfuscatedQuery = listeners.size() > 0 ? maybeObfuscatePassword(statement, query) : query;
for (Listener listener : listeners)
listener.executeFailure(statement, maybeObfuscatedQuery, options, state, cause);
}
catch (Throwable t)
{
noSpam1m.error("Failed notifying listeners", t);
JVMStabilityInspector.inspectThrowable(t);
}
}
public void notifyBatchSuccess(BatchStatement.Type batchType,
List statements,
List queries,
List> values,
QueryOptions options,
QueryState state,
long queryTime,
Message.Response response)
{
try
{
for (Listener listener : listeners)
listener.batchSuccess(batchType, statements, queries, values, options, state, queryTime, response);
}
catch (Throwable t)
{
noSpam1m.error("Failed notifying listeners", t);
JVMStabilityInspector.inspectThrowable(t);
}
}
public void notifyBatchFailure(List prepared,
BatchStatement.Type batchType,
List