示例#1
0
        static ByteBufferUtil()
        {
            Logger = InternalLoggerFactory.GetInstance(typeof(ByteBufferUtil));

            string allocType = SystemPropertyUtil.Get("io.netty.allocator.type", "pooled");

            allocType = allocType.Trim();

            IByteBufferAllocator alloc;

            if ("unpooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = UnpooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else if ("pooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else if ("arraypooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = ArrayPooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: pooled (unknown: {})", allocType);
            }

            DefaultAllocator    = alloc;
            MaxBytesPerCharUtf8 = Encoding.UTF8.GetMaxByteCount(1);
            AsciiByteProcessor  = new FindNonAscii();
        }
示例#2
0
        static ByteBufferUtil()
        {
            string allocType = SystemPropertyUtil.Get("io.netty.allocator.type", "pooled");

            allocType = allocType.Trim();

            IByteBufferAllocator alloc;

            if ("unpooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = UnpooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else if ("pooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: pooled (unknown: {})", allocType);
            }

            DefaultAllocator = alloc;
        }
示例#3
0
        static DefaultChannelId()
        {
            int    processId       = -1;
            string customProcessId = SystemPropertyUtil.Get("io.netty.processId");

            if (customProcessId is object)
            {
                if (!int.TryParse(customProcessId, out processId))
                {
                    processId = -1;
                }
                if (processId < 0 || processId > MaxProcessId)
                {
                    processId = -1;
                    Logger.Warn("-Dio.netty.processId: {} (malformed)", customProcessId);
                }
                else if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.processId: {} (user-set)", processId);
                }
            }
            if (processId < 0)
            {
                processId = DefaultProcessId();
                if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.processId: {} (auto-detected)", processId);
                }
            }
            ProcessId = processId;
            byte[] machineId       = null;
            string customMachineId = SystemPropertyUtil.Get("io.netty.machineId");

            if (customMachineId is object)
            {
                if (MachineIdPattern.Match(customMachineId).Success)
                {
                    machineId = ParseMachineId(customMachineId);
                    if (Logger.DebugEnabled)
                    {
                        Logger.Debug("-Dio.netty.machineId: {} (user-set)", customMachineId);
                    }
                }
                else
                {
                    Logger.Warn("-Dio.netty.machineId: {} (malformed)", customMachineId);
                }
            }

            if (machineId is null)
            {
                machineId = DefaultMachineId();
                if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.machineId: {} (auto-detected)", MacAddressUtil.FormatAddress(machineId));
                }
            }
            MachineId = machineId;
        }
示例#4
0
        static ThreadDeathWatcher()
        {
            string poolName            = "threadDeathWatcher";
            string serviceThreadPrefix = SystemPropertyUtil.Get("io.netty.serviceThreadPrefix");

            if (!string.IsNullOrEmpty(serviceThreadPrefix))
            {
                poolName = serviceThreadPrefix + poolName;
            }
        }
示例#5
0
        static ResourceLeakDetector()
        {
            // If new property name is present, use it
            string levelStr = SystemPropertyUtil.Get(PropLevel, DefaultLevel.ToString());

            if (!Enum.TryParse(levelStr, true, out DetectionLevel level))
            {
                level = DefaultLevel;
            }

            TargetRecords = SystemPropertyUtil.GetInt(PropTargetRecords, DefaultTargetRecords);
            Level         = level;

            if (Logger.DebugEnabled)
            {
                Logger.Debug("-D{}: {}", PropLevel, level.ToString().ToLower());
                Logger.Debug("-D{}: {}", PropTargetRecords, TargetRecords);
            }
        }
示例#6
0
        static ResourceLeakDetector()
        {
            Logger = InternalLoggerFactory.GetInstance <ResourceLeakDetector>();

            bool disabled = false;

            if (SystemPropertyUtil.Get("io.netty.noResourceLeakDetection") is object)
            {
                disabled = SystemPropertyUtil.GetBoolean("io.netty.noResourceLeakDetection", false);
                if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.noResourceLeakDetection: {}", disabled);
                }
                Logger.Warn(
                    "-Dio.netty.noResourceLeakDetection is deprecated. Use '-D{}={}' instead.",
                    PropLevel, DefaultLevel.ToString().ToLowerInvariant());
            }

            var defaultLevel = disabled ? DetectionLevel.Disabled : DefaultLevel;

            // If new property name is present, use it
            string levelStr = SystemPropertyUtil.Get(PropLevel, defaultLevel.ToString());

            if (!Enum.TryParse(levelStr, true, out DetectionLevel level))
            {
                level = defaultLevel;
            }

            s_targetRecords    = SystemPropertyUtil.GetInt(PropTargetRecords, DefaultTargetRecords);
            s_samplingInterval = SystemPropertyUtil.GetInt(PropSamplingInterval, DefaultSamplingInterval);
            Level = level;

            if (Logger.DebugEnabled)
            {
                Logger.Debug("-D{}: {}", PropLevel, level.ToString().ToLower());
                Logger.Debug("-D{}: {}", PropTargetRecords, s_targetRecords);
            }
        }
