コード例 #1
0
        public CommunicatorObserverI(Communicator communicator, ILogger logger)
        {
            _metrics     = new MetricsAdminI(communicator, logger);
            _delegate    = communicator.Observer;
            _connections = new ObserverFactoryWithDelegate <ConnectionMetrics, ConnectionObserverI,
                                                            IConnectionObserver>(_metrics, "Connection");
            _dispatch = new ObserverFactoryWithDelegate <DispatchMetrics, DispatchObserverI,
                                                         IDispatchObserver>(_metrics, "Dispatch");
            _invocations = new ObserverFactoryWithDelegate <InvocationMetrics, InvocationObserverI,
                                                            IInvocationObserver>(_metrics, "Invocation");
            _threads = new ObserverFactoryWithDelegate <ThreadMetrics, ThreadObserverI,
                                                        IThreadObserver>(_metrics, "Thread");
            _connects = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                         IObserver>(_metrics, "ConnectionEstablishment");
            _endpointLookups = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                                IObserver>(_metrics, "EndpointLookup");

            try
            {
                Type cl = typeof(InvocationMetrics);
                _invocations.RegisterSubMap <RemoteMetrics>("Remote", cl.GetField("Remotes") !);
                _invocations.RegisterSubMap <CollocatedMetrics>("Collocated", cl.GetField("Collocated") !);
            }
            catch (Exception)
            {
                Debug.Assert(false);
            }
        }
コード例 #2
0
ファイル: Instance.cs プロジェクト: sbesson/zeroc-ice
        //
        // 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);
                }
            }
コード例 #3
0
ファイル: MetricsAdminI.cs プロジェクト: nail-lian/ice
        internal MetricsMap(string mapPrefix, Communicator communicator, Dictionary <string, ISubMapFactory>?subMaps)
        {
            MetricsAdminI.ValidateProperties(mapPrefix, communicator);
            _properties = communicator.GetProperties(forPrefix: mapPrefix);

            _retain            = communicator.GetPropertyAsInt($"{mapPrefix}RetainDetached") ?? 10;
            _accept            = ParseRule(communicator, $"{mapPrefix}Accept");
            _reject            = ParseRule(communicator, $"{mapPrefix}Reject");
            _groupByAttributes = new List <string>();
            _groupBySeparators = new List <string>();

            string groupBy = communicator.GetProperty($"{mapPrefix}GroupBy") ?? "id";

            if (groupBy.Length > 0)
            {
                string v         = "";
                bool   attribute = char.IsLetter(groupBy[0]) || char.IsDigit(groupBy[0]);
                if (!attribute)
                {
                    _groupByAttributes.Add("");
                }

                foreach (char p in groupBy)
                {
                    bool isAlphaNum = char.IsLetter(p) || char.IsDigit(p) || p == '.';
                    if (attribute && !isAlphaNum)
                    {
                        _groupByAttributes.Add(v);
                        v         = "" + p;
                        attribute = false;
                    }
                    else if (!attribute && isAlphaNum)
                    {
                        _groupBySeparators.Add(v);
                        v         = "" + p;
                        attribute = true;
                    }
                    else
                    {
                        v += p;
                    }
                }

                if (attribute)
                {
                    _groupByAttributes.Add(v);
                }
                else
                {
                    _groupBySeparators.Add(v);
                }
            }

            if (subMaps != null && subMaps.Count > 0)
            {
                _subMaps = new Dictionary <string, ISubMapCloneFactory>();

                var subMapNames = new List <string>();
                foreach (KeyValuePair <string, ISubMapFactory> e in subMaps)
                {
                    subMapNames.Add(e.Key);
                    string subAllMapsPrefix = mapPrefix + "Map.";
                    string subMapPrefix     = subAllMapsPrefix + e.Key + '.';
                    if (communicator.GetProperties(forPrefix: subMapPrefix).Count == 0)
                    {
                        if (communicator.GetProperties(forPrefix: subAllMapsPrefix).Count == 0)
                        {
                            subMapPrefix = mapPrefix;
                        }
                        else
                        {
                            continue; // This sub-map isn't configured.
                        }
                    }

                    _subMaps.Add(e.Key, e.Value.CreateCloneFactory(subMapPrefix, communicator));
                }
            }
            else
            {
                _subMaps = null;
            }
        }
コード例 #4
0
ファイル: MetricsObserverI.cs プロジェクト: yuwenyong/ice
 public ObserverFactory(MetricsAdminI metrics, string name)
 {
     _metrics = metrics;
     _name    = name;
     _metrics.RegisterMap <T>(name, Update);
 }
コード例 #5
0
 public ObserverFactoryWithDelegate(MetricsAdminI metrics, string name)
     : base(metrics, name)
 {
 }