Ejemplo n.º 1
0
        public DotNettyTransportSettings(TransportMode transportMode, bool enableSsl, TimeSpan connectTimeout, string hostname, string publicHostname,
            int port, int? publicPort, int serverSocketWorkerPoolSize, int clientSocketWorkerPoolSize, int maxFrameSize, SslSettings ssl,
            bool dnsUseIpv6, bool tcpReuseAddr, bool tcpKeepAlive, bool tcpNoDelay, int backlog, bool enforceIpFamily,
            int? receiveBufferSize, int? sendBufferSize, int? writeBufferHighWaterMark, int? writeBufferLowWaterMark, bool backwardsCompatibilityModeEnabled, bool logTransport, ByteOrder byteOrder, 
            bool enableBufferPooling, BatchWriterSettings batchWriterSettings)
        {
            if (maxFrameSize < 32000) throw new ArgumentException("maximum-frame-size must be at least 32000 bytes", nameof(maxFrameSize));

            TransportMode = transportMode;
            EnableSsl = enableSsl;
            ConnectTimeout = connectTimeout;
            Hostname = hostname;
            PublicHostname = publicHostname;
            Port = port;
            PublicPort = publicPort;
            ServerSocketWorkerPoolSize = serverSocketWorkerPoolSize;
            ClientSocketWorkerPoolSize = clientSocketWorkerPoolSize;
            MaxFrameSize = maxFrameSize;
            Ssl = ssl;
            DnsUseIpv6 = dnsUseIpv6;
            TcpReuseAddr = tcpReuseAddr;
            TcpKeepAlive = tcpKeepAlive;
            TcpNoDelay = tcpNoDelay;
            Backlog = backlog;
            EnforceIpFamily = enforceIpFamily;
            ReceiveBufferSize = receiveBufferSize;
            SendBufferSize = sendBufferSize;
            WriteBufferHighWaterMark = writeBufferHighWaterMark;
            WriteBufferLowWaterMark = writeBufferLowWaterMark;
            BackwardsCompatibilityModeEnabled = backwardsCompatibilityModeEnabled;
            LogTransport = logTransport;
            ByteOrder = byteOrder;
            EnableBufferPooling = enableBufferPooling;
            BatchWriterSettings = batchWriterSettings;
        }
        public static DotNettyTransportSettings Create(Config config)
        {
            if (config.IsNullOrEmpty())
            {
                throw ConfigurationException.NullOrEmptyConfig <DotNettyTransportSettings>();
            }

            var transportMode = config.GetString("transport-protocol", "tcp").ToLower();
            var host          = config.GetString("hostname", null);

            if (string.IsNullOrEmpty(host))
            {
                host = IPAddress.Any.ToString();
            }
            var publicHost = config.GetString("public-hostname", null);
            var publicPort = config.GetInt("public-port", 0);

            var order           = ByteOrder.LittleEndian;
            var byteOrderString = config.GetString("byte-order", "little-endian").ToLowerInvariant();

            switch (byteOrderString)
            {
            case "little-endian": order = ByteOrder.LittleEndian; break;

            case "big-endian": order = ByteOrder.BigEndian; break;

            default: throw new ArgumentException($"Unknown byte-order option [{byteOrderString}]. Supported options are: big-endian, little-endian.");
            }

            var batchWriterSettings = new BatchWriterSettings(config.GetConfig("batching"));

            return(new DotNettyTransportSettings(
                       transportMode: transportMode == "tcp" ? TransportMode.Tcp : TransportMode.Udp,
                       enableSsl: config.GetBoolean("enable-ssl", false),
                       connectTimeout: config.GetTimeSpan("connection-timeout", TimeSpan.FromSeconds(15)),
                       hostname: host,
                       publicHostname: !string.IsNullOrEmpty(publicHost) ? publicHost : host,
                       port: config.GetInt("port", 2552),
                       publicPort: publicPort > 0 ? publicPort : (int?)null,
                       serverSocketWorkerPoolSize: ComputeWorkerPoolSize(config.GetConfig("server-socket-worker-pool")),
                       clientSocketWorkerPoolSize: ComputeWorkerPoolSize(config.GetConfig("client-socket-worker-pool")),
                       maxFrameSize: ToNullableInt(config.GetByteSize("maximum-frame-size", null)) ?? 128000,
                       ssl: config.HasPath("ssl") ? SslSettings.Create(config.GetConfig("ssl")) : SslSettings.Empty,
                       dnsUseIpv6: config.GetBoolean("dns-use-ipv6", false),
                       tcpReuseAddr: ResolveTcpReuseAddrOption(config.GetString("tcp-reuse-addr", "off-for-windows")),
                       tcpKeepAlive: config.GetBoolean("tcp-keepalive", true),
                       tcpNoDelay: config.GetBoolean("tcp-nodelay", true),
                       backlog: config.GetInt("backlog", 4096),
                       enforceIpFamily: RuntimeDetector.IsMono || config.GetBoolean("enforce-ip-family", false),
                       receiveBufferSize: ToNullableInt(config.GetByteSize("receive-buffer-size", null) ?? 256000),
                       sendBufferSize: ToNullableInt(config.GetByteSize("send-buffer-size", null) ?? 256000),
                       writeBufferHighWaterMark: ToNullableInt(config.GetByteSize("write-buffer-high-water-mark", null)),
                       writeBufferLowWaterMark: ToNullableInt(config.GetByteSize("write-buffer-low-water-mark", null)),
                       backwardsCompatibilityModeEnabled: config.GetBoolean("enable-backwards-compatibility", false),
                       logTransport: config.HasPath("log-transport") && config.GetBoolean("log-transport", false),
                       byteOrder: order,
                       enableBufferPooling: config.GetBoolean("enable-pooling", true),
                       batchWriterSettings: batchWriterSettings));
        }
Ejemplo n.º 3
0
 public BatchWriter(BatchWriterSettings settings)
 {
     Settings = settings;
 }