一 继承Net配置系统

Net应用程序配置机制跟程序集引用大致类似,均具有继承性,如iis几乎每个应用程序都会有一个Web.config,比如我们使用vs2012以上版本创建一个web应用程序会自带一个web.config配置文件,这个配置文件属于整个应用程序全局配置文件,再有某些个别目录下也会存在web.config这样的配置文件,连名字都跟应用程序配置文件相同,那么他们看起来重复出现,到底是为何?

Net的配置具有继承性,怎么理解?比如当前文件夹所拥有的配置则作用范围仅为当前文件夹,如果没有那么他们直接寻找应用程序根目录下config文件并当作自己的配置文件直到应用程序根目录,其查找顺序由下往上,由近及远,与dll引用一样本地找不到就去GAC找直到找不到;其中IIS中各个Web.Config继承性就非常的典型,所以这里也不再举例

SuperSocket使用了Net配置系统,而不是我们平常的一个对象序列化成一个xml文件的私有配置,对比起来减少了配置文件读写次数,且net配置系统本就如此强大

二 SuperSocket私有配置扩展

2.1 TypeProvider

SuperSocket对net配置元素进行一次继承,其代码如下

 public class TypeProvider : ConfigurationElement, ITypeProvider
{
/// <summary>
/// Gets the name.
/// </summary>
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get { return this["name"] as string; }
} /// <summary>
/// Gets the type.
/// </summary>
[ConfigurationProperty("type", IsRequired = true)]
public string Type
{
get { return this["type"] as string; }
}
}

扩展了Name和Type两个属性,这与SuperSocket类型提供工厂类完全对应;

  /// <summary>
/// Provider factory infomation
/// </summary>
[Serializable]
public class ProviderFactoryInfo
{
/// <summary>
/// Gets the key.
/// </summary>
public ProviderKey Key { get; set; } /// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; } /// <summary>
/// Gets or sets the export factory.
/// </summary>
/// <value>
/// The export factory.
/// </value>
public ExportFactory ExportFactory { get; set; } /// <summary>
/// Initializes a new instance of the <see cref="ProviderFactoryInfo"/> class.
/// </summary>
public ProviderFactoryInfo()
{ } /// <summary>
/// Initializes a new instance of the <see cref="ProviderFactoryInfo"/> class.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="name">The name.</param>
/// <param name="instance">The instance.</param>
public ProviderFactoryInfo(ProviderKey key, string name, object instance)
{
Key = key;
Name = name;
ExportFactory = new ExportFactory(instance);
} /// <summary>
/// Initializes a new instance of the <see cref="ProviderFactoryInfo"/> class.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="name">The name.</param>
/// <param name="typeName">Name of the type.</param>
public ProviderFactoryInfo(ProviderKey key, string name, string typeName)
{
Key = key;
Name = name;
ExportFactory = new ExportFactory(typeName);
} /// <summary>
/// Initializes a new instance of the <see cref="ProviderFactoryInfo"/> class.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="name">The name.</param>
/// <param name="type">The type.</param>
public ProviderFactoryInfo(ProviderKey key, string name, Type type)
: this(key, name, type.AssemblyQualifiedName)
{ }
}

从代码上可以看出只要有Name和Type这2个参数即可构造一个ProviderFactoryInfo类的实例

2.2 TypeProviderCollection 扩展的TypeProvider类型集合

 [ConfigurationCollection(typeof(TypeProvider))]
public class TypeProviderCollection : ConfigurationElementCollection, IEnumerable<ITypeProvider>
{
/// <summary>
/// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
/// </summary>
/// <returns>
/// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
/// </returns>
protected override ConfigurationElement CreateNewElement()
{
return new TypeProvider() as ConfigurationElement;
} /// <summary>
/// Gets the element key for a specified configuration element when overridden in a derived class.
/// </summary>
/// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
/// <returns>
/// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
/// </returns>
protected override object GetElementKey(ConfigurationElement element)
{
var provider = element as TypeProvider; if (provider == null)
return null; return provider.Name;
} /// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// </returns>
public new IEnumerator<ITypeProvider> GetEnumerator()
{
int count = base.Count; for (int i = ; i < count; i++)
{
yield return (ITypeProvider)base.BaseGet(i);
}
}
}

