<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright (C) 2008 Red Hat, Inc.
 * Copyright (C) 2000-2007 MetaMatrix, Inc.
 * Licensed to Red Hat, Inc. under one or more contributor 
 * license agreements.  See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

package com.metamatrix.server.dqp.service.tracker;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.ResourceNames;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.queue.WorkerPool;
import com.metamatrix.common.queue.WorkerPoolFactory;
import com.metamatrix.common.util.LogCommonConstants;
import com.metamatrix.server.ServerPlugin;


/**
 * This class represents the interface to a single transaction logging framework
 * that is easily accessible by any component.  Using the TransactionLogManager, a component
 * can quickly submit a log message, and can rely upon the TransactionLogManager to determine
 * whether that message is to be recorded or discarded. Thus, the component's code that submits
 * messages does not have to be modified to alter the logging behavior of the
 * application.
 * <p>
 * The TransactionLogManager has a number of features that makes it an efficient and configurable
 * framework. First, the methods in the TransactionLogManager that submit messages are
 * asynchronous to minimize the amount of time a client component waits for
 * the TransactionLogManager.
 * <p>
 * Secondly, the TransactionLogManager's behavior can be controlled at VM start time
 * through current Server configuration properties.
 */
public final class TransactionLogManager {

    /**
     * Whether to log transaction. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_TXN   = "metamatrix.transaction.log.storeTXN"; //$NON-NLS-1$

    /**
     * Whether to log MetaMatrix command. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_MMCMD   = "metamatrix.transaction.log.storeMMCMD"; //$NON-NLS-1$

    /**
     * Whether to log source command. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_SRCCMD  = "metamatrix.transaction.log.storeSRCCMD"; //$NON-NLS-1$

    /**
     * The name of the System property that contains the maximum number of threads
     * for the LogManager.  This is an optional property that defaults to '1'.
     * Note that the maximum value must be greater than or equal to the minimum value.
     */
    public static final String SYSTEM_LOG_MAX_THREADS           = "metamatrix.transaction.log.maxThreads"; //$NON-NLS-1$

    /**
     * The name of the System property that contains the time to live (in milliseconds) for threads
     * in the LogManager.  The time to live is simply the period of thread inactivity
     * that determines when a thread may be expired.  This is an optional property
     * that defaults to '600000' milliseconds (or 10 minutes).
     */
    public static final String SYSTEM_LOG_THREAD_TTL            = "metamatrix.transaction.log.threadTTL"; //$NON-NLS-1$

    protected static final String DEFAULT_LOG_MAX_THREADS          = "1"; //$NON-NLS-1$
    protected static final String DEFAULT_LOG_THREAD_TTL           = "600000"; //$NON-NLS-1$

	private static TransactionLogManager INSTANCE = new TransactionLogManager();

	private boolean storeTXN;
	private boolean storeMMCMD;
	private boolean storeSRCCMD;

	private WorkerPool workerPool;
	private Properties currentConfigProperties;
    private boolean isInitialized = false;
    private boolean isStopped = false;

    protected void finalize() {
        if ( this.isManagerStopped() ) {
            stop();
        }
    }

    private TransactionLogManager() {
        // Initialize the worker factory and message queue ...
        // Doing this before anything else allows messages to be enqueue before
        // and before the AuditManager is alive and before the destinations are created ...
    }

    private void init() {
        //get system properties
        currentConfigProperties = new Properties();
        try {
            Properties globalProperties = CurrentConfiguration.getProperties();

            currentConfigProperties.putAll(globalProperties);
            currentConfigProperties.putAll(CurrentConfiguration.getResourceProperties(ResourceNames.TRANSACTION_LOGGING));
        } catch ( ConfigurationException e ) {
            LogManager.logWarning(LogCommonConstants.CTX_TXN_LOG, e, ServerPlugin.Util.getString("ERR.003.001.0027")); //$NON-NLS-1$
            currentConfigProperties.putAll(System.getProperties());
        }

        String propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_TXN);
        if(propvalue != null){
            storeTXN = Boolean.valueOf(propvalue).booleanValue();
        }
        propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_MMCMD);
        if(propvalue != null){
            storeMMCMD = Boolean.valueOf(propvalue).booleanValue();
        }
        propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_SRCCMD);
        if(propvalue != null){
            storeSRCCMD = Boolean.valueOf(propvalue).booleanValue();
        }

        //if not logging anything, no need to really initialize anything
        if(!storeTXN && !storeMMCMD && !storeSRCCMD){
            this.isInitialized = true;
            return;
        }

        // Initialize the queue workers ...
        this.initializeQueueWorkers();

        this.isInitialized = true;
    }<commit_msg>FEDERATE-147 - removed the logic that called for resource properties because the resource is no longer managed<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright (C) 2008 Red Hat, Inc.
 * Copyright (C) 2000-2007 MetaMatrix, Inc.
 * Licensed to Red Hat, Inc. under one or more contributor 
 * license agreements.  See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

