public void LoadAddins() { string directory = System.IO.Directory.GetParent(System.Windows.Forms.Application.ExecutablePath).FullName ; this .addinManagement.LoadAllAddins(directory , true ) ; } public void Start() { this .agileTcp.Start() ; this .serverPerformanceMonitor.Start() ; this .asRemotingServiceAccesser.FsStarted() ; } public void Stop() { this .agileTcp.Stop() ; this .serverPerformanceMonitor.Stop() ; this .asRemotingServiceAccesser.FsToExit() ; } public void ReadyToExit() { this .Stop() ; this .agileTcp.Dispose() ; }
各个方法的含义和成员变量的含义相信大家已经非常的明白了,由必要解释一下serverPerformanceMonitor,它用于监控本服务器的性能状态,并将性能数据通过事件发布。如果你读过前面的文章,你会知道,这些性能数据将被发送给AS,然后AS根据这些性能数据在多个FS上进行负载均衡调度。asRemotingServiceAccesser用于访问AS发布的远程服务,比如FS启动或退出时通知AS。 FS核心的类FunctionServer就这些功能。你一定非常想知道,ITcp、ITcpStreamDispatcher等是如何与FunctionServer装配起来的,谜底马上揭晓。相对于使用4个cs文件就实现了FS来说,FS的组件装配就稍微复杂些(AS则更复杂)。我采用SPring.NET来完成组件装配。 我们先看ITcp组件的装配: < object name = " agileTcp " type = " ESFramework.Network.Tcp.AgileTcp ,ESFramework " init - method = " Initialize " > < property name = " Port " > < object type = " Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject ,Spring.Core " > < property name = " TargetObject " ref = " fsConfiguration " /> < property name = " TargetProperty " value = " TcpPort " /> </ object > </ property > < property name = " MaxMessageSize " value = " 2000000 " /> < property name = " Dispatcher " ref = " tcpStreamDispatcher " /> < property name = " ContractHelper " ref = " contractHelper " /> < property name = " BufferPool " > < object type = " ESFramework.Network.Tcp.SimpleBufferPool ,ESFramework " /> </ property > </ object >
如果你研究过AgileTcp组件,上面的配置非常容易理解,最主要的,AgileTcp使用的分派器组件,分配器组件的装配如下: < object name = " tcpStreamDispatcher " type = " ESFramework.Network.Tcp.TcpStreamDispatcher ,ESFramework " > < property name = " ContractHelper " ref = " contractHelper " /> < property name = " TcpClientsController " ref = " agileTcp " /> < property name = " RequestDealerFactory " > < object type = " ESFramework.Network.FunAddinDealerFactory ,ESFramework " > < property name = " AddinManagement " ref = " addinManagement " /> </ object > </ property > </ object >
非常需要说明一点的是,消息分派器使用的处理器工厂是ESFramework.Network.FunAddinDealerFactory,因为它只需要处理功能请求,并且这些功能请求是由功能插件处理的,所以使用ESFramework.Network.FunAddinDealerFactory就可以了,而不需要使用功能全面的EsbRequestDealerFactory,EsbRequestDealerFactory通常由AS使用。 最后一个重要组件的装配--FunctionServer: < object name = " functionServer " type = " FunctionServerSystem.Server.FunctionServer ,FunctionServerSystem " > < property name = " AgileTcp " ref = " agileTcp " /> < property name = " AddinManagement " ref = " addinManagement " /> < property name = " ServerPerformanceMonitor " ref = " serverPerformanceMonitor " /> < property name = " AsRemotingServiceAccesser " ref = " asRemotingServiceAccesser " /> </ object >
毫无秘密可言! 还有就是主界面MainForm的装配,就不罗列了,大家看源码就知道了。这是FS的一个例子,如果你需要看到客户端的例子, 是一个选择,不过AgileIM稍微复杂了些,过段时间我会给出一个简单的建立在ESFramework上的客户端实现。 下面是FS运行时的截图: (VS2003)。