三 SuperSocket配置内容

3.1 全局配置

如图红色部分所示,SuperSocket的所有配置均包裹在SocketServiceConfig这类型中,且成为App.config的一个配置节点section,那么SocketServiceConfig又包含了什么呢?

 public partial class SocketServiceConfig : ConfigurationSection, IConfigurationSource
{
/// <summary>
/// Gets all the server configurations
/// </summary>
[ConfigurationProperty("servers")]
public ServerCollection Servers
{
get
{
return this["servers"] as ServerCollection;
}
} /// <summary>
/// Gets the service configurations
/// </summary>
[ConfigurationProperty("serverTypes")]
public TypeProviderCollection ServerTypes
{
get
{
return this["serverTypes"] as TypeProviderCollection;
}
} /// <summary>
/// Gets all the connection filter configurations.
/// </summary>
[ConfigurationProperty("connectionFilters", IsRequired = false)]
public TypeProviderCollection ConnectionFilters
{
get
{
return this["connectionFilters"] as TypeProviderCollection;
}
} /// <summary>
/// Gets the defined log factory types.
/// </summary>
[ConfigurationProperty("logFactories", IsRequired = false)]
public TypeProviderCollection LogFactories
{
get
{
return this["logFactories"] as TypeProviderCollection;
}
} /// <summary>
/// Gets the logfactory name of the bootstrap.
/// </summary>
[ConfigurationProperty("receiveFilterFactories", IsRequired = false)]
public TypeProviderCollection ReceiveFilterFactories
{
get
{
return this["receiveFilterFactories"] as TypeProviderCollection;
}
} /// <summary>
/// Gets the command loaders definition.
/// </summary>
[ConfigurationProperty("commandLoaders", IsRequired = false)]
public TypeProviderCollection CommandLoaders
{
get
{
return this["commandLoaders"] as TypeProviderCollection;
}
} /// <summary>
/// Gets the max working threads.
/// </summary>
[ConfigurationProperty("maxWorkingThreads", IsRequired = false, DefaultValue = -)]
public int MaxWorkingThreads
{
get
{
return (int)this["maxWorkingThreads"];
}
} /// <summary>
/// Gets the min working threads.
/// </summary>
[ConfigurationProperty("minWorkingThreads", IsRequired = false, DefaultValue = -)]
public int MinWorkingThreads
{
get
{
return (int)this["minWorkingThreads"];
}
} /// <summary>
/// Gets the max completion port threads.
/// </summary>
[ConfigurationProperty("maxCompletionPortThreads", IsRequired = false, DefaultValue = -)]
public int MaxCompletionPortThreads
{
get
{
return (int)this["maxCompletionPortThreads"];
}
} /// <summary>
/// Gets the min completion port threads.
/// </summary>
[ConfigurationProperty("minCompletionPortThreads", IsRequired = false, DefaultValue = -)]
public int MinCompletionPortThreads
{
get
{
return (int)this["minCompletionPortThreads"];
}
} /// <summary>
/// Gets the performance data collect interval, in seconds.
/// </summary>
[ConfigurationProperty("performanceDataCollectInterval", IsRequired = false, DefaultValue = )]
public int PerformanceDataCollectInterval
{
get
{
return (int)this["performanceDataCollectInterval"];
}
} /// <summary>
/// Gets a value indicating whether [disable performance data collector].
/// </summary>
/// <value>
/// <c>true</c> if [disable performance data collector]; otherwise, <c>false</c>.
/// </value>
[ConfigurationProperty("disablePerformanceDataCollector", IsRequired = false, DefaultValue = false)]
public bool DisablePerformanceDataCollector
{
get
{
return (bool)this["disablePerformanceDataCollector"];
}
} /// <summary>
/// Gets the isolation mode.
/// </summary>
[ConfigurationProperty("isolation", IsRequired = false, DefaultValue = IsolationMode.None)]
public IsolationMode Isolation
{
get { return (IsolationMode)this["isolation"]; }
} /// <summary>
/// Gets the logfactory name of the bootstrap.
/// </summary>
[ConfigurationProperty("logFactory", IsRequired = false, DefaultValue = "")]
public string LogFactory
{
get
{
return (string)this["logFactory"];
}
} /// <summary>
/// Gets the option elements.
/// </summary>
public NameValueCollection OptionElements { get; private set; } /// <summary>
/// Gets a value indicating whether an unknown element is encountered during deserialization.
/// To keep compatible with old configuration
/// </summary>
/// <param name="elementName">The name of the unknown subelement.</param>
/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> being used for deserialization.</param>
/// <returns>
/// true when an unknown element is encountered while deserializing; otherwise, false.
/// </returns>
/// <exception cref="T:System.Configuration.ConfigurationErrorsException">The element identified by <paramref name="elementName"/> is locked.- or -One or more of the element's attributes is locked.- or -<paramref name="elementName"/> is unrecognized, or the element has an unrecognized attribute.- or -The element has a Boolean attribute with an invalid value.- or -An attempt was made to deserialize a property more than once.- or -An attempt was made to deserialize a property that is not a valid member of the element.- or -The element cannot contain a CDATA or text element.</exception>
protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
{
//To keep compatible with old configuration
if (!"services".Equals(elementName, StringComparison.OrdinalIgnoreCase))
{
if (OptionElements == null)
OptionElements = new NameValueCollection(); OptionElements.Add(elementName, reader.ReadOuterXml());
return true;
} var serverTypes = new TypeProviderCollection();
reader.Read();
serverTypes.Deserialize(reader); this["serverTypes"] = serverTypes; return true;
} /// <summary>
/// Gets a value indicating whether an unknown attribute is encountered during deserialization.
/// </summary>
/// <param name="name">The name of the unrecognized attribute.</param>
/// <param name="value">The value of the unrecognized attribute.</param>
/// <returns>
/// true when an unknown attribute is encountered while deserializing; otherwise, false.
/// </returns>
protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
{
const string xmlns = "xmlns";
const string xmlnsPrefix = "xmlns:";
const string xsiPrefix = "xsi:"; //for configuration intellisense, allow these unrecognized attributes: xmlns, xmlns:*, xsi:*
if (name.Equals(xmlns) || name.StartsWith(xmlnsPrefix) || name.StartsWith(xsiPrefix))
return true; return false;
} /// <summary>
/// Gets the child config.
/// </summary>
/// <typeparam name="TConfig">The type of the config.</typeparam>
/// <param name="childConfigName">Name of the child config.</param>
/// <returns></returns>
public TConfig GetChildConfig<TConfig>(string childConfigName)
where TConfig : ConfigurationElement, new()
{
return this.OptionElements.GetChildConfig<TConfig>(childConfigName);
} IEnumerable<IServerConfig> IConfigurationSource.Servers
{
get
{
return this.Servers;
}
} IEnumerable<ITypeProvider> IConfigurationSource.ServerTypes
{
get
{
return this.ServerTypes;
}
} IEnumerable<ITypeProvider> IConfigurationSource.ConnectionFilters
{
get
{
return this.ConnectionFilters;
}
} IEnumerable<ITypeProvider> IConfigurationSource.LogFactories
{
get
{
return this.LogFactories;
}
} IEnumerable<ITypeProvider> IConfigurationSource.ReceiveFilterFactories
{
get
{
return this.ReceiveFilterFactories;
}
} IEnumerable<ITypeProvider> IConfigurationSource.CommandLoaders
{
get
{
return this.CommandLoaders;
}
}
}

