<commit_before>/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the OpenSim Project nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Timers;
using System.Xml;
using libsecondlife;
using log4net;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Region.DataSnapshot.Interfaces;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes;
using libsecondlife.Packets;

namespace OpenSim.Region.DataSnapshot
{
    public class DataSnapshotManager : IRegionModule, IDataSnapshot
    {
        #region Class members
        //Information from config
        private bool m_enabled = false;
        private bool m_configLoaded = false;
        private List<String> m_disabledModules = new List<String>();
        private Dictionary<string, string> m_gridinfo = new Dictionary<string, string>();
        private string m_snapsDir = "DataSnapshot";

        //Lists of stuff we need
        private List<Scene> m_scenes = new List<Scene>();
        private List<IDataSnapshotProvider> m_dataproviders = new List<IDataSnapshotProvider>();

        //Various internal objects
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        internal object m_syncInit = new object();

        //DataServices and networking
        private string m_dataServices = "noservices";
        public string m_listener_port = "9000"; //TODO: Set default port over 9000
        public string m_hostname = "127.0.0.1";

        //Update timers
        private Timer m_periodic = null;
        private int m_period = 20; // in seconds
        private int m_maxStales = 500;
        private int m_stales = 0;
        private Timer m_passedCheck = null;
        private bool m_periodPassed = false;

        //Program objects
        private SnapshotStore m_snapStore = null;
        // private DataRequestHandler m_requests = null;

        #endregion

        #region IRegionModule

        public void Close() {}

