| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Net; |
| | | 4 | | |
| | | 5 | | namespace Ice.Internal; |
| | | 6 | | |
| | | 7 | | public sealed class DefaultsAndOverrides |
| | | 8 | | { |
| | 1 | 9 | | internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) |
| | | 10 | | { |
| | | 11 | | string val; |
| | | 12 | | |
| | 1 | 13 | | defaultProtocol = properties.getIceProperty("Ice.Default.Protocol"); |
| | | 14 | | |
| | 1 | 15 | | val = properties.getIceProperty("Ice.Default.Host"); |
| | 1 | 16 | | if (val.Length != 0) |
| | | 17 | | { |
| | 1 | 18 | | defaultHost = val; |
| | | 19 | | } |
| | | 20 | | else |
| | | 21 | | { |
| | 1 | 22 | | defaultHost = null; |
| | | 23 | | } |
| | | 24 | | |
| | 1 | 25 | | val = properties.getIceProperty("Ice.Default.SourceAddress"); |
| | 1 | 26 | | if (val.Length > 0) |
| | | 27 | | { |
| | 0 | 28 | | defaultSourceAddress = Network.getNumericAddress(val); |
| | 0 | 29 | | if (defaultSourceAddress == null) |
| | | 30 | | { |
| | 0 | 31 | | throw new Ice.InitializationException("invalid IP address set for Ice.Default.SourceAddress: `" + |
| | 0 | 32 | | val + "'"); |
| | | 33 | | } |
| | | 34 | | } |
| | | 35 | | else |
| | | 36 | | { |
| | 1 | 37 | | defaultSourceAddress = null; |
| | | 38 | | } |
| | | 39 | | |
| | 1 | 40 | | val = properties.getIceProperty("Ice.Override.Compress"); |
| | 1 | 41 | | if (val.Length > 0) |
| | | 42 | | { |
| | 1 | 43 | | overrideCompress = properties.getIcePropertyAsInt("Ice.Override.Compress") > 0; |
| | 1 | 44 | | if (!BZip2.isLoaded(logger) && overrideCompress.Value) |
| | | 45 | | { |
| | 0 | 46 | | Console.Error.WriteLine("warning: BZip2 library not found, Ice.Override.Compress ignored."); |
| | 0 | 47 | | overrideCompress = null; |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | else |
| | | 51 | | { |
| | 1 | 52 | | overrideCompress = BZip2.isLoaded(logger) ? null : false; |
| | | 53 | | } |
| | | 54 | | |
| | 1 | 55 | | defaultCollocationOptimization = |
| | 1 | 56 | | properties.getIcePropertyAsInt("Ice.Default.CollocationOptimized") > 0; |
| | | 57 | | |
| | 1 | 58 | | val = properties.getIceProperty("Ice.Default.EndpointSelection"); |
| | 1 | 59 | | if (val == "Random") |
| | | 60 | | { |
| | 1 | 61 | | defaultEndpointSelection = Ice.EndpointSelectionType.Random; |
| | | 62 | | } |
| | 0 | 63 | | else if (val == "Ordered") |
| | | 64 | | { |
| | 0 | 65 | | defaultEndpointSelection = Ice.EndpointSelectionType.Ordered; |
| | | 66 | | } |
| | | 67 | | else |
| | | 68 | | { |
| | 0 | 69 | | throw new ParseException( |
| | 0 | 70 | | $"illegal value '{val}' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | { |
| | 1 | 74 | | int value = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); |
| | 1 | 75 | | if (value < -1) |
| | | 76 | | { |
| | 0 | 77 | | throw new InitializationException($"invalid value for Ice.Default.LocatorCacheTimeout: {value}"); |
| | | 78 | | } |
| | 1 | 79 | | defaultLocatorCacheTimeout = TimeSpan.FromSeconds(value); |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | { |
| | 1 | 83 | | int value = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); |
| | 1 | 84 | | if (value < 1 && value != -1) |
| | | 85 | | { |
| | 0 | 86 | | throw new InitializationException($"invalid value for Ice.Default.InvocationTimeout: {value}"); |
| | | 87 | | } |
| | 1 | 88 | | defaultInvocationTimeout = TimeSpan.FromMilliseconds(value); |
| | | 89 | | } |
| | | 90 | | |
| | 1 | 91 | | val = properties.getIceProperty("Ice.Default.EncodingVersion"); |
| | 1 | 92 | | defaultEncoding = Protocol.stringToEncodingVersion(val); |
| | 1 | 93 | | Protocol.checkSupportedEncoding(defaultEncoding); |
| | | 94 | | |
| | 1 | 95 | | bool slicedFormat = properties.getIcePropertyAsInt("Ice.Default.SlicedFormat") > 0; |
| | 1 | 96 | | defaultFormat = slicedFormat ? FormatType.SlicedFormat : FormatType.CompactFormat; |
| | 1 | 97 | | } |
| | | 98 | | |
| | | 99 | | public string defaultHost; |
| | | 100 | | public EndPoint defaultSourceAddress; |
| | | 101 | | public string defaultProtocol; |
| | | 102 | | public bool defaultCollocationOptimization; |
| | | 103 | | public Ice.EndpointSelectionType defaultEndpointSelection; |
| | | 104 | | public TimeSpan defaultLocatorCacheTimeout; |
| | | 105 | | public TimeSpan defaultInvocationTimeout; |
| | | 106 | | public Ice.EncodingVersion defaultEncoding; |
| | | 107 | | public Ice.FormatType defaultFormat; |
| | | 108 | | |
| | | 109 | | public bool? overrideCompress; |
| | | 110 | | } |