1)Servers服务实例;

  集合:AppServer有多少appserver实例

2)ServerTypes服务类型ServerTypes

  集合:继承AppServer的子类型

3)ConnectionFilters

  集合:说明了有多少个连接过滤工厂类型

4)LogFactories

集合:说明了有多少个日志工厂类型

5)ReceiveFilterFactories

  集合:说明了有多少个协议解析工厂类型

6)CommandLoaders

  集合:说明了有多少个命令加载工厂类型

7)MaxWorkingThreads

  app最大工作线程数,主要用于配置ThreadPool

等等,这里可以详细参考官方文档SuperSocket配置:http://docs.supersocket.net/v1-6/zh-CN/SuperSocket-Basic-Configuration

其中类型的配置示例

 <serverTypes>

   <add name="TelnetServer" type="SuperSocket.QuickStart.TelnetServer_StartByConfig.TelnetServer, SuperSocket.QuickStart.TelnetServer_StartByConfig"/
</serverTypes>

均是TypeProvider,只需指定Name和type即可

3.2 服务配置

与之对应的类型ServerConfig,每个详细的配置均有默认值

 public partial class ServerConfig : IServerConfig
{
/// <summary>
/// Default ReceiveBufferSize
/// </summary>
public const int DefaultReceiveBufferSize = ; /// <summary>
/// Default MaxConnectionNumber
/// </summary>
public const int DefaultMaxConnectionNumber = ; /// <summary>
/// Default sending queue size
/// </summary>
public const int DefaultSendingQueueSize = ; /// <summary>
/// Default MaxRequestLength
/// </summary>
public const int DefaultMaxRequestLength = ; /// <summary>
/// Default send timeout value, in milliseconds
/// </summary>
public const int DefaultSendTimeout = ; /// <summary>
/// Default clear idle session interval
/// </summary>
public const int DefaultClearIdleSessionInterval = ; /// <summary>
/// Default idle session timeout
/// </summary>
public const int DefaultIdleSessionTimeOut = ; /// <summary>
/// The default send buffer size
/// </summary>
public const int DefaultSendBufferSize = ; /// <summary>
/// The default session snapshot interval
/// </summary>
public const int DefaultSessionSnapshotInterval = ; /// <summary>
/// The default keep alive time
/// </summary>
public const int DefaultKeepAliveTime = ; // 60 * 10 = 10 minutes /// <summary>
/// The default keep alive interval
/// </summary>
public const int DefaultKeepAliveInterval = ; // 60 seconds /// <summary>
/// The default listen backlog
/// </summary>
public const int DefaultListenBacklog = ; /// <summary>
/// Initializes a new instance of the <see cref="ServerConfig"/> class.
/// </summary>
/// <param name="serverConfig">The server config.</param>
public ServerConfig(IServerConfig serverConfig)
{
serverConfig.CopyPropertiesTo(this); this.Options = serverConfig.Options;
this.OptionElements = serverConfig.OptionElements; if (serverConfig.Certificate != null)
this.Certificate = serverConfig.Certificate.CopyPropertiesTo(new CertificateConfig()); if (serverConfig.Listeners != null && serverConfig.Listeners.Any())
{
this.Listeners = serverConfig.Listeners.Select(l => l.CopyPropertiesTo(new ListenerConfig())).OfType<ListenerConfig>().ToArray();
} if (serverConfig.CommandAssemblies != null && serverConfig.CommandAssemblies.Any())
{
this.CommandAssemblies = serverConfig.CommandAssemblies.Select(c => c.CopyPropertiesTo(new CommandAssemblyConfig())).OfType<CommandAssemblyConfig>().ToArray();
}
} /// <summary>
/// Initializes a new instance of the <see cref="ServerConfig"/> class.
/// </summary>
public ServerConfig()
{
Security = "None";
MaxConnectionNumber = DefaultMaxConnectionNumber;
Mode = SocketMode.Tcp;
MaxRequestLength = DefaultMaxRequestLength;
KeepAliveTime = DefaultKeepAliveTime;
KeepAliveInterval = DefaultKeepAliveInterval;
ListenBacklog = DefaultListenBacklog;
ReceiveBufferSize = DefaultReceiveBufferSize;
SendingQueueSize = DefaultSendingQueueSize;
SendTimeOut = DefaultSendTimeout;
ClearIdleSessionInterval = DefaultClearIdleSessionInterval;
IdleSessionTimeOut = DefaultIdleSessionTimeOut;
SendBufferSize = DefaultSendBufferSize;
LogBasicSessionActivity = true;
SessionSnapshotInterval = DefaultSessionSnapshotInterval;
} #region IServerConfig Members /// <summary>
/// Gets/sets the name of the server type of this appServer want to use.
/// </summary>
/// <value>
/// The name of the server type.
/// </value>
public string ServerTypeName { get; set; } /// <summary>
/// Gets/sets the type definition of the appserver.
/// </summary>
/// <value>
/// The type of the server.
/// </value>
public string ServerType { get; set; } /// <summary>
/// Gets/sets the Receive filter factory.
/// </summary>
public string ReceiveFilterFactory { get; set; } /// <summary>
/// Gets/sets the ip.
/// </summary>
public string Ip { get; set; } /// <summary>
/// Gets/sets the port.
/// </summary>
public int Port { get; set; } /// <summary>
/// Gets/sets the options.
/// </summary>
public NameValueCollection Options { get; set; } /// <summary>
/// Gets the option elements.
/// </summary>
public NameValueCollection OptionElements { get; set; } /// <summary>
/// Gets/sets a value indicating whether this <see cref="IServerConfig"/> is disabled.
/// </summary>
/// <value>
/// <c>true</c> if disabled; otherwise, <c>false</c>.
/// </value>
public bool Disabled { get; set; } /// <summary>
/// Gets the name.
/// </summary>
public string Name { get; set; } /// <summary>
/// Gets/sets the mode.
/// </summary>
public SocketMode Mode { get; set; } /// <summary>
/// Gets/sets the send time out.
/// </summary>
public int SendTimeOut { get; set; } /// <summary>
/// Gets the max connection number.
/// </summary>
public int MaxConnectionNumber { get; set; } /// <summary>
/// Gets the size of the receive buffer.
/// </summary>
/// <value>
/// The size of the receive buffer.
/// </value>
public int ReceiveBufferSize { get; set; } /// <summary>
/// Gets the size of the send buffer.
/// </summary>
/// <value>
/// The size of the send buffer.
/// </value>
public int SendBufferSize { get; set; } /// <summary>
/// Gets a value indicating whether sending is in synchronous mode.
/// </summary>
/// <value>
/// <c>true</c> if [sync send]; otherwise, <c>false</c>.
/// </value>
public bool SyncSend { get; set; } /// <summary>
/// Gets/sets a value indicating whether log command in log file.
/// </summary>
/// <value>
/// <c>true</c> if log command; otherwise, <c>false</c>.
/// </value>
public bool LogCommand { get; set; } /// <summary>
/// Gets/sets a value indicating whether clear idle session.
/// </summary>
/// <value>
/// <c>true</c> if clear idle session; otherwise, <c>false</c>.
/// </value>
public bool ClearIdleSession { get; set; } /// <summary>
/// Gets/sets the clear idle session interval, in seconds.
/// </summary>
/// <value>
/// The clear idle session interval.
/// </value>
public int ClearIdleSessionInterval { get; set; } /// <summary>
/// Gets/sets the idle session timeout time length, in seconds.
/// </summary>
/// <value>
/// The idle session time out.
/// </value>
public int IdleSessionTimeOut { get; set; } /// <summary>
/// Gets/sets X509Certificate configuration.
/// </summary>
/// <value>
/// X509Certificate configuration.
/// </value>
public ICertificateConfig Certificate { get; set; } /// <summary>
/// Gets/sets the security protocol, X509 certificate.
/// </summary>
public string Security { get; set; } /// <summary>
/// Gets/sets the length of the max request.
/// </summary>
/// <value>
/// The length of the max request.
/// </value>
public int MaxRequestLength { get; set; } /// <summary>
/// Gets/sets a value indicating whether [disable session snapshot].
/// </summary>
/// <value>
/// <c>true</c> if [disable session snapshot]; otherwise, <c>false</c>.
/// </value>
public bool DisableSessionSnapshot { get; set; } /// <summary>
/// Gets/sets the interval to taking snapshot for all live sessions.
/// </summary>
public int SessionSnapshotInterval { get; set; } /// <summary>
/// Gets/sets the connection filters used by this server instance.
/// </summary>
/// <value>
/// The connection filter's name list, seperated by comma
/// </value>
public string ConnectionFilter { get; set; } /// <summary>
/// Gets the command loader, multiple values should be separated by comma.
/// </summary>
public string CommandLoader { get; set; } /// <summary>
/// Gets/sets the start keep alive time, in seconds
/// </summary>
public int KeepAliveTime { get; set; } /// <summary>
/// Gets/sets the keep alive interval, in seconds.
/// </summary>
public int KeepAliveInterval { get; set; } /// <summary>
/// Gets the backlog size of socket listening.
/// </summary>
public int ListenBacklog { get; set; } /// <summary>
/// Gets/sets the startup order of the server instance.
/// </summary>
public int StartupOrder { get; set; } /// <summary>
/// Gets the child config.
/// </summary>
/// <typeparam name="TConfig">The type of the config.</typeparam>
/// <param name="childConfigName">Name of the child config.</param>
/// <returns></returns>
public virtual TConfig GetChildConfig<TConfig>(string childConfigName)
where TConfig : ConfigurationElement, new()
{
return this.OptionElements.GetChildConfig<TConfig>(childConfigName);
} /// <summary>
/// Gets and sets the listeners' configuration.
/// </summary>
public IEnumerable<IListenerConfig> Listeners { get; set; } /// <summary>
/// Gets/sets the log factory name.
/// </summary>
public string LogFactory { get; set; } /// <summary>
/// Gets/sets the size of the sending queue.
/// </summary>
/// <value>
/// The size of the sending queue.
/// </value>
public int SendingQueueSize { get; set; } /// <summary>
/// Gets a value indicating whether [log basic session activity like connected and disconnected].
/// </summary>
/// <value>
/// <c>true</c> if [log basic session activity]; otherwise, <c>false</c>.
/// </value>
public bool LogBasicSessionActivity { get; set; } /// <summary>
/// Gets/sets a value indicating whether [log all socket exception].
/// </summary>
/// <value>
/// <c>true</c> if [log all socket exception]; otherwise, <c>false</c>.
/// </value>
public bool LogAllSocketException { get; set; } /// <summary>
/// Gets/sets the default text encoding.
/// </summary>
/// <value>
/// The text encoding.
/// </value>
public string TextEncoding { get; set; } /// <summary>
/// Gets the command assemblies configuration.
/// </summary>
/// <value>
/// The command assemblies.
/// </value>
public IEnumerable<ICommandAssemblyConfig> CommandAssemblies { get; set; } #endregion
}

