<commit_before>/*
 * @(#) StorageProxyStatsAspect.java
 * Created Nov 4, 2011 by oleg
 * (C) ONE, SIA
 */
package odkl.cassandra.stat;

import java.net.InetAddress;

import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import one.log.util.LoggerUtil;

/**
 * This collects one-log statistics from HintedHandoff manager - i.e. 
 * 
 * @author <NAME><<EMAIL>>
 *
 */
@Aspect
public class HintedHandoffStatsAspect extends SystemArchitectureAspect
{

    /**
     * Logger of one-log to file stats to.
     * for current DAO instance.
     */
    private Log opLogger = LogFactory.getLog(OP_LOGGER_NAME);
    
    /**
     * timeout to feed into stats
     */
    private long timeout = DatabaseDescriptor.getRpcTimeout() ;
    
    
    @Around("hintStorePointcut(endpoint)")
    public Object hintStore(ProceedingJoinPoint join, InetAddress endpoint) throws Throwable
    {
        return collectStats(join, "HINT.STORE", endpoint);
    }
    
    @Around("hintDeliveryPointcut(endpoint)")
    public Object hintDelivery(ProceedingJoinPoint join, InetAddress endpoint) throws Throwable
    {
        return collectStats(join, "HINT.DELIVERY", endpoint);
    }
    
    private Object collectStats(ProceedingJoinPoint join, String opName, InetAddress endpoint) throws Throwable
    {
        
        // if no logging is configured doing a shortcut call to dao method
        if (!opLogger.isTraceEnabled())
            return join.proceed();
        
        final long time = LoggerUtil.getMeasureStartTime();
        boolean ok=false;
        try {
            final Object result=join.proceed();

            // if return is boolean and it is false - this is unsuccesful opration. see deliverHint & sendMessage
            ok= result!=Boolean.FALSE;
            
            // method call finished successfully
            return result;
        }
        finally
        {
            if (ok)
                LoggerUtil.operationSuccess(opLogger, time, timeout, opName,DatabaseDescriptor.getClusterName(), endpoint  );
            else
                LoggerUtil.operationFailure(opLogger, time,timeout, opName,DatabaseDescriptor.getClusterName(), endpoint );
        }
    }

    
}<commit_msg>[cassandra] переделять сбор статистики кассандра серверов на прямую запись в one-log (OL-17030)<commit_after>/*
 * @(#) StorageProxyStatsAspect.java
 * Created Nov 4, 2011 by oleg
 * (C) ONE, SIA
 */
package odkl.cassandra.stat;

import java.net.InetAddress;

import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import one.log.util.LoggerUtil;

/**
 * This collects one-log statistics from HintedHandoff manager - i.e. 
 * 
 * @author <NAME><<EMAIL>>
 *
 */
@Aspect
public class HintedHandoffStatsAspect extends SystemArchitectureAspect
{

    /**
     * Logger of one-log to file stats to.
     * for current DAO instance.
     */
    private Log opLogger = LogFactory.getLog(OP_LOGGER_NAME);
    
    /**
     * timeout to feed into stats
     */
    private long timeout = DatabaseDescriptor.getRpcTimeout() ;
    
    
    @Around("hintStorePointcut(endpoint)")
    public Object hintStore(ProceedingJoinPoint join, InetAddress endpoint) throws Throwable
    {
        return collectStats(join, "HINT.STORE", endpoint);
    }
    
    @Around("hintDeliveryPointcut(endpoint)")
    public Object hintDelivery(ProceedingJoinPoint join, InetAddress endpoint) throws Throwable
    {
        return collectStats(join, "HINT.DELIVERY", endpoint);
    }
    
    private Object collectStats(ProceedingJoinPoint join, String opName, InetAddress endpoint) throws Throwable
    {
        
        // if no logging is configured doing a shortcut call to dao method
        if (!opLogger.isTraceEnabled())
            return join.proceed();
        
        final long time = LoggerUtil.getMeasureStartTime();
        boolean ok=false;
        try {
            final Object result=join.proceed();

            // if return is boolean and it is false - this is unsuccesful opration. see deliverHint & sendMessage
            ok= result!=Boolean.FALSE;
            
            // method call finished successfully
            return result;
        }
        finally
        {
            if (ok)
                LoggerUtil.operationSuccess(opLogger, time, timeout, opName,DatabaseDescriptor.getClusterName(), endpoint.getHostAddress()  );
            else
                LoggerUtil.operationFailure(opLogger, time,timeout, opName,DatabaseDescriptor.getClusterName(), endpoint.getHostAddress() );
        }
    }

    
}
{'fraction_non_alphanumeric': 0.09145487292375425, 'fraction_numerical': 0.003001801080648389, 'mean_word_length': 2.7466266866566715, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889588', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1398, 'n_words': 347}