/// <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()); } } }
/// <summary> /// Start listening for incoming connections. When this method is called, /// it is guaranteed that <see cref="MessageDispatcher"/> is available for consumption. /// </summary> protected virtual void StartCommunicationListeners() { var _config = TrinityConfig.CurrentClusterConfig; var _si = _config.GetMyServerInfo() ?? _config.GetMyProxyInfo(); var _my_ip = Global.MyIPAddress; if (_si != null) _my_ip = NetworkUtility.Hostname2IPv4Address(_si.HostName); // Initialize message passing networking NativeNetwork.StartTrinityServer((UInt16)_config.ListeningPort); // XXX might not be accurate: NativeNetwork.StartTrinityServer listens on all servers. Log.WriteLine("My IPEndPoint: " + _my_ip + ":" + _config.ListeningPort); // Initialize Http server if (HasHttpEndpoints()) StartHttpServer(); }