其详细可参考代码和文档:

http://docs.supersocket.net/v1-6/zh-CN/Start-SuperSocket-by-Configuration:重配置启动

http://docs.supersocket.net/v1-6/zh-CN/SuperSocket-Basic-Configuration:服务实例配置

3.3 IRootConfig

这是最顶层的配置,从代码可以看出是对全局进行基础性配置,同时也是大部分配置实现了,如SocketServiceConfig

 public partial interface IRootConfig
{
/// <summary>
/// Gets the max working threads.
/// </summary>
int MaxWorkingThreads { get; } /// <summary>
/// Gets the min working threads.
/// </summary>
int MinWorkingThreads { get; } /// <summary>
/// Gets the max completion port threads.
/// </summary>
int MaxCompletionPortThreads { get; } /// <summary>
/// Gets the min completion port threads.
/// </summary>
int MinCompletionPortThreads { get; } /// <summary>
/// Gets a value indicating whether [disable performance data collector].
/// </summary>
/// <value>
/// <c>true</c> if [disable performance data collector]; otherwise, <c>false</c>.
/// </value>
bool DisablePerformanceDataCollector { get; } /// <summary>
/// Gets the performance data collect interval, in seconds.
/// </summary>
int PerformanceDataCollectInterval { get; } /// <summary>
/// Gets the log factory name.
/// </summary>
/// <value>
/// The log factory.
/// </value>
string LogFactory { get; } /// <summary>
/// Gets the isolation mode.
/// </summary>
IsolationMode Isolation { get; } /// <summary>
/// Gets the option elements.
/// </summary>
NameValueCollection OptionElements { get; } /// <summary>
/// Gets the child config.
/// </summary>
/// <typeparam name="TConfig">The type of the config.</typeparam>
/// <param name="childConfigName">Name of the child config.</param>
/// <returns></returns>
TConfig GetChildConfig<TConfig>(string childConfigName)
where TConfig : ConfigurationElement, new();
}

