SuperSocket中的Server是如何初Initialize的
第一个函数
d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs
static void Main(string[] args)
{
Console.WriteLine("Press any key to start the server!"); Console.ReadKey();
Console.WriteLine(); var bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize())
{
Console.WriteLine("Failed to initialize!");
Console.ReadKey();
return;
} var result = bootstrap.Start(); Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed)
{
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
} Console.WriteLine("Press key 'q' to stop it!"); while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
} Console.WriteLine(); //Stop the appServer
bootstrap.Stop(); Console.WriteLine("The server was stopped!");
}
第二个函数
d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs
/// <summary>
/// Initializes the bootstrap with the configuration
/// </summary>
/// <returns></returns>
public virtual bool Initialize()
{
return Initialize(c => c);
}
第三个函数
d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs
/// <summary>
/// Initializes the bootstrap with the configuration and config resolver.
/// </summary>
/// <param name="serverConfigResolver">The server config resolver.</param>
/// <returns></returns>
public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver)
{
return Initialize(serverConfigResolver, null);
}
第四个函数
d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs
/// <summary>
/// Initializes the bootstrap with the configuration, config resolver and log factory.
/// </summary>
/// <param name="serverConfigResolver">The server config resolver.</param>
/// <param name="logFactory">The log factory.</param>
/// <returns></returns>
public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
{
if (m_Initialized)
throw new Exception("The server had been initialized already, you cannot initialize it again!"); if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
{
throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
} IEnumerable<WorkItemFactoryInfo> workItemFactories; using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
{
var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory(); logFactory = bootstrapLogFactory.ExportFactory.CreateExport<ILogFactory>(); LogFactory = logFactory;
m_GlobalLog = logFactory.GetLog(this.GetType().Name); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); try
{
workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(e); return false;
}
} m_AppServers = new List<IWorkItem>(m_Config.Servers.Count()); IWorkItem serverManager = null; //Initialize servers
foreach (var factoryInfo in workItemFactories)
{
IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo); if (appServer == null)
return false; if (factoryInfo.IsServerManager)
serverManager = appServer;
else if (!(appServer is IsolationAppServer))//No isolation
{
//In isolation mode, cannot check whether is server manager in the factory info loader
if (TypeValidator.IsServerManagerType(appServer.GetType()))
serverManager = appServer;
} m_AppServers.Add(appServer);
} if (serverManager != null)
m_ServerManager = serverManager; if (!m_Config.DisablePerformanceDataCollector)
{
m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory); if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
} if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.Debug("The Bootstrap has been initialized!"); try
{
RegisterRemotingService();
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("Failed to register remoting access service!", e); return false;
} m_Initialized = true; return true;
}
第五个函数
d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs
private IWorkItem InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo)
{
IWorkItem appServer; try
{
appServer = CreateWorkItemInstance(factoryInfo.ServerType, factoryInfo.StatusInfoMetadata); if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
return null;
} var exceptionSource = appServer as IExceptionSource; if (exceptionSource != null)
exceptionSource.ExceptionThrown += new EventHandler<ErrorEventArgs>(exceptionSource_ExceptionThrown); var setupResult = false; try
{
setupResult = SetupWorkItemInstance(appServer, factoryInfo); if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
}
catch (Exception e)
{
m_GlobalLog.Error(e);
setupResult = false;
} if (!setupResult)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("Failed to setup server instance!"); return null;
} return appServer;
}
第六个函数
d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs
internal virtual bool SetupWorkItemInstance(IWorkItem workItem, WorkItemFactoryInfo factoryInfo)
{
try
{
//Share AppDomain AppServers also share same socket server factory and log factory instances
factoryInfo.SocketServerFactory.ExportFactory.EnsureInstance();
factoryInfo.LogFactory.ExportFactory.EnsureInstance();
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(e); return false;
} return workItem.Setup(this, factoryInfo.Config, factoryInfo.ProviderFactories.ToArray());
}
第七个函数
d:\sourcecode\github\supersocket\socketbase\appserverbase.cs
/// <summary>
/// Setups the specified root config.
/// </summary>
/// <param name="bootstrap">The bootstrap.</param>
/// <param name="config">The socket server instance config.</param>
/// <param name="factories">The factories.</param>
/// <returns></returns>
bool IWorkItem.Setup(IBootstrap bootstrap, IServerConfig config, ProviderFactoryInfo[] factories)
{
if (bootstrap == null)
throw new ArgumentNullException("bootstrap"); Bootstrap = bootstrap; if (factories == null)
throw new ArgumentNullException("factories"); TrySetInitializedState(); var rootConfig = bootstrap.Config; SetupBasic(rootConfig, config, GetSingleProviderInstance<ISocketServerFactory>(factories, ProviderKey.SocketServerFactory)); if (!SetupLogFactory(GetSingleProviderInstance<ILogFactory>(factories, ProviderKey.LogFactory)))
return false; Logger = CreateLogger(this.Name); IEnumerable<IConnectionFilter> connectionFilters = null; if (!TryGetProviderInstances(factories, ProviderKey.ConnectionFilter, null,
(p, f) =>
{
var ret = p.Initialize(f.Name, this); if(!ret)
{
Logger.ErrorFormat("Failed to initialize the connection filter: {0}.", f.Name);
} return ret;
}, out connectionFilters))
{
return false;
} if (!SetupMedium(
GetSingleProviderInstance<IReceiveFilterFactory<TRequestInfo>>(factories, ProviderKey.ReceiveFilterFactory),
connectionFilters,
GetProviderInstances<ICommandLoader<ICommand<TAppSession, TRequestInfo>>>(
factories,
ProviderKey.CommandLoader,
(t) => Activator.CreateInstance(t.MakeGenericType(typeof(ICommand<TAppSession, TRequestInfo>))))))
{
return false;
} if (!SetupAdvanced(config))
return false; if (!Setup(rootConfig, config))
return false; if (!SetupFinal())
return false; m_StateCode = ServerStateConst.NotStarted;
return true;
}
第八个函数
d:\sourcecode\github\supersocket\socketbase\appserverbase.cs
private bool SetupFinal()
{
//Check receiveFilterFactory
if (ReceiveFilterFactory == null)
{
ReceiveFilterFactory = CreateDefaultReceiveFilterFactory(); if (ReceiveFilterFactory == null)
{
if (Logger.IsErrorEnabled)
Logger.Error("receiveFilterFactory is required!"); return false;
}
} var plainConfig = Config as ServerConfig; if (plainConfig == null)
{
//Using plain config model instead of .NET configuration element to improve performance
plainConfig = new ServerConfig(Config); if (string.IsNullOrEmpty(plainConfig.Name))
plainConfig.Name = Name; Config = plainConfig;
} try
{
m_ServerStatus = new StatusInfoCollection();
m_ServerStatus.Name = Name;
m_ServerStatus.Tag = Name;
m_ServerStatus[StatusInfoKeys.MaxConnectionNumber] = Config.MaxConnectionNumber;
m_ServerStatus[StatusInfoKeys.Listeners] = m_Listeners;
}
catch (Exception e)
{
if (Logger.IsErrorEnabled)
Logger.Error("Failed to create ServerSummary instance!", e); return false;
} return SetupSocketServer();
}
第九个函数
d:\sourcecode\github\supersocket\socketbase\appserverbase.cs
/// <summary>
/// Setups the socket server.instance
/// </summary>
/// <returns></returns>
private bool SetupSocketServer()
{
try
{
m_SocketServer = m_SocketServerFactory.CreateSocketServer<TRequestInfo>(this, m_Listeners, Config);
return m_SocketServer != null;
}
catch (Exception e)
{
if (Logger.IsErrorEnabled)
Logger.Error(e); return false;
}
}
第十个函数
d:\sourcecode\github\supersocket\socketengine\socketserverfactory.cs
/// <summary>
/// Default socket server factory
/// </summary>
public class SocketServerFactory : ISocketServerFactory
{
#region ISocketServerFactory Members /// <summary>
/// Creates the socket server.
/// </summary>
/// <typeparam name="TRequestInfo">The type of the request info.</typeparam>
/// <param name="appServer">The app server.</param>
/// <param name="listeners">The listeners.</param>
/// <param name="config">The config.</param>
/// <returns></returns>
public ISocketServer CreateSocketServer<TRequestInfo>(IAppServer appServer, ListenerInfo[] listeners, IServerConfig config)
where TRequestInfo : IRequestInfo
{
if (appServer == null)
throw new ArgumentNullException("appServer"); if (listeners == null)
throw new ArgumentNullException("listeners"); if (config == null)
throw new ArgumentNullException("config"); switch(config.Mode)
{
case(SocketMode.Tcp):
return new AsyncSocketServer(appServer, listeners);
case(SocketMode.Udp):
return new UdpSocketServer<TRequestInfo>(appServer, listeners);
default:
throw new NotSupportedException("Unsupported SocketMode:" + config.Mode);
}
} #endregion
}
SuperSocket中的Server是如何初Initialize的的更多相关文章
- SuperSocket中的Server是如何初Start的
第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...
- SuperSocket中的Server的初始化和启动
一.初始化的过程 static void Main(string[] args) { var bootstrap = BootstrapFactory.CreateBootstrap(); if (! ...
- win7中 SQL server 2005无法连接到服务器,错误码:18456
win7中 SQL server 2005无法连接到服务器,错误码:18456.. 数据库刚装完.我用Windows登陆 结果登陆不上去.. 选中SQL Server Management Stud ...
- Asp.net中使用Server.HtmlDecode(string str)的使用
前言: 在使用Visual Studio开发web页面时,需要在GridView中绑定Table数据,并加入了CommandField, 试图,点击详情按钮是,获取GridView中Rows中Cell ...
- servers中添加server时,看不到运行环境的选择。
servers中添加server时,看不到运行环境的选择. 主要原因是tomcat目录中的配置文件格式不对.
- paip.java 开发中web server的选择jboss resin tomcat比较..
paip.java 开发中web server的选择jboss resin tomcat比较.. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专 ...
- Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6629298 在前面一篇文章浅谈Android系 ...
- Windows10中“SQL Server 配置管理器”哪去了?
SQL Server 配置管理器是一种工具,用于管理与 SQL Server 相关联的服务.配置 SQL Server 使用的网络协议以及从 SQL Server 客户端计算机管理网络连接配置.SQL ...
- tomcat配置好后,启动eclipse中的server,不能出现有猫的页面,提示404
原因:tomcat与eclipse中的server未关联起来 解决办法:双击servers中的server,在Server Locations中选中第二项,保存之后再进行刚才的操作就好了.
随机推荐
- 「 Luogu P2196 」 挖地雷
# 解题思路 跑 $\text{n}$ 遍 $\text{spfa}$ 并记录路径,找到比当前最长路长的就更新答案,并且将路径也更新,注意起点的处理. # 附上代码 #include <iost ...
- [GXOI/GZOI2019]与或和(单调栈)
想了想决定把这几题也随便水个解题报告... bzoj luogu 思路: 首先肯定得拆成二进制30位啊 此后每一位的就是个01矩阵 Q1就是全是1的矩阵个数 Q2就是总矩阵个数减去全是0的矩阵个数 ...
- linux命令 host-常用的分析域名查询工具
博主推荐:更多网络测试相关命令关注 网络测试 收藏linux命令大全 host命令是常用的分析域名查询工具,可以用来测试域名系统工作是否正常. 语法 host(选项)(参数) 选项 -a:显示详细的 ...
- buf.entries()详解
buf.entries() 返回:{Iterator} 从当前 Buffer 的内容中,创建并返回一个 [index, byte] 形式的迭代器. const buf = Buffer.from('b ...
- python flask获取微信用户信息报404,nginx问题
在学习flask与微信公众号时问题,发现测试自动回复/wechat8008时正常,而测试获取微信用户信息/wechat8008/index时出现404.查询资料后收发是nginx配置问题. 在loca ...
- 早期创业,应该充分利用互联网产品和服务(从”皇包车”看一家全球中文车导服务平台如何选用ToB产品)
前段时间,在搜索"皇包车"相关的资料,于是在IT桔子网站看到了"从'皇包车'看一家全球中文车导服务平台如何选用ToB产品"这篇文章. 我是非常的震撼! ...
- AD采集精度中的LSB
测量范围+5V, 精度10位,LSB=0.0048 精度16位,LSB=0.000076951 测量范围+-5V, 精度10位,LSB=0.009765625,大约为0.01 精度16位,LSB=0. ...
- 对Kaldi nnet3进行奇异值分解(SVD)以减小模型大小
用处 基于SVD实现模型压缩以适配低功耗平台 根据nnet3bin/nnet3-copy,nnet3-copy或nnet3-am-copy的"--edits-config" ...
- 7-26 Windows消息队列(25 分)(堆排序)
7-26 Windows消息队列(25 分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中. ...
- HDU 1525 Euclid Game
题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...