        public void Initialise(Scene scene, IConfigSource config)
        {
            if (!m_configLoaded) {
                m_configLoaded = true;
                m_log.Info("[DATASNAPSHOT]: Loading configuration");
                //Read from the config for options
                 lock (m_syncInit)
                 {
                     try
                     {
                         m_enabled = config.Configs["DataSnapshot"].GetBoolean("index_sims", m_enabled);
                         if (config.Configs["Startup"].GetBoolean("gridmode", true))
                         {
                             m_gridinfo.Add("gridserverURL", config.Configs["Network"].GetString("grid_server_url", "harbl"));
                             m_gridinfo.Add("userserverURL", config.Configs["Network"].GetString("user_server_url", "harbl"));
                             m_gridinfo.Add("assetserverURL", config.Configs["Network"].GetString("asset_server_url", "harbl"));
                         }
                         else
                         {
                             //Non gridmode stuff
                         }

                        m_gridinfo.Add("Name", config.Configs["DataSnapshot"].GetString("gridname", "harbl"));
                        m_period = config.Configs["DataSnapshot"].GetInt("default_snapshot_period", m_period);
                        m_maxStales = config.Configs["DataSnapshot"].GetInt("max_changes_before_update", m_maxStales);
                        m_snapsDir = config.Configs["DataSnapshot"].GetString("snapshot_cache_directory", m_snapsDir);
                        m_dataServices = config.Configs["DataSnapshot"].GetString("data_services", m_dataServices);
                        m_listener_port = config.Configs["Network"].GetString("http_listener_port", m_listener_port);

                        String[] annoying_string_array = config.Configs["DataSnapshot"].GetString("disable_modules", "").Split(".".ToCharArray());
                        foreach (String bloody_wanker in annoying_string_array) {
                            m_disabledModules.Add(bloody_wanker);
                        }
                    } catch (Exception) {
                        m_log.Info("[DATASNAPSHOT]: Could not load configuration. DataSnapshot will be disabled.");
                        m_enabled = false;
                        return;
                    }
                }

                if (m_enabled)
                {
                    //Create update timer
                    m_periodic = new Timer();
                    m_periodic.Interval = m_period * 1000;
                    m_periodic.Elapsed += SnapshotTimerCallback;

                    //Create update eligibility timer
                    m_passedCheck = new Timer();
                    m_passedCheck.Interval = m_period * 1000;
                    m_passedCheck.Elapsed += UpdateEligibilityCallback;
                    m_passedCheck.Start();

                    //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
                    // m_requests = new DataRequestHandler(scene, this);

                    m_hostname = scene.RegionInfo.ExternalHostName;
                    m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);

                    MakeEverythingStale();

                    if (m_dataServices != "noservices")
                        NotifyDataServices(m_dataServices);
                }<commit_msg>* Resolve mantis 1911 without reintroducing warnings<commit_after>/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the OpenSim Project nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Timers;
using System.Xml;
using libsecondlife;
using log4net;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Region.DataSnapshot.Interfaces;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes;
using libsecondlife.Packets;

namespace OpenSim.Region.DataSnapshot
{
    public class DataSnapshotManager : IRegionModule, IDataSnapshot
    {
        #region Class members
        //Information from config
        private bool m_enabled = false;
        private bool m_configLoaded = false;
        private List<String> m_disabledModules = new List<String>();
        private Dictionary<string, string> m_gridinfo = new Dictionary<string, string>();
        private string m_snapsDir = "DataSnapshot";

        //Lists of stuff we need
        private List<Scene> m_scenes = new List<Scene>();
        private List<IDataSnapshotProvider> m_dataproviders = new List<IDataSnapshotProvider>();

        //Various internal objects
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        internal object m_syncInit = new object();

        //DataServices and networking
        private string m_dataServices = "noservices";
        public string m_listener_port = "9000"; //TODO: Set default port over 9000
        public string m_hostname = "127.0.0.1";

        //Update timers
        private Timer m_periodic = null;
        private int m_period = 20; // in seconds
        private int m_maxStales = 500;
        private int m_stales = 0;
        private Timer m_passedCheck = null;
        private bool m_periodPassed = false;

        //Program objects
        private SnapshotStore m_snapStore = null;

        #endregion

        #region IRegionModule

        public void Close() {}

        public void Initialise(Scene scene, IConfigSource config)
        {
            if (!m_configLoaded) {
                m_configLoaded = true;
                m_log.Info("[DATASNAPSHOT]: Loading configuration");
                //Read from the config for options
                 lock (m_syncInit)
                 {
                     try
                     {
                         m_enabled = config.Configs["DataSnapshot"].GetBoolean("index_sims", m_enabled);
                         if (config.Configs["Startup"].GetBoolean("gridmode", true))
                         {
                             m_gridinfo.Add("gridserverURL", config.Configs["Network"].GetString("grid_server_url", "harbl"));
                             m_gridinfo.Add("userserverURL", config.Configs["Network"].GetString("user_server_url", "harbl"));
                             m_gridinfo.Add("assetserverURL", config.Configs["Network"].GetString("asset_server_url", "harbl"));
                         }
                         else
                         {
                             //Non gridmode stuff
                         }

                        m_gridinfo.Add("Name", config.Configs["DataSnapshot"].GetString("gridname", "harbl"));
                        m_period = config.Configs["DataSnapshot"].GetInt("default_snapshot_period", m_period);
                        m_maxStales = config.Configs["DataSnapshot"].GetInt("max_changes_before_update", m_maxStales);
                        m_snapsDir = config.Configs["DataSnapshot"].GetString("snapshot_cache_directory", m_snapsDir);
                        m_dataServices = config.Configs["DataSnapshot"].GetString("data_services", m_dataServices);
                        m_listener_port = config.Configs["Network"].GetString("http_listener_port", m_listener_port);

                        String[] annoying_string_array = config.Configs["DataSnapshot"].GetString("disable_modules", "").Split(".".ToCharArray());
                        foreach (String bloody_wanker in annoying_string_array) {
                            m_disabledModules.Add(bloody_wanker);
                        }
                    } catch (Exception) {
                        m_log.Info("[DATASNAPSHOT]: Could not load configuration. DataSnapshot will be disabled.");
                        m_enabled = false;
                        return;
                    }
                }

                if (m_enabled)
                {
                    //Create update timer
                    m_periodic = new Timer();
                    m_periodic.Interval = m_period * 1000;
                    m_periodic.Elapsed += SnapshotTimerCallback;

                    //Create update eligibility timer
                    m_passedCheck = new Timer();
                    m_passedCheck.Interval = m_period * 1000;
                    m_passedCheck.Elapsed += UpdateEligibilityCallback;
                    m_passedCheck.Start();

                    //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
                    new DataRequestHandler(scene, this);

                    m_hostname = scene.RegionInfo.ExternalHostName;
                    m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);

                    MakeEverythingStale();

                    if (m_dataServices != "noservices")
                        NotifyDataServices(m_dataServices);
                }
{'fraction_non_alphanumeric': 0.07875894988066826, 'fraction_numerical': 0.004352098834760634, 'mean_word_length': 2.2044534412955468, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3395015', 'n_tokens_mistral': 3632, 'n_tokens_neox': 3359, 'n_words': 1051}