四 配置如何使用

诚然net的配置是非常方便的只需一句代码即可

var configSection = ConfigurationManager.GetSection("superSocket");即可拿到所有Supersocket的配置

五 根据配置启动

在所提供的代码中大多数都是以配置启动服务器,将SuperSocket直接作为app,那么其启动入口则有BootstrapFactory开始

5.1 引导程序开始

public static IBootstrap CreateBootstrap()
{
  var configSection = ConfigurationManager.GetSection("superSocket");

  if (configSection == null)//to keep compatible with old version
    configSection = ConfigurationManager.GetSection("socketServer");

  if(configSection == null)
    throw new ConfigurationErrorsException("Missing 'superSocket' or 'socketServer' configuration section.");

  var configSource = configSection as IConfigurationSource;
  if(configSource == null)
    throw new ConfigurationErrorsException("Invalid 'superSocket' or 'socketServer' configuration section.");

  return CreateBootstrap(configSource);
}

5.2 appserver工厂代理加载器

public List<WorkItemFactoryInfo> LoadResult(Func<IServerConfig, IServerConfig> serverConfigResolver)
通过代理直接将所配置的类型提供信息解析成 ProviderFactoryInfo他们只是封装了name和type但是可以导出各类工厂如LogFactory,这里就直接转到了工厂设计模式频道了

