/// <summary> /// 按照一个配置集来初始化KJFramework全局的底层网络缓冲区 /// </summary> internal static void Initialize(ChannelInternalConfigSettings settings) { if (_initialized) { return; } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } //initializes global value. RecvBufferSize = settings.RecvBufferSize; BuffStubPoolSize = settings.BuffStubPoolSize; NamedPipeBuffStubPoolSize = settings.NamedPipeBuffStubPoolSize; NoBuffStubPoolSize = settings.NoBuffStubPoolSize; MaxMessageDataLength = settings.MaxMessageDataLength; SegmentSize = settings.SegmentSize; _memoryChunkSize = SegmentSize * (BuffStubPoolSize + NamedPipeBuffStubPoolSize); SegmentContainer = new MemoryChunkCacheContainer(SegmentSize, _memoryChunkSize); Tenant = new CacheTenant(); BuffAsyncStubPool = Tenant.Rent <SocketBuffStub>("Pool::BuffSocketIOStub", BuffStubPoolSize); NamedPipeBuffPool = Tenant.Rent <BuffStub>("Pool::NamedPipeIOStub", NamedPipeBuffStubPoolSize); NoBuffAsyncStubPool = Tenant.Rent <NoBuffSocketStub>("Pool::NoBuffSocketIOStub", NoBuffStubPoolSize); _initialized = true; }
/// <summary> /// 初始化KJFramework全局的底层网络缓冲区 /// </summary> public static void Initialize() { ChannelInternalConfigSettings settings; if (!ChannelInternalConfigSettings.TryParse(SystemConfigurations.Configuration, out settings)) { settings = new ChannelInternalConfigSettings(); settings.RecvBufferSize = 4096; settings.BuffStubPoolSize = 200000; settings.NamedPipeBuffStubPoolSize = 200000; settings.NoBuffStubPoolSize = 200000; settings.MaxMessageDataLength = 5120; settings.SegmentSize = 5120; } Initialize(settings); }
/// <summary> /// 运行一个用的定指户KEA APP /// </summary> /// <param name="etcdClusterUrl">远程的ETCD集群地址</param> /// <param name="appFilePath">目标待行执的APP全路径</param> public static void Run(string etcdClusterUrl, string appFilePath) { if (string.IsNullOrEmpty(etcdClusterUrl)) { throw new ArgumentNullException("etcdClusterUrl"); } if (string.IsNullOrEmpty(appFilePath)) { throw new ArgumentNullException("appFilePath"); } string appRealPath = string.Empty; if (appFilePath.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase)) { appRealPath = DownloadAPP(appFilePath); } else { appRealPath = appFilePath; } _tracing.DebugInfo("\t#Loading KPPs..."); Tuple <string, ApplicationEntryInfo, KPPDataStructure> tuple = ((IApplicationFinder)KAESystemInternalResource.Factory.GetResource(KAESystemInternalResource.APPFinder)).ReadKPPFrom(appRealPath); if (tuple == null) { _tracing.DebugInfo("\t#An unhandled exception occured during unzipping the KPP file you specified! {0}", ConsoleColor.DarkRed, appRealPath); return; } //does a copy of current AppDomain's global network layer settings for each of installing KPP. ChannelInternalConfigSettings settings = new ChannelInternalConfigSettings { BuffStubPoolSize = ChannelConst.BuffStubPoolSize, MaxMessageDataLength = ChannelConst.MaxMessageDataLength, NamedPipeBuffStubPoolSize = ChannelConst.NamedPipeBuffStubPoolSize, NoBuffStubPoolSize = ChannelConst.NoBuffStubPoolSize, RecvBufferSize = ChannelConst.RecvBufferSize, SegmentSize = ChannelConst.SegmentSize }; Application = new Application(HandleSucceedSituation, HandleErrorSituation); Application.Initialize(tuple.Item3, settings, new KAEHostResourceProxy()); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="structure">KPP资源包的数据结构</param> /// <param name="settings">APP所使用的网络资源设置集</param> /// <param name="proxy">KAE宿主代理器</param> /// <param name="greyPolicyCode">灰度升级策略脚本</param> internal void Initialize(KPPDataStructure structure, ChannelInternalConfigSettings settings, IKAEResourceProxy proxy, string greyPolicyCode = null) { _structure = structure; Version = _structure.GetSectionField <string>(0x00, "Version"); PackageName = _structure.GetSectionField <string>(0x00, "PackName"); Description = _structure.GetSectionField <string>(0x00, "PackDescription"); GlobalUniqueId = _structure.GetSectionField <Guid>(0x00, "GlobalUniqueIdentity"); Level = (ApplicationLevel)_structure.GetSectionField <byte>(0x00, "ApplicationLevel"); IsCompletedEnvironment = _structure.GetSectionField <bool>(0x00, "IsCompletedEnvironment"); Status = ApplicationStatus.Initializing; try { _processors = CollectAbilityProcessors(); InnerInitialize(); Status = ApplicationStatus.Initialized; } catch (Exception ex) { _tracing.Error(ex); Status = ApplicationStatus.Exception; throw; } }
/// <summary> /// 为KPP专门设计的初始化SystemWorker的函数 /// </summary> /// <param name="role">服务角色</param> /// <param name="proxy">KAE资源代理器</param> /// <param name="settings">KJFramework网络层设置集</param> /// <param name="appUniqueId">APP唯一编号</param> /// <exception cref="ArgumentNullException">参数不能为空</exception> internal static void InitializeForKPP(string role, IKAEResourceProxy proxy, ChannelInternalConfigSettings settings, Guid appUniqueId) { if (IsInitialized) { return; } if (string.IsNullOrEmpty(role)) { throw new ArgumentNullException(nameof(role)); } _hostProxy = proxy; _appUniqueId = appUniqueId; _configurationProxy = new KPPConfigurationProxy(proxy); SystemConfigurations.Initialize(role, RemoteConfigurationSetting.Default, _configurationProxy); _tracing = TracingManager.GetTracing(typeof(SystemWorker));; TransactionGlobal.Initialize(); //Regist("LGS", new LGSProtocolStack()); TracingManager.NotificationHandler = new RemoteLogProxy(); InitializeCore(role); //initialize long...long memory buffer for tcp layer. ChannelConst.Initialize(settings); _isInitialized = true; IsInSpecifiedKPP = true; }