一 继承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. 学习MVC遇到的问题

    修改电脑上的DNS配置: Opendns 首选DNS服务器和备用DNS服务器分别设置为208.67.222.222和208.67.220.220 google的8.8.8.8 首选DNS服务器和备用D ...

  2. 解决Jedis数据读取乱码问题

    现象 同一套代码,同一个数据源,不同的操作系统,在OSX上数据提取编码正常,而Ubuntu上拉取数据乱码,数据拉取代码如下. @Override public List<String> m ...

  3. mysql 中的 IF 和 IFNULL 用法

    IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境. IF(S ...

  4. java的for循环问题的解决,以及安卓中ListView插入数据的问题

    package test.testdemo; import org.springframework.jdbc.core.JdbcTemplate; import com.util.Pub; publi ...

  5. php的迭代器

    接口Iterator 主要需要实现的方法: abstract public mixed current ( void ) abstract public scalar key ( void ) abs ...

  6. Oracle中的EXCEPTION

    Oracle系统预定义的异常 比如:SELF_IS_NULL.VALUE_ERROR.ZERO_DIVIDE等Oracle中自带的异常类型 使用方法: DECLARE V_Result ); BEGI ...

  7. 关于Mysql索引的笔记

    MySQL索引原理 索引目的 索引的目的在于提高查询效率,可以类比字典,如果要查“mysql”这个单词,我们肯定需要定位到m字母,然后从下往下找到y字母,再找到剩下的sql.如果没有索引,那么你可能需 ...

  8. chrome浏览器强制采用https加密链接

    在chrome地址栏输入chrome://net-internals/#hsts,然后把www.google.com添加到domain,并且Include subdomains全部沟上添加就可以了.

  9. mongoDB初接触

    首先去官网http://www.mongodb.org/ 下载mongoDB 下载后解压D:\mongodb 创建两个新文件夹data以及log 新建一个文件命名为mongodb.cfg dbpath ...

  10. 用SQL实现统计报表中的"小计"与"合计"的方法详解

    本篇文章是对使用SQL实现统计报表中的"小计"与"合计"的方法进行了详细的分析介绍,需要的朋友参考下   客户提出需求,针对某一列分组加上小计,合计汇总.网上找 ...