示例#7
0
        static FABChannelId()
        {
            int    processId       = -1;
            string customProcessId = SystemPropertyUtil.Get("io.netty.processId");

            if (customProcessId != null)
            {
                if (!int.TryParse(customProcessId, out processId))
                {
                    processId = -1;
                }
                if (processId < 0 || processId > MaxProcessId)
                {
                    processId = -1;
                }
            }
            if (processId < 0)
            {
                processId = DefaultProcessId();
            }
            ProcessId = processId;
            byte[] machineId       = null;
            string customMachineId = SystemPropertyUtil.Get("io.netty.machineId");

            if (customMachineId != null)
            {
                if (MachineIdPattern.Match(customMachineId).Success)
                {
                    machineId = ParseMachineId(customMachineId);
                }
            }

            if (machineId == null)
            {
                machineId = DefaultMachineId();
            }
            MachineId = machineId;
        }
示例#8
0
        static StringUtil()
        {
            EmptyString = string.Empty;
            Newline     = SystemPropertyUtil.Get("line.separator", Environment.NewLine);

            Byte2HexPad   = new string[256];
            Byte2HexNopad = new string[256];
            // Generate the lookup table that converts a byte into a 2-digit hexadecimal integer.
            int i;

            for (i = 0; i < 10; i++)
            {
                var buf = new StringBuilder(2);
                _ = buf.Append('0');
                _ = buf.Append(i);
                Byte2HexPad[i]   = buf.ToString();
                Byte2HexNopad[i] = (i).ToString();
            }
            for (; i < 16; i++)
            {
                var  buf = new StringBuilder(2);
                char c   = (char)('A' + i - 10);
                _ = buf.Append('0');
                _ = buf.Append(c);
                Byte2HexPad[i]   = buf.ToString();
                Byte2HexNopad[i] = c.ToString(); /* String.valueOf(c);*/
            }
            for (; i < Byte2HexPad.Length; i++)
            {
                var buf = new StringBuilder(2);
                _ = buf.Append(i.ToString("X") /*Integer.toHexString(i)*/);
                string str = buf.ToString();
                Byte2HexPad[i]   = str;
                Byte2HexNopad[i] = str;
            }
        }
示例#9
0
        static ByteBufferUtil()
        {
            char[] digits = "0123456789abcdef".ToCharArray();
            for (int i = 0; i < 256; i++)
            {
                HexdumpTable[i << 1]       = digits[(int)((uint)i >> 4 & 0x0F)];
                HexdumpTable[(i << 1) + 1] = digits[i & 0x0F];
            }

            // Generate the lookup table for byte-to-hex-dump conversion
            for (int i = 0; i < Byte2Hex.Length; i++)
            {
                Byte2Hex[i] = ' ' + StringUtil.ByteToHexStringPadded(i);
            }

            // Generate the lookup table for hex dump paddings
            for (int i = 0; i < HexPadding.Length; i++)
            {
                int padding = HexPadding.Length - i;
                var buf     = new StringBuilder(padding * 3);
                for (int j = 0; j < padding; j++)
                {
                    buf.Append("   ");
                }
                HexPadding[i] = buf.ToString();
            }

            // Generate the lookup table for byte dump paddings
            for (int i = 0; i < BytePadding.Length; i++)
            {
                int padding = BytePadding.Length - i;
                var buf     = new StringBuilder(padding);
                for (int j = 0; j < padding; j++)
                {
                    buf.Append(' ');
                }
                BytePadding[i] = buf.ToString();
            }

            // Generate the lookup table for byte-to-char conversion
            for (int i = 0; i < Byte2Char.Length; i++)
            {
                if (i <= 0x1f || i >= 0x7f)
                {
                    Byte2Char[i] = '.';
                }
                else
                {
                    Byte2Char[i] = (char)i;
                }
            }

            // Generate the lookup table for the start-offset header in each row (up to 64KiB).
            for (int i = 0; i < HexDumpRowPrefixes.Length; i++)
            {
                var buf = new StringBuilder(12);
                buf.Append(Environment.NewLine);
                buf.Append((i << 4 & 0xFFFFFFFFL | 0x100000000L).ToString("X2"));
                buf.Insert(buf.Length - 9, '|');
                buf.Append('|');
                HexDumpRowPrefixes[i] = buf.ToString();
            }

            string allocType = SystemPropertyUtil.Get(
                "io.netty.allocator.type", "pooled");

            allocType = allocType.Trim();

            IByteBufferAllocator alloc;

            if ("unpooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = UnpooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else if ("pooled".Equals(allocType, StringComparison.OrdinalIgnoreCase))
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: {}", allocType);
            }
            else
            {
                alloc = PooledByteBufferAllocator.Default;
                Logger.Debug("-Dio.netty.allocator.type: pooled (unknown: {})", allocType);
            }

            DefaultAllocator = alloc;
        }