package com.metamatrix.server.dqp.service.tracker;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.ResourceNames;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.queue.WorkerPool;
import com.metamatrix.common.queue.WorkerPoolFactory;
import com.metamatrix.common.util.LogCommonConstants;
import com.metamatrix.server.ServerPlugin;


/**
 * This class represents the interface to a single transaction logging framework
 * that is easily accessible by any component.  Using the TransactionLogManager, a component
 * can quickly submit a log message, and can rely upon the TransactionLogManager to determine
 * whether that message is to be recorded or discarded. Thus, the component's code that submits
 * messages does not have to be modified to alter the logging behavior of the
 * application.
 * <p>
 * The TransactionLogManager has a number of features that makes it an efficient and configurable
 * framework. First, the methods in the TransactionLogManager that submit messages are
 * asynchronous to minimize the amount of time a client component waits for
 * the TransactionLogManager.
 * <p>
 * Secondly, the TransactionLogManager's behavior can be controlled at VM start time
 * through current Server configuration properties.
 */
public final class TransactionLogManager {

    /**
     * Whether to log transaction. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_TXN   = "metamatrix.transaction.log.storeTXN"; //$NON-NLS-1$

    /**
     * Whether to log MetaMatrix command. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_MMCMD   = "metamatrix.transaction.log.storeMMCMD"; //$NON-NLS-1$

    /**
     * Whether to log source command. Defaults to false.
     */
    public static final String SYSTEM_TXN_STORE_SRCCMD  = "metamatrix.transaction.log.storeSRCCMD"; //$NON-NLS-1$

    /**
     * The name of the System property that contains the maximum number of threads
     * for the LogManager.  This is an optional property that defaults to '1'.
     * Note that the maximum value must be greater than or equal to the minimum value.
     */
    public static final String SYSTEM_LOG_MAX_THREADS           = "metamatrix.transaction.log.maxThreads"; //$NON-NLS-1$

    /**
     * The name of the System property that contains the time to live (in milliseconds) for threads
     * in the LogManager.  The time to live is simply the period of thread inactivity
     * that determines when a thread may be expired.  This is an optional property
     * that defaults to '600000' milliseconds (or 10 minutes).
     */
    public static final String SYSTEM_LOG_THREAD_TTL            = "metamatrix.transaction.log.threadTTL"; //$NON-NLS-1$

    protected static final String DEFAULT_LOG_MAX_THREADS          = "1"; //$NON-NLS-1$
    protected static final String DEFAULT_LOG_THREAD_TTL           = "600000"; //$NON-NLS-1$

	private static TransactionLogManager INSTANCE = new TransactionLogManager();

	private boolean storeTXN;
	private boolean storeMMCMD;
	private boolean storeSRCCMD;

	private WorkerPool workerPool;
	private Properties currentConfigProperties;
    private boolean isInitialized = false;
    private boolean isStopped = false;

    protected void finalize() {
        if ( this.isManagerStopped() ) {
            stop();
        }
    }

    private TransactionLogManager() {
        // Initialize the worker factory and message queue ...
        // Doing this before anything else allows messages to be enqueue before
        // and before the AuditManager is alive and before the destinations are created ...
    }

    private void init() {
        //get system properties
        currentConfigProperties = new Properties();
        try {
            Properties globalProperties = CurrentConfiguration.getProperties();

            currentConfigProperties.putAll(globalProperties);
        } catch ( ConfigurationException e ) {
            LogManager.logWarning(LogCommonConstants.CTX_TXN_LOG, e, ServerPlugin.Util.getString("ERR.003.001.0027")); //$NON-NLS-1$
            currentConfigProperties.putAll(System.getProperties());
        }

        String propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_TXN);
        if(propvalue != null){
            storeTXN = Boolean.valueOf(propvalue).booleanValue();
        }
        propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_MMCMD);
        if(propvalue != null){
            storeMMCMD = Boolean.valueOf(propvalue).booleanValue();
        }
        propvalue = currentConfigProperties.getProperty(SYSTEM_TXN_STORE_SRCCMD);
        if(propvalue != null){
            storeSRCCMD = Boolean.valueOf(propvalue).booleanValue();
        }

        //if not logging anything, no need to really initialize anything
        if(!storeTXN && !storeMMCMD && !storeSRCCMD){
            this.isInitialized = true;
            return;
        }

        // Initialize the queue workers ...
        this.initializeQueueWorkers();

        this.isInitialized = true;
    }
{'fraction_non_alphanumeric': 0.07551274083281541, 'fraction_numerical': 0.00940024860161591, 'mean_word_length': 3.2639947002318648, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '264805', 'n_tokens_mistral': 3425, 'n_tokens_neox': 3251, 'n_words': 1224}