Skip to content

Commit

Permalink
working configuration compatibility between DotNetty & Helios
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Jan 19, 2017
1 parent 1d22345 commit 651cdc2
Show file tree
Hide file tree
Showing 11 changed files with 451 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@
<Compile Include="HeliosHelpers.cs" />
<Compile Include="HeliosTcpTransport.cs" />
<Compile Include="HeliosTransport.cs" />
<Compile Include="HeliosTransportSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<EmbeddedResource Include="remote.conf" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka.Remote\Akka.Remote.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class HeliosTcpTransport : HeliosTransport
/// <param name="system">TBD</param>
/// <param name="config">TBD</param>
public HeliosTcpTransport(ActorSystem system, Config config)
: base(system, config)
: base(system, config, "akka.remote.helios.tcp")
{
}

Expand Down
196 changes: 8 additions & 188 deletions src/contrib/transports/Akka.Remote.Transport.Helios/HeliosTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@
#endregion

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Dispatch;
using Akka.Event;
using Akka.Util;
using Helios.Channels;
using Helios.Channels.Bootstrap;
using Helios.Channels.Sockets;
using Helios.Codecs;
using Helios.Exceptions;
using Helios.Logging;
using Helios.Topology;
using Helios.Util.Concurrency;
using AtomicCounter = Helios.Util.AtomicCounter;
using LengthFieldPrepender = Helios.Codecs.LengthFieldPrepender;
Expand Down Expand Up @@ -81,193 +77,16 @@ public TcpTransportException(string message, Exception cause = null) : base(mess
}
}

