// // Only for use by Ice.CommunicatorI // public Instance(Ice.Communicator communicator, Ice.InitializationData initData) { _state = StateActive; _initData = initData; try { if(_initData.properties == null) { _initData.properties = Ice.Util.createProperties(); } #if !SILVERLIGHT && !UNITY lock(_staticLock) { if(!_oneOffDone) { string stdOut = _initData.properties.getProperty("Ice.StdOut"); string stdErr = _initData.properties.getProperty("Ice.StdErr"); System.IO.StreamWriter outStream = null; if(stdOut.Length > 0) { try { outStream = System.IO.File.AppendText(stdOut); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdOut; throw fe; } outStream.AutoFlush = true; System.Console.Out.Close(); System.Console.SetOut(outStream); } if(stdErr.Length > 0) { if(stdErr.Equals(stdOut)) { System.Console.SetError(outStream); } else { System.IO.StreamWriter errStream = null; try { errStream = System.IO.File.AppendText(stdErr); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdErr; throw fe; } errStream.AutoFlush = true; System.Console.Error.Close(); System.Console.SetError(errStream); } } _oneOffDone = true; } } #endif if(_initData.logger == null) { #if !SILVERLIGHT && !UNITY string logfile = _initData.properties.getProperty("Ice.LogFile"); if(_initData.properties.getPropertyAsInt("Ice.UseSyslog") > 0 && AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { if(logfile.Length != 0) { throw new Ice.InitializationException("Ice.LogFile and Ice.UseSyslog cannot both be set."); } _initData.logger = new Ice.SysLoggerI(_initData.properties.getProperty("Ice.ProgramName"), _initData.properties.getPropertyWithDefault("Ice.SyslogFacility", "LOG_USER")); } else if(logfile.Length != 0) { _initData.logger = new Ice.FileLoggerI(_initData.properties.getProperty("Ice.ProgramName"), logfile); } else if(Ice.Util.getProcessLogger() is Ice.LoggerI) { // // Ice.ConsoleListener is enabled by default. // # if COMPACT _initData.logger = new Ice.ConsoleLoggerI(_initData.properties.getProperty("Ice.ProgramName")); # else bool console = _initData.properties.getPropertyAsIntWithDefault("Ice.ConsoleListener", 1) == 1; _initData.logger = new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), console); # endif } #else if(Ice.Util.getProcessLogger() is Ice.LoggerI) { _initData.logger = new Ice.ConsoleLoggerI(_initData.properties.getProperty("Ice.ProgramName")); } #endif else { _initData.logger = Ice.Util.getProcessLogger(); } } _traceLevels = new TraceLevels(_initData.properties); _defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties); #if COMPACT || SILVERLIGHT char[] separators = { ' ', '\t', '\n', '\r' }; _factoryAssemblies = _initData.properties.getProperty("Ice.FactoryAssemblies").Split(separators); #endif { const int defaultMessageSizeMax = 1024; int num = _initData.properties.getPropertyAsIntWithDefault("Ice.MessageSizeMax", defaultMessageSizeMax); if(num < 1) { _messageSizeMax = defaultMessageSizeMax * 1024; // Ignore non-sensical values. } else if(num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } // // Client ACM enabled by default. Server ACM disabled by default. // _clientACM = _initData.properties.getPropertyAsIntWithDefault("Ice.ACM.Client", 60); _serverACM = _initData.properties.getPropertyAsInt("Ice.ACM.Server"); _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getProperty("Ice.ImplicitContext")); _routerManager = new RouterManager(); _locatorManager = new LocatorManager(_initData.properties); _referenceFactory = new ReferenceFactory(this, communicator); _proxyFactory = new ProxyFactory(this); bool ipv4 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool ipv6 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv6", 1) > 0; if(!ipv4 && !ipv6) { throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled."); } else if(ipv4 && ipv6) { _protocolSupport = Network.EnableBoth; } else if(ipv4) { _protocolSupport = Network.EnableIPv4; } else { _protocolSupport = Network.EnableIPv6; } _preferIPv6 = _initData.properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; _endpointFactoryManager = new EndpointFactoryManager(this); EndpointFactory tcpEndpointFactory = new TcpEndpointFactory(this); _endpointFactoryManager.add(tcpEndpointFactory); EndpointFactory udpEndpointFactory = new UdpEndpointFactory(this); _endpointFactoryManager.add(udpEndpointFactory); #if !SILVERLIGHT _pluginManager = new Ice.PluginManagerI(communicator); #endif _outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this); _servantFactoryManager = new ObjectFactoryManager(); _objectAdapterFactory = new ObjectAdapterFactory(this, communicator); _retryQueue = new RetryQueue(this); string[] facetFilter = _initData.properties.getPropertyAsList("Ice.Admin.Facets"); if(facetFilter.Length > 0) { foreach(string s in facetFilter) { _adminFacetFilter.Add(s); } } _adminFacets.Add("Process", new ProcessI(communicator)); MetricsAdminI admin = new MetricsAdminI(_initData.properties, _initData.logger); _adminFacets.Add("Metrics", admin); PropertiesAdminI props = new PropertiesAdminI("Properties", _initData.properties, _initData.logger); _adminFacets.Add("Properties", props); // // Setup the communicator observer only if the user didn't already set an // Ice observer resolver and if the admininistrative endpoints are set. // if(_initData.observer == null && (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains("Metrics")) && _initData.properties.getProperty("Ice.Admin.Endpoints").Length > 0) { CommunicatorObserverI observer = new CommunicatorObserverI(admin); _initData.observer = observer; // // Make sure the admin plugin receives property updates. // props.addUpdateCallback(admin); } }
private Reference create(Ice.Identity ident, string facet, Reference.Mode mode, bool secure, Ice.ProtocolVersion protocol, Ice.EncodingVersion encoding, EndpointI[] endpoints, string adapterId, string propertyPrefix) { DefaultsAndOverrides defaultsAndOverrides = instance_.defaultsAndOverrides(); // // Default local proxy options. // LocatorInfo locatorInfo = null; if (_defaultLocator != null) { if (!((Ice.ObjectPrxHelperBase)_defaultLocator).reference__().getEncoding().Equals(encoding)) { locatorInfo = instance_.locatorManager().get( (Ice.LocatorPrx)_defaultLocator.ice_encodingVersion(encoding)); } else { locatorInfo = instance_.locatorManager().get(_defaultLocator); } } RouterInfo routerInfo = instance_.routerManager().get(_defaultRouter); bool collocOptimized = defaultsAndOverrides.defaultCollocationOptimization; bool cacheConnection = true; bool preferSecure = defaultsAndOverrides.defaultPreferSecure; Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection; int locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; int invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; Dictionary <string, string> context = null; // // Override the defaults with the proxy properties if a property prefix is defined. // if (propertyPrefix != null && propertyPrefix.Length > 0) { Ice.Properties properties = instance_.initializationData().properties; // // Warn about unknown properties. // if (properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { checkForUnknownProperties(propertyPrefix); } string property; property = propertyPrefix + ".Locator"; Ice.LocatorPrx locator = Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); if (locator != null) { if (!((Ice.ObjectPrxHelperBase)locator).reference__().getEncoding().Equals(encoding)) { locatorInfo = instance_.locatorManager().get( (Ice.LocatorPrx)locator.ice_encodingVersion(encoding)); } else { locatorInfo = instance_.locatorManager().get(locator); } } property = propertyPrefix + ".Router"; Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); if (router != null) { if (propertyPrefix.EndsWith(".Router", StringComparison.Ordinal)) { string s = "`" + property + "=" + properties.getProperty(property) + "': cannot set a router on a router; setting ignored"; instance_.initializationData().logger.warning(s); } else { routerInfo = instance_.routerManager().get(router); } } property = propertyPrefix + ".CollocationOptimized"; collocOptimized = properties.getPropertyAsIntWithDefault(property, collocOptimized ? 1 : 0) > 0; property = propertyPrefix + ".ConnectionCached"; cacheConnection = properties.getPropertyAsIntWithDefault(property, cacheConnection ? 1 : 0) > 0; property = propertyPrefix + ".PreferSecure"; preferSecure = properties.getPropertyAsIntWithDefault(property, preferSecure ? 1 : 0) > 0; property = propertyPrefix + ".EndpointSelection"; if (properties.getProperty(property).Length > 0) { string type = properties.getProperty(property); if (type.Equals("Random")) { endpointSelection = Ice.EndpointSelectionType.Random; } else if (type.Equals("Ordered")) { endpointSelection = Ice.EndpointSelectionType.Ordered; } else { throw new Ice.EndpointSelectionTypeParseException("illegal value `" + type + "'; expected `Random' or `Ordered'"); } } property = propertyPrefix + ".LocatorCacheTimeout"; string val = properties.getProperty(property); if (val.Length > 0) { locatorCacheTimeout = properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout); if (locatorCacheTimeout < -1) { locatorCacheTimeout = -1; StringBuilder msg = new StringBuilder("invalid value for "); msg.Append(property); msg.Append(" `"); msg.Append(properties.getProperty(property)); msg.Append("': defaulting to -1"); instance_.initializationData().logger.warning(msg.ToString()); } } property = propertyPrefix + ".InvocationTimeout"; val = properties.getProperty(property); if (val.Length > 0) { invocationTimeout = properties.getPropertyAsIntWithDefault(property, invocationTimeout); if (invocationTimeout < 1 && invocationTimeout != -1) { invocationTimeout = -1; StringBuilder msg = new StringBuilder("invalid value for "); msg.Append(property); msg.Append(" `"); msg.Append(properties.getProperty(property)); msg.Append("': defaulting to -1"); instance_.initializationData().logger.warning(msg.ToString()); } } property = propertyPrefix + ".Context."; Dictionary <string, string> contexts = properties.getPropertiesForPrefix(property); if (contexts.Count != 0) { context = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> e in contexts) { context.Add(e.Key.Substring(property.Length), e.Value); } } } // // Create new reference // return(new RoutableReference(instance_, _communicator, ident, facet, mode, secure, protocol, encoding, endpoints, adapterId, locatorInfo, routerInfo, collocOptimized, cacheConnection, preferSecure, endpointSelection, locatorCacheTimeout, invocationTimeout, context)); }
// // Only for use by Ice.CommunicatorI // public Instance(Ice.Communicator communicator, Ice.InitializationData initData) { _state = StateActive; _initData = initData; try { if(_initData.properties == null) { _initData.properties = Ice.Util.createProperties(); } #if !SILVERLIGHT && !UNITY lock(_staticLock) { if(!_oneOfDone) { string stdOut = _initData.properties.getProperty("Ice.StdOut"); string stdErr = _initData.properties.getProperty("Ice.StdErr"); System.IO.StreamWriter outStream = null; if(stdOut.Length > 0) { try { outStream = System.IO.File.AppendText(stdOut); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdOut; throw fe; } outStream.AutoFlush = true; System.Console.Out.Close(); System.Console.SetOut(outStream); } if(stdErr.Length > 0) { if(stdErr.Equals(stdOut)) { System.Console.SetError(outStream); } else { System.IO.StreamWriter errStream = null; try { errStream = System.IO.File.AppendText(stdErr); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdErr; throw fe; } errStream.AutoFlush = true; System.Console.Error.Close(); System.Console.SetError(errStream); } } _oneOfDone = true; } } #endif if(_initData.logger == null) { #if !SILVERLIGHT && !UNITY string logfile = _initData.properties.getProperty("Ice.LogFile"); if(_initData.properties.getPropertyAsInt("Ice.UseSyslog") > 0 && AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { if(logfile.Length != 0) { throw new Ice.InitializationException("Ice.LogFile and Ice.UseSyslog cannot both be set."); } _initData.logger = new Ice.SysLoggerI(_initData.properties.getProperty("Ice.ProgramName"), _initData.properties.getPropertyWithDefault("Ice.SyslogFacility", "LOG_USER")); } else if(logfile.Length != 0) { _initData.logger = new Ice.FileLoggerI(_initData.properties.getProperty("Ice.ProgramName"), logfile); } else if(Ice.Util.getProcessLogger() is Ice.LoggerI) { // // Ice.ConsoleListener is enabled by default. // # if COMPACT _initData.logger = new Ice.ConsoleLoggerI(_initData.properties.getProperty("Ice.ProgramName")); # else bool console = _initData.properties.getPropertyAsIntWithDefault("Ice.ConsoleListener", 1) > 0; _initData.logger = new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), console); # endif } #else if(Ice.Util.getProcessLogger() is Ice.LoggerI) { _initData.logger = new Ice.ConsoleLoggerI(_initData.properties.getProperty("Ice.ProgramName")); } #endif else { _initData.logger = Ice.Util.getProcessLogger(); } } _traceLevels = new TraceLevels(_initData.properties); _defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties, _initData.logger); _clientACM = new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM.Client", new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM", new ACMConfig(false))); _serverACM = new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM.Server", new ACMConfig(_initData.properties, _initData.logger, "Ice.ACM", new ACMConfig(true))); #if COMPACT || SILVERLIGHT char[] separators = { ' ', '\t', '\n', '\r' }; _factoryAssemblies = _initData.properties.getProperty("Ice.FactoryAssemblies").Split(separators); #endif { const int defaultMessageSizeMax = 1024; int num = _initData.properties.getPropertyAsIntWithDefault("Ice.MessageSizeMax", defaultMessageSizeMax); if(num < 1 || num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } if(_initData.properties.getProperty("Ice.BatchAutoFlushSize").Length == 0 && _initData.properties.getProperty("Ice.BatchAutoFlush").Length > 0) { if(_initData.properties.getPropertyAsInt("Ice.BatchAutoFlush") > 0) { _batchAutoFlushSize = _messageSizeMax; } } else { int num = _initData.properties.getPropertyAsIntWithDefault("Ice.BatchAutoFlushSize", 1024); // 1MB if(num < 1) { _batchAutoFlushSize = num; } else if(num > 0x7fffffff / 1024) { _batchAutoFlushSize = 0x7fffffff; } else { _batchAutoFlushSize = num * 1024; // Property is in kilobytes, _batchAutoFlushSize in bytes } } _cacheMessageBuffers = _initData.properties.getPropertyAsIntWithDefault("Ice.CacheMessageBuffers", 2); _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getProperty("Ice.ImplicitContext")); _routerManager = new RouterManager(); _locatorManager = new LocatorManager(_initData.properties); _referenceFactory = new ReferenceFactory(this, communicator); _proxyFactory = new ProxyFactory(this); _requestHandlerFactory = new RequestHandlerFactory(this); bool isIPv6Supported = Network.isIPv6Supported(); bool ipv4 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool ipv6 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv6", isIPv6Supported ? 1 : 0) > 0; if(!ipv4 && !ipv6) { throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled."); } else if(ipv4 && ipv6) { _protocolSupport = Network.EnableBoth; } else if(ipv4) { _protocolSupport = Network.EnableIPv4; } else { _protocolSupport = Network.EnableIPv6; } _preferIPv6 = _initData.properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; _networkProxy = createNetworkProxy(_initData.properties, _protocolSupport); _endpointFactoryManager = new EndpointFactoryManager(this); ProtocolInstance tcpProtocolInstance = new ProtocolInstance(this, Ice.TCPEndpointType.value, "tcp"); EndpointFactory tcpEndpointFactory = new TcpEndpointFactory(tcpProtocolInstance); _endpointFactoryManager.add(tcpEndpointFactory); ProtocolInstance udpProtocolInstance = new ProtocolInstance(this, Ice.UDPEndpointType.value, "udp"); EndpointFactory udpEndpointFactory = new UdpEndpointFactory(udpProtocolInstance); _endpointFactoryManager.add(udpEndpointFactory); ProtocolInstance wsProtocolInstance = new ProtocolInstance(this, Ice.WSEndpointType.value, "ws"); _endpointFactoryManager.add(new WSEndpointFactory(wsProtocolInstance, tcpEndpointFactory.clone(wsProtocolInstance))); #if !SILVERLIGHT _pluginManager = new Ice.PluginManagerI(communicator); #endif _outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this); _servantFactoryManager = new ObjectFactoryManager(); _objectAdapterFactory = new ObjectAdapterFactory(this, communicator); _retryQueue = new RetryQueue(this); }
private TraceLevels _traceLevels; // Immutable, not reset by destroy(). #endregion Fields #region Constructors // // Only for use by Ice.CommunicatorI // public Instance(Ice.Communicator communicator, Ice.InitializationData initData) { _state = StateActive; _initData = initData; try { if(_initData.properties == null) { _initData.properties = Ice.Util.createProperties(); } lock(_staticLock) { if(!_oneOffDone) { string stdOut = _initData.properties.getProperty("Ice.StdOut"); string stdErr = _initData.properties.getProperty("Ice.StdErr"); System.IO.StreamWriter outStream = null; if(stdOut.Length > 0) { try { outStream = System.IO.File.AppendText(stdOut); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdOut; throw fe; } outStream.AutoFlush = true; System.Console.Out.Close(); System.Console.SetOut(outStream); } if(stdErr.Length > 0) { if(stdErr.Equals(stdOut)) { System.Console.SetError(outStream); } else { System.IO.StreamWriter errStream = null; try { errStream = System.IO.File.AppendText(stdErr); } catch(System.IO.IOException ex) { Ice.FileException fe = new Ice.FileException(ex); fe.path = stdErr; throw fe; } errStream.AutoFlush = true; System.Console.Error.Close(); System.Console.SetError(errStream); } } _oneOffDone = true; } } if(_initData.logger == null) { string logfile = _initData.properties.getProperty("Ice.LogFile"); if(_initData.properties.getPropertyAsInt("Ice.UseSyslog") > 0) { if(logfile.Length != 0) { throw new Ice.InitializationException("Ice.LogFile and Ice.UseSyslog cannot both be set."); } _initData.logger = new Ice.SysLoggerI(_initData.properties.getProperty("Ice.ProgramName"), _initData.properties.getPropertyWithDefault("Ice.SyslogFacility", "LOG_USER")); } else if(logfile.Length != 0 || Ice.Util.getProcessLogger() is Ice.LoggerI) { // // Ice.ConsoleListener is enabled by default unless Ice.LogFile is set. // bool console = _initData.properties.getPropertyAsIntWithDefault("Ice.ConsoleListener", logfile.Length == 0 ? 1 : 0) > 0; _initData.logger = new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), logfile, console); } else { _initData.logger = Ice.Util.getProcessLogger(); } } _traceLevels = new TraceLevels(_initData.properties); _defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties); #if COMPACT _factoryAssemblies = _initData.properties.getPropertyAsList("Ice.FactoryAssemblies"); #endif { const int defaultMessageSizeMax = 1024; int num = _initData.properties.getPropertyAsIntWithDefault("Ice.MessageSizeMax", defaultMessageSizeMax); if(num < 1) { _messageSizeMax = defaultMessageSizeMax * 1024; // Ignore non-sensical values. } else if(num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } // // Client ACM enabled by default. Server ACM disabled by default. // _clientACM = _initData.properties.getPropertyAsIntWithDefault("Ice.ACM.Client", 60); _serverACM = _initData.properties.getPropertyAsInt("Ice.ACM.Server"); _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getProperty("Ice.ImplicitContext")); _routerManager = new RouterManager(); _locatorManager = new LocatorManager(_initData.properties); _referenceFactory = new ReferenceFactory(this, communicator); _proxyFactory = new ProxyFactory(this); bool ipv4 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool ipv6 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv6", 0) > 0; if(!ipv4 && !ipv6) { throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled."); } else if(ipv4 && ipv6) { _protocolSupport = Network.EnableBoth; } else if(ipv4) { _protocolSupport = Network.EnableIPv4; } else { _protocolSupport = Network.EnableIPv6; } _endpointFactoryManager = new EndpointFactoryManager(this); EndpointFactory tcpEndpointFactory = new TcpEndpointFactory(this); _endpointFactoryManager.add(tcpEndpointFactory); EndpointFactory udpEndpointFactory = new UdpEndpointFactory(this); _endpointFactoryManager.add(udpEndpointFactory); _pluginManager = new Ice.PluginManagerI(communicator); _outgoingConnectionFactory = new OutgoingConnectionFactory(this); _servantFactoryManager = new ObjectFactoryManager(); _objectAdapterFactory = new ObjectAdapterFactory(this, communicator); _retryQueue = new RetryQueue(this); string[] facetFilter = _initData.properties.getPropertyAsList("Ice.Admin.Facets"); if(facetFilter.Length > 0) { foreach(string s in facetFilter) { _adminFacetFilter.Add(s); } } _adminFacets.Add("Properties", new PropertiesAdminI(_initData.properties)); _adminFacets.Add("Process", new ProcessI(communicator)); } catch(Ice.LocalException) { destroy(); throw; } }