public object Create(object parent, object configContext, System.Xml.XmlNode section) { CastleServiceConfiguration config = new CastleServiceConfiguration(); config.LoadValuesFromConfigurationXml(section); return(config); }
/// <summary> /// HttpServiceCaller初始化 /// </summary> /// <param name="group"></param> /// <param name="config"></param> /// <param name="container"></param> public HttpServiceCaller(IWorkItemsGroup group, CastleServiceConfiguration config, IServiceContainer container) { this.config = config; this.container = container; this.smart = group; this.callers = new HttpCallerInfoCollection(); this.callTimeouts = new Dictionary<string, int>(); }
private int maxCalls = ServiceConfig.DEFAULT_MAX_CALL; //默认的并发调用数 /// <summary> /// 获取远程对象配置 /// </summary> /// <returns></returns> public static CastleServiceConfiguration GetConfig() { string key = "mysoft.framework/castleService"; CastleServiceConfiguration obj = CacheHelper.Get <CastleServiceConfiguration>(key); if (obj == null) { var tmp = ConfigurationManager.GetSection(key); obj = tmp as CastleServiceConfiguration; CacheHelper.Permanent(key, obj); } return(obj); }
/// <summary> /// 实例化ServerStatusService /// </summary> /// <param name="server"></param> /// <param name="container"></param> /// <param name="config"></param> public ServerStatusService(IScsServer server, CastleServiceConfiguration config, IServiceContainer container) { this.config = config; this.server = server; this.container = container; this.startTime = DateTime.Now; this.statuslist = new TimeStatusCollection(config.RecordHours * 3600); this.counterlist = new CounterInfoCollection(config.MinuteCalls); //启动定义推送线程 var threadPush = new Thread(DoPushWork); threadPush.IsBackground = true; threadPush.Start(); //启动自动检测线程 var threadCheck = new Thread(DoCheckWork); threadCheck.IsBackground = true; threadCheck.Start(); }
/// <summary> /// 实例化CastleService /// </summary> /// <param name="config"></param> public CastleService(CastleServiceConfiguration config) { this.config = config; if (string.Compare(config.Host, "any", true) == 0) { config.Host = IPAddress.Loopback.ToString(); epServer = new ScsTcpEndPoint(config.Port); } else epServer = new ScsTcpEndPoint(config.Host, config.Port); this.server = ScsServerFactory.CreateServer(epServer); this.server.ClientConnected += server_ClientConnected; this.server.ClientDisconnected += server_ClientDisconnected; this.server.WireProtocolFactory = new CustomWireProtocolFactory(config.Compress, config.Encrypt); //服务端注入内存处理 this.container = new SimpleServiceContainer(CastleFactoryType.Local); this.container.OnError += error => { if (OnError != null) OnError(error); }; this.container.OnLog += (log, type) => { if (OnLog != null) OnLog(log, type); }; //实例化SmartThreadPool var stp = new STPStartInfo { IdleTimeout = config.Timeout * 1000, MaxWorkerThreads = Math.Max(config.MaxCalls, 10), MinWorkerThreads = 5, ThreadPriority = ThreadPriority.Normal, WorkItemPriority = WorkItemPriority.Normal }; //创建线程池 smart = new SmartThreadPool(stp); smart.Start(); //创建并发任务组 var group = smart.CreateWorkItemsGroup(2); group.Start(); //实例化调用者 var status = new ServerStatusService(server, config, container); this.caller = new ServiceCaller(group, status); //判断是否启用httpServer if (config.HttpEnabled) { //设置默认的解析器 IHttpApiResolver resolver = new DefaultApiResolver(); //判断是否配置了HttpType if (config.HttpType != null && typeof(IHttpApiResolver).IsAssignableFrom(config.HttpType)) { resolver = Activator.CreateInstance(config.HttpType) as IHttpApiResolver; } var httpCaller = new HttpServiceCaller(group, config, container); //刷新服务委托 status.OnRefresh += () => httpCaller.InitCaller(resolver); //初始化调用器 httpCaller.InitCaller(resolver); var handler = new HttpServiceHandler(httpCaller); var factory = new HttpRequestHandlerFactory(handler); this.httpServer = new HTTPServer(factory, config.HttpPort); } //绑定事件 MessageCenter.Instance.OnError += Instance_OnError; }
public object Create(object parent, object configContext, System.Xml.XmlNode section) { CastleServiceConfiguration config = new CastleServiceConfiguration(); config.LoadValuesFromConfigurationXml(section); return config; }