/// <summary> /// 验证请求是否有效 /// </summary> /// <param name="requestHeader"></param> protected override void ValidateRequest(RequestHeader requestHeader) { // check for server error. ServiceResult error = ServerError; if (ServiceResult.IsBad(error)) { throw new ServiceResultException(error); } // check server state. ServerInternalData serverInternal = m_serverInternal; if (serverInternal == null || !serverInternal.IsRunning) { throw new ServiceResultException(StatusCodes.BadServerHalted); } if (requestHeader == null) { throw new ServiceResultException(StatusCodes.BadRequestHeaderInvalid); } }
/// <summary> /// 启动服务 /// </summary> /// <param name="configuration"></param> protected override void StartApplication(ApplicationConfiguration configuration) { lock (m_lock) { try { // create the datastore for the instance. m_serverInternal = new ServerInternalData( ServerProperties, configuration, MessageContext, new CertificateValidator(), InstanceCertificate); // create the manager responsible for providing localized string resources. ResourceManager resourceManager = CreateResourceManager(m_serverInternal, configuration); // create the manager responsible for incoming requests. RequestManager requestManager = new RequestManager(m_serverInternal); // create the master node manager. MasterNodeManager masterNodeManager = new MasterNodeManager(m_serverInternal, configuration, null); // add the node manager to the datastore. m_serverInternal.SetNodeManager(masterNodeManager); // put the node manager into a state that allows it to be used by other objects. masterNodeManager.Startup(); // create the manager responsible for handling events. EventManager eventManager = new EventManager(m_serverInternal, (uint)configuration.ServerConfiguration.MaxEventQueueSize); // creates the server object. m_serverInternal.CreateServerObject( eventManager, resourceManager, requestManager); // create the manager responsible for aggregates. m_serverInternal.AggregateManager = CreateAggregateManager(m_serverInternal, configuration); // start the session manager. SessionManager sessionManager = new SessionManager(m_serverInternal, configuration); sessionManager.Startup(); // start the subscription manager. SubscriptionManager subscriptionManager = new SubscriptionManager(m_serverInternal, configuration); subscriptionManager.Startup(); // add the session manager to the datastore. m_serverInternal.SetSessionManager(sessionManager, subscriptionManager); ServerError = null; // set the server status as running. SetServerState(ServerState.Running); // monitor the configuration file. if (!String.IsNullOrEmpty(configuration.SourceFilePath)) { var m_configurationWatcher = new ConfigurationWatcher(configuration); m_configurationWatcher.Changed += new EventHandler <ConfigurationWatcherEventArgs>(this.OnConfigurationChanged); } CertificateValidator.CertificateUpdate += OnCertificateUpdate; //60s后开始清理过期服务列表,此后每60s检查一次 m_timer = new Timer(ClearNoliveServer, null, 60000, 60000); Console.WriteLine("Discovery服务已启动完成,请勿退出程序!!!"); } catch (Exception e) { Utils.Trace(e, "Unexpected error starting application"); m_serverInternal = null; ServiceResult error = ServiceResult.Create(e, StatusCodes.BadInternalError, "Unexpected error starting application"); ServerError = error; throw new ServiceResultException(error); } } }