/// <summary>
/// TBD
/// </summary>
internal class HeliosTransportSettings
{
/// <summary>
/// TBD
/// </summary>
internal readonly Config Config;

/// <summary>
/// TBD
/// </summary>
/// <param name="config">TBD</param>
public HeliosTransportSettings(Config config)
{
Config = config;
Init();
}
static HeliosTransportSettings()
{
// Disable STDOUT logging for Helios in release mode
#if !DEBUG
LoggingFactory.DefaultFactory = new NoOpLoggerFactory();
#endif

}

private void Init()
{
//TransportMode
var protocolString = Config.GetString("transport-protocol");
if (protocolString.Equals("tcp")) TransportMode = new Tcp();
else if (protocolString.Equals("udp")) TransportMode = new Udp();
else throw new ConfigurationException(string.Format("Unknown transport transport-protocol='{0}'", protocolString));
EnableSsl = Config.GetBoolean("enable-ssl");
ConnectTimeout = Config.GetTimeSpan("connection-timeout");
WriteBufferHighWaterMark = OptionSize("write-buffer-high-water-mark");
WriteBufferLowWaterMark = OptionSize("write-buffer-low-water-mark");
SendBufferSize = OptionSize("send-buffer-size");
ReceiveBufferSize = OptionSize("receive-buffer-size");
var size = OptionSize("maximum-frame-size");
if (size == null || size < 32000) throw new ConfigurationException("Setting 'maximum-frame-size' must be at least 32000 bytes");
MaxFrameSize = (int)size;
Backlog = Config.GetInt("backlog");
TcpNoDelay = Config.GetBoolean("tcp-nodelay");
TcpKeepAlive = Config.GetBoolean("tcp-keepalive");
TcpReuseAddr = Config.GetBoolean("tcp-reuse-addr");
var configHost = Config.GetString("hostname");
var publicConfigHost = Config.GetString("public-hostname");
DnsUseIpv6 = Config.GetBoolean("dns-use-ipv6");
EnforceIpFamily = RuntimeDetector.IsMono || Config.GetBoolean("enforce-ip-family");
Hostname = string.IsNullOrEmpty(configHost) ? IPAddress.Any.ToString() : configHost;
PublicHostname = string.IsNullOrEmpty(publicConfigHost) ? Hostname : publicConfigHost;
ServerSocketWorkerPoolSize = ComputeWps(Config.GetConfig("server-socket-worker-pool"));
ClientSocketWorkerPoolSize = ComputeWps(Config.GetConfig("client-socket-worker-pool"));
Port = Config.GetInt("port");

// used to provide backwards compatibility with Helios 1.* clients
BackwardsCompatibilityModeEnabled = Config.GetBoolean("enable-backwards-compatibility", false);
}

/// <summary>
/// TBD
/// </summary>
public TransportMode TransportMode { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool EnableSsl { get; private set; }

/// <summary>
/// TBD
/// </summary>
public TimeSpan ConnectTimeout { get; private set; }

/// <summary>
/// TBD
/// </summary>
public long? WriteBufferHighWaterMark { get; private set; }

/// <summary>
/// TBD
/// </summary>
public long? WriteBufferLowWaterMark { get; private set; }

/// <summary>
/// TBD
/// </summary>
public long? SendBufferSize { get; private set; }

/// <summary>
/// TBD
/// </summary>
public long? ReceiveBufferSize { get; private set; }

/// <summary>
/// TBD
/// </summary>
public int MaxFrameSize { get; private set; }

/// <summary>
/// TBD
/// </summary>
public int Port { get; private set; }

/// <summary>
/// TBD
/// </summary>
public int Backlog { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool TcpNoDelay { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool TcpKeepAlive { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool TcpReuseAddr { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool DnsUseIpv6 { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool EnforceIpFamily { get; private set; }

/// <summary>
/// The hostname that this server binds to
/// </summary>
public string Hostname { get; private set; }

/// <summary>
/// If different from <see cref="Hostname"/>, this is the public "address" that is bound to the <see cref="ActorSystem"/>,
/// whereas <see cref="Hostname"/> becomes the physical address that the low-level socket connects to.
/// </summary>
public string PublicHostname { get; private set; }

/// <summary>
/// TBD
/// </summary>
public int ServerSocketWorkerPoolSize { get; private set; }

/// <summary>
/// TBD
/// </summary>
public int ClientSocketWorkerPoolSize { get; private set; }

/// <summary>
/// TBD
/// </summary>
public bool BackwardsCompatibilityModeEnabled { get; private set; }

#region Internal methods

private long? OptionSize(string s)
{
var bytes = Config.GetByteSize(s);
if (bytes == null || bytes == 0) return null;
if (bytes < 0) throw new ConfigurationException(string.Format("Setting {0} must be 0 or positive", s));
return bytes;
}

private int ComputeWps(Config config)
{
return ThreadPoolConfig.ScaledPoolSize(config.GetInt("pool-size-min"), config.GetDouble("pool-size-factor"),
config.GetInt("pool-size-max"));
}

#endregion
}

/// <summary>
/// Abstract base class for HeliosTransport - has separate child implementations for TCP / UDP respectively
/// </summary>
abstract class HeliosTransport : Transport
{
internal static Config DefaultConfig()
{
var config = ConfigurationFactory.FromResource<HeliosTransport>("Akka.Remote.Transport.Helios.remote.conf");
return config;
}

private readonly IEventLoopGroup _serverEventLoopGroup;
private readonly IEventLoopGroup _clientEventLoopGroup;
Expand All @@ -277,11 +96,12 @@ abstract class HeliosTransport : Transport
/// </summary>
/// <param name="system">TBD</param>
/// <param name="config">TBD</param>
protected HeliosTransport(ActorSystem system, Config config)
protected HeliosTransport(ActorSystem system, Config config, string fallbackConfigPath)
{
Config = config;
System = system;
Settings = new HeliosTransportSettings(config);
var fallbackConfig = DefaultConfig();
Settings = new HeliosTransportSettings(config.WithFallback(fallbackConfig.GetConfig(fallbackConfigPath)));
Log = Logging.GetLogger(System, GetType());
_serverEventLoopGroup = new MultithreadEventLoopGroup(Settings.ServerSocketWorkerPoolSize);
_clientEventLoopGroup = new MultithreadEventLoopGroup(Settings.ClientSocketWorkerPoolSize);
Expand Down
Loading

0 comments on commit 651cdc2

Please sign in to comment.