然后将所有这些ProviderFactoryInfo成为WorkItemFactoryInfo的配套也就是说每个AppServer的配套,AppServer所需要的如Log,SocketServer均由ProviderFactoryInfo所导出的与之相应的LogFactory,SocketServerFactory创建,并且将配置作为这些对象初始化参数

5.3 启动所有Server

六 默认配置

6.1 默认全局日志

由Log4NetFactory创建,代码位置

6.2 AppServer 默认日志

Log4NetFactory

6.3 默认的SocketServerFactroy

workItemFactory.SocketServerFactory = new ProviderFactoryInfo(ProviderKey.SocketServerFactory, string.Empty, typeof(SocketServerFactory));

6.4 默认的协议

且使用换行符作为结束标志,如发送一条消息 echo xxd ccc;那么解析后key:echo,body:xxd ccc ,params:xxd,ccc,其中参数以空格为分割

6.5 连接过滤

没有默认

6.6 命令加载器

ReflectCommandLoader

七 配置改变

http://docs.supersocket.net/v1-6/zh-CN/Server-Configuration-Hot-Update

SuperSocket源码解析之配置系统的更多相关文章

  1. Mybatis 系列6-结合源码解析节点配置:objectFactory、databaseIdProvider、plugins、mappers

    [Mybatis 系列10-结合源码解析mybatis 执行流程] [Mybatis 系列9-强大的动态sql 语句] [Mybatis 系列8-结合源码解析select.resultMap的用法] ...

  2. SuperSocket源码解析之开篇

    一 简介 官方介绍:SuperSocket 是一个轻量级, 跨平台而且可扩展的 .Net/Mono Socket 服务器程序框架.你无须了解如何使用 Socket, 如何维护 Socket 连接和 S ...

  3. SuperSocket源码解析之开篇 (转)

    一 简介 官方介绍:SuperSocket 是一个轻量级, 跨平台而且可扩展的 .Net/Mono Socket 服务器程序框架.你无须了解如何使用 Socket, 如何维护 Socket 连接和 S ...

  4. SuperSocket源码解析之启动过程

    一 简介 这里主要说明从配置系统引导启动SuperScoekt作为应用程序,且以控制台程序方式启动 二 启动过程 2.1 配置解析 从读取配置文件开始,直接拿到一个SocketServiceConfi ...

  5. 干货分享之Spring框架源码解析01-(xml配置解析)

    记录并分享一下本人学习spring源码的过程,有什么问题或者补充会持续更新.欢迎大家指正! 环境: spring5.X + idea Spring 是一个工厂,是一个负责对象的创建和维护的工厂.它给我 ...

  6. Spring源码解析 – @Configuration配置类及注解Bean的解析

    在分析Spring 容器创建过程时,我们知道容器默认会加载一些后置处理器PostPRocessor,以AnnotationConfigApplicationContext为例,在构造函数中初始化rea ...

  7. Ejabberd源码解析前奏--配置

    一.基本配置     配置文件将在你第一次启动ejabberd时加载,从该文件中获得的内容将被解析并存储到内部的ejabberd数据库中,以后的配置将从数据库加载,并且任何配置文件里的命令都会被添加到 ...

  8. SuperSocket源码解析之消息处理

    一 简述 Tcp消息的处理本身是与Tcp消息传输过程独立的,是消息的两个不同阶段,从前面的会话生命周期我们已经知道消息的传输主要有SocketSession实现,而真正处理则交由AppSession实 ...

  9. SuperSocket源码解析之会话生命周期

    一 基本概念 会话(Session)是客户端与服务器进行通信的基本单元,也是一个Socket的封装,在http协议中也有Session机制,其主要作用封装一个通信单元socket,负责服务器与客户端消 ...

