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