<commit_before>package com.github.dynamicextensionsalfresco.metrics

import org.alfresco.repo.transaction.AlfrescoTransactionSupport
import org.alfresco.util.transaction.TransactionListener
import org.slf4j.LoggerFactory
import org.springframework.transaction.support.TransactionSynchronizationManager
import org.springframework.util.StopWatch

/**
 * [Timer] based on Spring's [StopWatch]
 * collects data during a transaction and logs to log4j after commit at TRACE level
 */
public class SpringTimer : Timer {
    val logger = LoggerFactory.getLogger(javaClass)

    val identifier = javaClass.getPackage().getName()

    override val enabled: Boolean
        get() = logger.isTraceEnabled()

    private val stopWatch: StopWatch
        get() {
            var stopWatch = TransactionSynchronizationManager.getResource(identifier) as? StopWatch
            if (stopWatch == null) {
                stopWatch = StopWatch(identifier)
                TransactionSynchronizationManager.bindResource(identifier, stopWatch)

                registerTxListener()
            }
            return stopWatch
        }

    private fun registerTxListener() {
        AlfrescoTransactionSupport.bindListener(object : TransactionListener {
            override fun beforeCompletion() {}

            override fun beforeCommit(readOnly: Boolean) {}

            override fun afterRollback() {}

            override fun afterCommit() {
                logger.trace(stopWatch.prettyPrint())
            }
        })
    }

    override fun start(label: String) {
        if (enabled) {
            with(stopWatch) {
                if (isRunning()) {
                    stop()
                }
                start(label)
            }
        }
    }
<commit_msg>use the older org.alfresco.repo.transaction.TransactionListener interface for backward compatibility<commit_after>package com.github.dynamicextensionsalfresco.metrics

import org.alfresco.repo.transaction.AlfrescoTransactionSupport
import org.alfresco.repo.transaction.TransactionListener
import org.slf4j.LoggerFactory
import org.springframework.transaction.support.TransactionSynchronizationManager
import org.springframework.util.StopWatch

/**
 * [Timer] based on Spring's [StopWatch]
 * collects data during a transaction and logs to log4j after commit at TRACE level
 */
public class SpringTimer : Timer {
    val logger = LoggerFactory.getLogger(javaClass)

    val identifier = javaClass.getPackage().getName()

    override val enabled: Boolean
        get() = logger.isTraceEnabled()

    private val stopWatch: StopWatch
        get() {
            var stopWatch = TransactionSynchronizationManager.getResource(identifier) as? StopWatch
            if (stopWatch == null) {
                stopWatch = StopWatch(identifier)
                TransactionSynchronizationManager.bindResource(identifier, stopWatch)

                registerTxListener()
            }
            return stopWatch
        }

    private fun registerTxListener() {
        AlfrescoTransactionSupport.bindListener(object : TransactionListener {
            override fun flush() {}

            override fun beforeCompletion() {}

            override fun beforeCommit(readOnly: Boolean) {}

            override fun afterRollback() {}

            override fun afterCommit() {
                logger.trace(stopWatch.prettyPrint())
            }
        })
    }

    override fun start(label: String) {
        if (enabled) {
            with(stopWatch) {
                if (isRunning()) {
                    stop()
                }
                start(label)
            }
        }
    }

{'fraction_non_alphanumeric': 0.07696536558548653, 'fraction_numerical': 0.0010995052226498076, 'mean_word_length': 2.353917050691244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6546137', 'n_tokens_mistral': 891, 'n_tokens_neox': 853, 'n_words': 204}