Пример #1
0
        /// <summary>
        /// Starts a Trinity instance.
        /// </summary>
        public void Start()
        {
            lock (m_lock)
            {
                if (m_started)
                {
                    return;
                }
                try
                {
                    Log.WriteLine(LogLevel.Debug, "Starting communication instance.");
                    var _config = TrinityConfig.CurrentClusterConfig;

                    _config.RunningMode          = this.RunningMode;
                    Global.CommunicationInstance = this;

                    if (_InstanceList.Count == 0)
                    {
                        Log.WriteLine(LogLevel.Warning, "No distributed instances configured. Turning on local test mode.");
                        TrinityConfig.LocalTest = true;
                    }

                    //  Initialize message handlers
                    MessageHandlers.Initialize();
                    RegisterMessageHandler();

                    //  Initialize message passing networking
                    NativeNetwork.StartTrinityServer((UInt16)_config.ListeningPort);
                    Log.WriteLine("My IPEndPoint: " + _config.MyBoundIP + ":" + _config.ListeningPort);

                    //  Initialize cloud storage
                    memory_cloud = Global.CloudStorage;

                    //  Initialize the modules
                    _InitializeModules();

                    if (HasHttpEndpoints())
                    {
                        StartHttpServer();
                    }

                    Console.WriteLine("Working Directory: {0}", Global.MyAssemblyPath);
                    Console.WriteLine(_config.OutputCurrentConfig());
                    Console.WriteLine(TrinityConfig.OutputCurrentConfig());

                    m_started = true;
                    Log.WriteLine("{0} {1} is successfully started.", RunningMode, _config.MyInstanceId);
                    _RaiseStartedEvents();
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogLevel.Error, "CommunicationInstance: " + ex.ToString());
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Starts a Trinity instance.
        /// </summary>
        public unsafe void Start()
        {
            lock (m_lock)
            {
                if (m_started)
                {
                    return;
                }
                try
                {
                    Log.WriteLine(LogLevel.Debug, "Starting communication instance.");
                    Global.CommunicationInstance     = this;
                    TrinityConfig.CurrentRunningMode = this.RunningMode;

                    //  Initialize message handlers
                    MessageHandlers.Initialize();
                    RegisterMessageHandler();
                    MessageDispatcher = _MessageInitializationTrap;

                    //  Bring up networking subsystems
                    StartCommunicationListeners();

                    //  Initialize cloud storage
                    memory_cloud = Global.CloudStorage;

                    //  Initialize the modules
                    _ScanForAutoRegisteredModules();
                    _InitializeModules();

                    //  Modules initialized, release pending messages from the trap
                    m_module_init_signal.Set();
                    MessageDispatcher = MessageHandlers.DefaultParser.DispatchMessage;

                    Log.WriteLine("Working Directory: {0}", Global.MyAssemblyPath);
                    Log.WriteLines(TrinityConfig.OutputCurrentConfig());

                    m_started = true;
                    Log.WriteLine("{0} {1} is successfully started.", RunningMode, memory_cloud.MyInstanceId);
                    _RaiseStartedEvents();
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogLevel.Error, "CommunicationInstance: " + ex.ToString());
                }
            }
        }