随机推荐

  1. 利用jxl读取excel合并的单元格的一个小样例

    工作中我们可能要把Excel文件的记录保存到数据库, 今天我用jxl读取Excel文件时遇到了合并格的问题,记录例如以下: 如Excel文件例如以下: watermark/2/text/aHR0cDo ...

  2. js常用几种类方法实现

    js定义类方法的常用几种定义 1 定义方法,方法中包含实现 function createCORSRequest() { var xhr = new XMLHttpRequest(); xhr.onl ...

  3. [转载]CSS 创作指南(Beta)(css规范)

    当年还在纠结各种规范的时候,不知道从哪里翻到这个,就让我脱离了css这个规范的苦海了... 反正就是团队和项目合作说的算,选择合适的进行使用就可以了,见到合适的文章,我也会转载过来的 来源 https ...

  4. HTML5 总结-应用程序缓存-8

    HTML 5 应用程序缓存 使用 HTML5,通过创建 cache manifest 文件,可以轻松地创建 web 应用的离线版本. 什么是应用程序缓存(Application Cache)? HTM ...

  5. 405 HTTP method GET is not supported by this URL

    孙鑫java web开发详解P285里面提交Get网站弹出提示405 HTTP method GET is not supported by this URL 原因父类doGet()方法未覆盖. 应写 ...

  6. S2S:分享出的营销机遇

    (速途网专栏 作者:高学争)经常在网上购物的你,有没有遇到过这样的问题:你知道自己想买什么,但是在淘宝上一搜,出来了数以万计的同类型,他们有着同样的价位(甚至可能是同样的图片),但是由不同的商家提供, ...

  7. cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(六)-马里奥跳跃

    当w键按下时,马里奥执行跳跃动作 执行跳跃动作也是在MarioMove函数中调用的

  8. 使用FreeType实现矢量字体的粗体、斜体、描边、阴影效果

    前言: Freetype是一个跨平台.开源的字体渲染器,网上很多文章介绍,本人就不啰嗦了.本文重点在于实现文章标题所属的各种效果,不是Freetype的基本使用方法介绍文档,所以对于Freetype不 ...

  9. SQL Server 2008 还原数据库

    1.得到数据库备份文件,怎么得到的,[能够看这里]~ 2.把备份文件加个.bak 的后缀,比如: 3.打开SQL , 你能够新建一个空数据库 , 或者利用原有的数据库 , 点击右键>>任务 ...

  10. iOS开发- 打包ipa,让别人设备安装你的App

    一般在接外包的时候, 通常第三方须要安装你的app进行測试(这时候你的app肯定是还没传到app store之前). 这样的情况下.假设是企业账号就好办了, 随便安装.. 可是个人开发人员账号呢? 假 ...