示例#1
0
        public ServiceManagerI(Ice.Communicator communicator, string[] args)
        {
            _communicator = communicator;
            _logger = _communicator.getLogger();

            Ice.Properties props = _communicator.getProperties();

            if(props.getProperty("Ice.Admin.Enabled").Length == 0)
            {
            _adminEnabled = props.getProperty("Ice.Admin.Endpoints").Length > 0;
            }
            else
            {
            _adminEnabled = props.getPropertyAsInt("Ice.Admin.Enabled") > 0;
            }

            if(_adminEnabled)
            {
            string[] facetFilter = props.getPropertyAsList("Ice.Admin.Facets");
            if(facetFilter.Length > 0)
            {
                _adminFacetFilter = new HashSet<string>(facetFilter);
            }
            else
            {
                _adminFacetFilter = new HashSet<string>();
            }
            }

            _argv = args;
            _traceServiceObserver = _communicator.getProperties().getPropertyAsInt("IceBox.Trace.ServiceObserver");
        }
示例#2
0
        /*
         * ~ServantManager()
         * {
         *  //
         *  // Don't check whether destroy() has been called. It might have
         *  // not been called if the associated object adapter was not
         *  // properly deactivated.
         *  //
         *  //lock(this)
         *  //{
         *      //IceUtil.Assert.FinalizerAssert(instance_ == null);
         *  //}
         * }
         */

        //
        // Only for use by Ice.ObjectAdapterI.
        //
        public void destroy()
        {
            Dictionary <string, Ice.ServantLocator> locatorMap = null;

            Ice.Logger logger = null;
            lock (this)
            {
                Debug.Assert(instance_ != null); // Must not be called after destruction.
                logger = instance_.initializationData().logger;
                _servantMapMap.Clear();

                locatorMap = new Dictionary <string, Ice.ServantLocator>(_locatorMap);
                _locatorMap.Clear();
                instance_ = null;
            }

            foreach (KeyValuePair <string, Ice.ServantLocator> p in locatorMap)
            {
                Ice.ServantLocator locator = p.Value;
                try
                {
                    locator.deactivate(p.Key);
                }
                catch (System.Exception ex)
                {
                    string s = "exception during locator deactivation:\n" + "object adapter: `"
                               + _adapterName + "'\n" + "locator category: `" + p.Key + "'\n" + ex;
                    logger.error(s);
                }
            }
        }
示例#3
0
 public ServiceManagerI(Ice.Communicator communicator, string[] args)
 {
     _communicator = communicator;
     _logger = _communicator.getLogger();
     _argv = args;
     _traceServiceObserver = _communicator.getProperties().getPropertyAsInt("IceBox.Trace.ServiceObserver");
 }
示例#4
0
 setLogger(Ice.Logger logger)
 {
     //
     // No locking, as it can only be called during plug-in loading
     //
     _initData.logger = logger;
 }
示例#5
0
 public ProtocolInstance(Instance instance, short type, string protocol, bool secure)
 {
     instance_ = instance;
     traceLevel_ = instance_.traceLevels().network;
     traceCategory_ = instance_.traceLevels().networkCat;
     logger_ = instance_.initializationData().logger;
     properties_ = instance_.initializationData().properties;
     type_ = type;
     protocol_ = protocol;
     secure_ = secure;
 }
示例#6
0
 public ProtocolInstance(Ice.Communicator communicator, short type, string protocol, bool secure)
 {
     instance_ = Util.getInstance(communicator);
     traceLevel_ = instance_.traceLevels().network;
     traceCategory_ = instance_.traceLevels().networkCat;
     logger_ = instance_.initializationData().logger;
     properties_ = instance_.initializationData().properties;
     type_ = type;
     protocol_ = protocol;
     secure_ = secure;
 }
示例#7
0
        internal bool addOrUpdateMap(Ice.Properties properties, string mapName, IMetricsMapFactory factory,
                                     Ice.Logger logger)
        {
            //
            // Add maps to views configured with the given map.
            //
            string viewPrefix = "IceMX.Metrics." + _name + ".";
            string mapsPrefix = viewPrefix + "Map.";
            Dictionary <string, string> mapsProps = properties.getPropertiesForPrefix(mapsPrefix);

            string mapPrefix;
            Dictionary <string, string> mapProps = new Dictionary <string, string>();

            if (mapsProps.Count > 0)
            {
                mapPrefix = mapsPrefix + mapName + ".";
                mapProps  = properties.getPropertiesForPrefix(mapPrefix);
                if (mapProps.Count == 0)
                {
                    // This map isn't configured for this view.
                    return(_maps.Remove(mapName));
                }
            }
            else
            {
                mapPrefix = viewPrefix;
                mapProps  = properties.getPropertiesForPrefix(mapPrefix);
            }

            if (properties.getPropertyAsInt(mapPrefix + "Disabled") > 0)
            {
                // This map is disabled for this view.
                return(_maps.Remove(mapName));
            }

            IMetricsMap m;

            if (_maps.TryGetValue(mapName, out m) &&
                IceUtilInternal.Collections.DictionaryEquals(m.getProperties(), mapProps))
            {
                return(false); // The map configuration didn't change, no need to re-create.
            }

            try
            {
                _maps[mapName] = factory.create(mapPrefix, properties);
            }
            catch (Exception ex)
            {
                logger.warning("unexpected exception while creating metrics map:\n" + ex);
                _maps.Remove(mapName);
            }
            return(true);
        }
示例#8
0
        internal AcceptorI(Instance instance, string adapterName, string host, int port)
        {
            _instance = instance;
            _adapterName = adapterName;
            _logger = instance.communicator().getLogger();
            _backlog = instance.communicator().getProperties().getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511);

            //
            // .NET requires that a certificate be supplied.
            //
            X509Certificate2Collection certs = instance.certs();
            if(certs.Count == 0)
            {
                Ice.SecurityException ex = new Ice.SecurityException();
                ex.reason = "IceSSL: certificate required for server endpoint";
                throw ex;
            }

            try
            {
                _addr = IceInternal.Network.getAddressForServer(host, port, _instance.protocolSupport());
                _fd = IceInternal.Network.createSocket(false, _addr.AddressFamily);
                IceInternal.Network.setBlock(_fd, false);
                IceInternal.Network.setTcpBufSize(_fd, _instance.communicator().getProperties(), _logger);
                if(IceInternal.AssemblyUtil.platform_ != IceInternal.AssemblyUtil.Platform.Windows)
                {
                    //
                    // Enable SO_REUSEADDR on Unix platforms to allow
                    // re-using the socket even if it's in the TIME_WAIT
                    // state. On Windows, this doesn't appear to be
                    // necessary and enabling SO_REUSEADDR would actually
                    // not be a good thing since it allows a second
                    // process to bind to an address even it's already
                    // bound by another process.
                    //
                    // TODO: using SO_EXCLUSIVEADDRUSE on Windows would
                    // probably be better but it's only supported by recent
                    // Windows versions (XP SP2, Windows Server 2003).
                    //
                    IceInternal.Network.setReuseAddress(_fd, true);
                }
                if(_instance.networkTraceLevel() >= 2)
                {
                    string s = "attempting to bind to ssl socket " + IceInternal.Network.addrToString(_addr);
                    _logger.trace(_instance.networkTraceCategory(), s);
                }
                _addr = IceInternal.Network.doBind(_fd, _addr);
            }
            catch(System.Exception)
            {
                _fd = null;
                throw;
            }
        }
示例#9
0
        public CollocatedRequestHandler(Reference @ref, Ice.ObjectAdapter adapter)
        {
            _reference = @ref;
            _dispatcher = _reference.getInstance().initializationData().dispatcher != null;
            _response = _reference.getMode() == Reference.Mode.ModeTwoway;
            _adapter = (Ice.ObjectAdapterI)adapter;

            _logger = _reference.getInstance().initializationData().logger; // Cached for better performance.
            _traceLevels = _reference.getInstance().traceLevels(); // Cached for better performance.
            _requestId = 0;
        }
示例#10
0
 internal LoggerAdminLoggerI(Ice.Communicator communicator, Ice.Logger localLogger)
 {
     if (localLogger is LoggerAdminLoggerI)
     {
         _localLogger = ((LoggerAdminLoggerI)localLogger).getLocalLogger();
     }
     else
     {
         _localLogger = localLogger;
     }
     _loggerAdmin = new LoggerAdminI(communicator, this);
 }
示例#11
0
        //
        // Only for use by TcpEndpoint
        //
        internal TcpConnector(Instance instance, IPEndPoint addr, int timeout, string connectionId)
        {
            _instance = instance;
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _addr = addr;
            _timeout = timeout;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _timeout;
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
示例#12
0
        //
        // Only for use by EndpointI.
        //
        internal ConnectorI(Instance instance, string host, IPEndPoint addr, int timeout, string connectionId)
        {
            _instance = instance;
            _host = host;
            _logger = instance.communicator().getLogger();
            _addr = addr;
            _timeout = timeout;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _timeout;
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
示例#13
0
        public ACMConfig(Ice.Properties p, Ice.Logger l, string prefix, ACMConfig dflt)
        {
            Debug.Assert(prefix != null);

            string timeoutProperty;

            if ((prefix.Equals("Ice.ACM.Client") || prefix.Equals("Ice.ACM.Server")) &&
                p.getProperty(prefix + ".Timeout").Length == 0)
            {
                timeoutProperty = prefix; // Deprecated property.
            }
            else
            {
                timeoutProperty = prefix + ".Timeout";
            }

            timeout = p.getPropertyAsIntWithDefault(timeoutProperty, dflt.timeout / 1000) * 1000; // To milliseconds
            if (timeout < 0)
            {
                l.warning("invalid value for property `" + timeoutProperty + "', default value will be used instead");
                timeout = dflt.timeout;
            }

            int hb = p.getPropertyAsIntWithDefault(prefix + ".Heartbeat", (int)dflt.heartbeat);

            if (hb >= (int)Ice.ACMHeartbeat.HeartbeatOff && hb <= (int)Ice.ACMHeartbeat.HeartbeatAlways)
            {
                heartbeat = (Ice.ACMHeartbeat)hb;
            }
            else
            {
                l.warning("invalid value for property `" + prefix + ".Heartbeat" +
                          "', default value will be used instead");
                heartbeat = dflt.heartbeat;
            }

            int cl = p.getPropertyAsIntWithDefault(prefix + ".Close", (int)dflt.close);

            if (cl >= (int)Ice.ACMClose.CloseOff && cl <= (int)Ice.ACMClose.CloseOnIdleForceful)
            {
                close = (Ice.ACMClose)cl;
            }
            else
            {
                l.warning("invalid value for property `" + prefix + ".Close" +
                          "', default value will be used instead");
                close = dflt.close;
            }
        }
示例#14
0
 internal void deadRemoteLogger(Ice.RemoteLoggerPrx remoteLogger, Ice.Logger logger, Ice.LocalException ex,
                                string operation)
 {
     //
     // No need to convert remoteLogger as we only use its identity
     //
     if (removeRemoteLogger(remoteLogger))
     {
         if (_traceLevel > 0)
         {
             logger.trace(_traceCategory, "detached `" + remoteLogger.ToString() + "' because "
                          + operation + " raised:\n" + ex.ToString());
         }
     }
 }
示例#15
0
        internal LoggerAdminLoggerI(Ice.Properties props, Ice.Logger localLogger)
        {
            LoggerAdminLoggerI wrapper = localLogger as LoggerAdminLoggerI;

            if (wrapper != null)
            {
                _localLogger = wrapper.getLocalLogger();
            }
            else
            {
                _localLogger = localLogger;
            }

            _loggerAdmin = new LoggerAdminI(props, this);
        }
示例#16
0
        internal LoggerAdminLoggerI(Ice.Properties props, Ice.Logger localLogger)
        {
            LoggerAdminLoggerI wrapper = localLogger as LoggerAdminLoggerI;

            if(wrapper != null)
            {
            _localLogger = wrapper.getLocalLogger();
            }
            else
            {
            _localLogger = localLogger;
            }

            _loggerAdmin = new LoggerAdminI(props, this);
        }
示例#17
0
        internal static void traceRecv(Ice.InputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    byte type = printMessage(s, str);

                    logger.trace(tl.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.ToString());
                }
                str.pos(p);
            }
        }
示例#18
0
        internal Instance(Ice.Communicator communicator)
        {
            _logger = communicator.getLogger();
            _facade = IceInternal.Util.getProtocolPluginFacade(communicator);
            _securityTraceLevel = communicator.getProperties().getPropertyAsIntWithDefault("IceSSL.Trace.Security", 0);
            _securityTraceCategory = "Security";
            _initialized = false;
            _trustManager = new TrustManager(communicator);

            //
            // Register the endpoint factory. We have to do this now, rather than
            // in initialize, because the communicator may need to interpret
            // proxies before the plug-in is fully initialized.
            //
            _facade.addEndpointFactory(new EndpointFactoryI(this));
        }
示例#19
0
        public ACMConfig(Ice.Communicator communicator, Ice.Logger logger, string prefix, ACMConfig defaults)
        {
            Debug.Assert(prefix != null);

            string timeoutProperty;

            if ((prefix == "Ice.ACM.Client" || prefix == "Ice.ACM.Server") &&
                communicator.GetProperty($"{prefix}.Timeout") == null)
            {
                timeoutProperty = prefix; // Deprecated property.
            }
            else
            {
                timeoutProperty = prefix + ".Timeout";
            }

            timeout = communicator.GetPropertyAsInt(timeoutProperty) * 1000 ?? defaults.timeout;
            if (timeout < 0)
            {
                logger.warning($"invalid value for property `{timeoutProperty}', default value will be used instead");
                timeout = defaults.timeout;
            }

            int hb = communicator.GetPropertyAsInt($"{prefix}.Heartbeat") ?? (int)defaults.heartbeat;

            if (hb >= (int)Ice.ACMHeartbeat.HeartbeatOff && hb <= (int)Ice.ACMHeartbeat.HeartbeatAlways)
            {
                heartbeat = (Ice.ACMHeartbeat)hb;
            }
            else
            {
                logger.warning($"invalid value for property `{prefix}.Heartbeat', default value will be used instead");
                heartbeat = defaults.heartbeat;
            }

            int cl = communicator.GetPropertyAsInt($"{prefix}.Close") ?? (int)defaults.close;

            if (cl >= (int)Ice.ACMClose.CloseOff && cl <= (int)Ice.ACMClose.CloseOnIdleForceful)
            {
                close = (Ice.ACMClose)cl;
            }
            else
            {
                logger.warning($"invalid value for property `{prefix}.Close', default value will be used instead");
                close = defaults.close;
            }
        }
示例#20
0
        internal static void trace(string heading, Ice.InputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    s.Write(heading);
                    printMessage(s, str);

                    logger.trace(tl.protocolCat, s.ToString());
                }
                str.pos(p);
            }
        }
示例#21
0
        internal static void traceSend(Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int             p   = str.pos();
                Ice.InputStream iss = new Ice.InputStream(str.instance(), str.getEncoding(), str.getBuffer(), false);
                iss.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    byte type = printMessage(s, iss);

                    logger.trace(tl.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.ToString());
                }
                str.pos(p);
            }
        }
示例#22
0
        internal TcpAcceptor(Instance instance, string host, int port)
        {
            instance_ = instance;
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _backlog = instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511);

            try
            {
                _addr = Network.getAddressForServer(host, port, instance_.protocolSupport());
                _fd = Network.createSocket(false, _addr.AddressFamily);
                Network.setBlock(_fd, false);
            #if !COMPACT
                Network.setTcpBufSize(_fd, instance_.initializationData().properties, _logger);
            #endif
                if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows)
                {
                    //
                    // Enable SO_REUSEADDR on Unix platforms to allow
                    // re-using the socket even if it's in the TIME_WAIT
                    // state. On Windows, this doesn't appear to be
                    // necessary and enabling SO_REUSEADDR would actually
                    // not be a good thing since it allows a second
                    // process to bind to an address even it's already
                    // bound by another process.
                    //
                    // TODO: using SO_EXCLUSIVEADDRUSE on Windows would
                    // probably be better but it's only supported by recent
                    // Windows versions (XP SP2, Windows Server 2003).
                    //
                    Network.setReuseAddress(_fd, true);
                }
                if(_traceLevels.network >= 2)
                {
                    string s = "attempting to bind to tcp socket " + Network.addrToString(_addr);
                    _logger.trace(_traceLevels.networkCat, s);
                }
                _addr = Network.doBind(_fd, _addr);
            }
            catch(System.Exception)
            {
                _fd = null;
                throw;
            }
        }
示例#23
0
        internal static void trace(string heading, Ice.OutputStream str, Ice.Logger logger, TraceLevels tl)
        {
            if (tl.protocol >= 1)
            {
                int             p   = str.pos();
                Ice.InputStream iss = new Ice.InputStream(str.instance(), str.getEncoding(), str.getBuffer(), false);
                iss.pos(0);

                using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    s.Write(heading);
                    printMessage(s, iss);

                    logger.trace(tl.protocolCat, s.ToString());
                }
                str.pos(p);
            }
        }
示例#24
0
 internal SSLEngine(IceInternal.ProtocolPluginFacade facade)
 {
     _communicator = facade.getCommunicator();
     _logger = _communicator.getLogger();
     _facade = facade;
     _securityTraceLevel = _communicator.getProperties().getPropertyAsIntWithDefault("IceSSL.Trace.Security", 0);
     _securityTraceCategory = "Security";
     _initialized = false;
     _trustManager = new TrustManager(_communicator);
     _tls12Support = false;
     try
     {
         Enum.Parse(typeof(System.Security.Authentication.SslProtocols), "Tls12");
         _tls12Support = true;
     }
     catch(Exception)
     {
     }
 }
示例#25
0
        /*
         * ~ServantManager()
         * {
         *  //
         *  // Don't check whether destroy() has been called. It might have
         *  // not been called if the associated object adapter was not
         *  // properly deactivated.
         *  //
         *  //lock(this)
         *  //{
         *      //IceUtil.Assert.FinalizerAssert(_instance == null);
         *  //}
         * }
         */

        //
        // Only for use by Ice.ObjectAdapterI.
        //
        public void destroy()
        {
            Dictionary <string, Ice.ServantLocator> locatorMap = null;

            Ice.Logger logger = null;
            lock (this)
            {
                //
                // If the ServantManager has already been destroyed, we're done.
                //
                if (_instance == null)
                {
                    return;
                }

                logger = _instance.initializationData().logger;

                _servantMapMap.Clear();

                _defaultServantMap.Clear();

                locatorMap = new Dictionary <string, Ice.ServantLocator>(_locatorMap);
                _locatorMap.Clear();

                _instance = null;
            }

            foreach (KeyValuePair <string, Ice.ServantLocator> p in locatorMap)
            {
                Ice.ServantLocator locator = p.Value;
                try
                {
                    locator.deactivate(p.Key);
                }
                catch (System.Exception ex)
                {
                    string s = "exception during locator deactivation:\n" + "object adapter: `"
                               + _adapterName + "'\n" + "locator category: `" + p.Key + "'\n" + ex;
                    logger.error(s);
                }
            }
        }
示例#26
0
        //
        // Only for use by TcpConnector, TcpAcceptor
        //
        internal TcpTransceiver(Instance instance, Socket fd, IPEndPoint addr, bool connected)
        {
            _fd = fd;
            _addr = addr;
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _stats = instance.initializationData().stats;
            _state = connected ? StateConnected : StateNeedConnect;
            _desc = connected ? Network.fdToString(_fd) : "<not connected>";

            _maxSendPacketSize = Network.getSendBufferSize(fd);
            if(_maxSendPacketSize < 512)
            {
                _maxSendPacketSize = 0;
            }

            _maxReceivePacketSize = Network.getRecvBufferSize(fd);
            if(_maxReceivePacketSize < 512)
            {
                _maxReceivePacketSize = 0;
            }
        }
示例#27
0
        //
        // Only for use by ConnectorI, AcceptorI.
        //
        internal TransceiverI(Instance instance, Socket fd, IPEndPoint addr, string host, bool connected,
                              string adapterName)
        {
            _instance = instance;
            _fd = fd;
            _addr = addr;
            _host = host;
            _adapterName = adapterName;
            _stream = null;
            _logger = instance.communicator().getLogger();
            _stats = instance.communicator().getStats();
            _desc = connected ? IceInternal.Network.fdToString(_fd) : "<not connected>";
            _state = connected ? StateNeedAuthenticate : StateNeedConnect;

            _maxSendPacketSize = IceInternal.Network.getSendBufferSize(fd);
            if(_maxSendPacketSize < 512)
            {
                _maxSendPacketSize = 0;
            }

            _maxReceivePacketSize = IceInternal.Network.getRecvBufferSize(fd);
            if(_maxReceivePacketSize < 512)
            {
                _maxReceivePacketSize = 0;
            }

            if(_adapterName != null)
            {
                //
                // Determine whether a certificate is required from the peer.
                //
                _verifyPeer =
                    _instance.communicator().getProperties().getPropertyAsIntWithDefault("IceSSL.VerifyPeer", 2);
            }
            else
            {
                _verifyPeer = 0;
            }
        }
示例#28
0
        //
        // Only for use by UdpConnector.
        //
        internal UdpTransceiver(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl)
        {
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _stats = instance.initializationData().stats;
            _addr = addr;
            _mcastInterface = mcastInterface;
            _mcastTtl = mcastTtl;
            _state = StateNeedConnect;
            _incoming = false;

            try
            {
                _fd = Network.createSocket(true, _addr.AddressFamily);
                setBufSize(instance);
                Network.setBlock(_fd, false);
            }
            catch(Ice.LocalException)
            {
                _fd = null;
                throw;
            }
        }
示例#29
0
 internal PropertiesAdminI(Ice.Properties properties, Ice.Logger logger)
 {
     _properties = properties;
     _logger     = logger;
 }
示例#30
0
        private static Ice.Communicator createSendLogCommunicator(Ice.Communicator communicator, Ice.Logger logger)
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.logger     = logger;
            initData.properties = Ice.Util.createProperties();

            Ice.Properties mainProps = communicator.getProperties();

            copyProperties("Ice.Default.Locator", mainProps, initData.properties);
            copyProperties("Ice.Plugin.IceSSL", mainProps, initData.properties);
            copyProperties("IceSSL.", mainProps, initData.properties);

            string[] extraProps = mainProps.getPropertyAsList("Ice.Admin.Logger.Properties");

            if (extraProps.Length > 0)
            {
                for (int i = 0; i < extraProps.Length; ++i)
                {
                    string p = extraProps[i];
                    if (!p.StartsWith("--"))
                    {
                        extraProps[i] = "--" + p;
                    }
                }
                initData.properties.parseCommandLineOptions("", extraProps);
            }
            return(Ice.Util.initialize(initData));
        }
示例#31
0
        public int checkRetryAfterException(Ice.LocalException ex, Reference @ref, bool sleep, ref int cnt)
        {
            TraceLevels traceLevels = instance_.traceLevels();

            Ice.Logger logger = instance_.initializationData().logger;

            //
            // We don't retry batch requests because the exception might have caused
            // the all the requests batched with the connection to be aborted and we
            // want the application to be notified.
            //
            if (@ref.getMode() == Reference.Mode.ModeBatchOneway || @ref.getMode() == Reference.Mode.ModeBatchDatagram)
            {
                throw ex;
            }

            Ice.ObjectNotExistException one = ex as Ice.ObjectNotExistException;
            if (one != null)
            {
                if (@ref.getRouterInfo() != null && one.operation.Equals("ice_add_proxy"))
                {
                    //
                    // If we have a router, an ObjectNotExistException with an
                    // operation name "ice_add_proxy" indicates to the client
                    // that the router isn't aware of the proxy (for example,
                    // because it was evicted by the router). In this case, we
                    // must *always* retry, so that the missing proxy is added
                    // to the router.
                    //

                    @ref.getRouterInfo().clearCache(@ref);

                    if (traceLevels.retry >= 1)
                    {
                        string s = "retrying operation call to add proxy to router\n" + ex;
                        logger.trace(traceLevels.retryCat, s);
                    }
                    return(0); // We must always retry, so we don't look at the retry count.
                }
                else if (@ref.isIndirect())
                {
                    //
                    // We retry ObjectNotExistException if the reference is
                    // indirect.
                    //

                    if (@ref.isWellKnown())
                    {
                        LocatorInfo li = @ref.getLocatorInfo();
                        if (li != null)
                        {
                            li.clearCache(@ref);
                        }
                    }
                }
                else
                {
                    //
                    // For all other cases, we don't retry ObjectNotExistException.
                    //
                    throw ex;
                }
            }
            else if (ex is Ice.RequestFailedException)
            {
                throw ex;
            }

            //
            // There is no point in retrying an operation that resulted in a
            // MarshalException. This must have been raised locally (because if
            // it happened in a server it would result in an UnknownLocalException
            // instead), which means there was a problem in this process that will
            // not change if we try again.
            //
            // The most likely cause for a MarshalException is exceeding the
            // maximum message size, which is represented by the subclass
            // MemoryLimitException. For example, a client can attempt to send a
            // message that exceeds the maximum memory size, or accumulate enough
            // batch requests without flushing that the maximum size is reached.
            //
            // This latter case is especially problematic, because if we were to
            // retry a batch request after a MarshalException, we would in fact
            // silently discard the accumulated requests and allow new batch
            // requests to accumulate. If the subsequent batched requests do not
            // exceed the maximum message size, it appears to the client that all
            // of the batched requests were accepted, when in reality only the
            // last few are actually sent.
            //
            if (ex is Ice.MarshalException)
            {
                throw ex;
            }

            ++cnt;
            Debug.Assert(cnt > 0);

            int interval;

            if (cnt == (_retryIntervals.Length + 1) && ex is Ice.CloseConnectionException)
            {
                //
                // A close connection exception is always retried at least once, even if the retry
                // limit is reached.
                //
                interval = 0;
            }
            else if (cnt > _retryIntervals.Length)
            {
                if (traceLevels.retry >= 1)
                {
                    string s = "cannot retry operation call because retry limit has been exceeded\n" + ex;
                    logger.trace(traceLevels.retryCat, s);
                }
                throw ex;
            }
            else
            {
                interval = _retryIntervals[cnt - 1];
            }

            if (traceLevels.retry >= 1)
            {
                string s = "retrying operation call";
                if (interval > 0)
                {
                    s += " in " + interval + "ms";
                }
                s += " because of exception\n" + ex;
                logger.trace(traceLevels.retryCat, s);
            }

            if (sleep && interval > 0)
            {
                //
                // Sleep before retrying.
                //
                System.Threading.Thread.Sleep(interval);
            }
            return(interval);
        }
示例#32
0
 public MetricsAdminI(Ice.Communicator communicator, Ice.Logger logger)
 {
     _logger       = logger;
     _communicator = communicator;
     updateViews();
 }
示例#33
0
        public int checkRetryAfterException(Ice.LocalException ex, Reference @ref, ref int cnt)
        {
            TraceLevels traceLevels = _instance.traceLevels();

            Ice.Logger logger = _instance.initializationData().logger;

            if (@ref.getMode() == Reference.Mode.ModeBatchOneway || @ref.getMode() == Reference.Mode.ModeBatchDatagram)
            {
                Debug.Assert(false); // batch no longer implemented anyway
                throw ex;
            }

            Ice.ObjectNotExistException one = ex as Ice.ObjectNotExistException;
            if (one != null)
            {
                if (@ref.getRouterInfo() != null && one.operation.Equals("ice_add_proxy"))
                {
                    //
                    // If we have a router, an ObjectNotExistException with an
                    // operation name "ice_add_proxy" indicates to the client
                    // that the router isn't aware of the proxy (for example,
                    // because it was evicted by the router). In this case, we
                    // must *always* retry, so that the missing proxy is added
                    // to the router.
                    //

                    @ref.getRouterInfo().clearCache(@ref);

                    if (traceLevels.retry >= 1)
                    {
                        string s = "retrying operation call to add proxy to router\n" + ex;
                        logger.trace(traceLevels.retryCat, s);
                    }
                    return(0); // We must always retry, so we don't look at the retry count.
                }
                else if (@ref.isIndirect())
                {
                    //
                    // We retry ObjectNotExistException if the reference is
                    // indirect.
                    //

                    if (@ref.isWellKnown())
                    {
                        LocatorInfo li = @ref.getLocatorInfo();
                        if (li != null)
                        {
                            li.clearCache(@ref);
                        }
                    }
                }
                else
                {
                    //
                    // For all other cases, we don't retry ObjectNotExistException.
                    //
                    throw ex;
                }
            }
            else if (ex is Ice.RequestFailedException)
            {
                throw ex;
            }

            //
            // There is no point in retrying an operation that resulted in a
            // MarshalException. This must have been raised locally (because if
            // it happened in a server it would result in an UnknownLocalException
            // instead), which means there was a problem in this process that will
            // not change if we try again.
            //
            if (ex is Ice.MarshalException)
            {
                throw ex;
            }

            //
            // Don't retry if the communicator is destroyed, object adapter is deactivated,
            // or connection is manually closed.
            //
            if (ex is Ice.CommunicatorDestroyedException ||
                ex is Ice.ObjectAdapterDeactivatedException ||
                ex is Ice.ConnectionManuallyClosedException)
            {
                throw ex;
            }

            //
            // Don't retry invocation timeouts.
            //
            if (ex is Ice.InvocationTimeoutException || ex is Ice.InvocationCanceledException)
            {
                throw ex;
            }

            ++cnt;
            Debug.Assert(cnt > 0);

            int interval;

            if (cnt == (_retryIntervals.Length + 1) && ex is Ice.CloseConnectionException)
            {
                //
                // A close connection exception is always retried at least once, even if the retry
                // limit is reached.
                //
                interval = 0;
            }
            else if (cnt > _retryIntervals.Length)
            {
                if (traceLevels.retry >= 1)
                {
                    string s = "cannot retry operation call because retry limit has been exceeded\n" + ex;
                    logger.trace(traceLevels.retryCat, s);
                }
                throw ex;
            }
            else
            {
                interval = _retryIntervals[cnt - 1];
            }

            if (traceLevels.retry >= 1)
            {
                string s = "retrying operation call";
                if (interval > 0)
                {
                    s += " in " + interval + "ms";
                }
                s += " because of exception\n" + ex;
                logger.trace(traceLevels.retryCat, s);
            }

            return(interval);
        }
示例#34
0
        internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger)
        {
            string val;

            defaultProtocol = properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");

            val = properties.getProperty("Ice.Default.Host");
            if (val.Length != 0)
            {
                defaultHost = val;
            }
            else
            {
                defaultHost = null;
            }

            val = properties.getProperty("Ice.Default.SourceAddress");
            if (val.Length > 0)
            {
                defaultSourceAddress = Network.getNumericAddress(val);
                if (defaultSourceAddress == null)
                {
                    throw new Ice.InitializationException("invalid IP address set for Ice.Default.SourceAddress: `" +
                                                          val + "'");
                }
            }
            else
            {
                defaultSourceAddress = null;
            }

            val = properties.getProperty("Ice.Override.Timeout");
            if (val.Length > 0)
            {
                overrideTimeout      = true;
                overrideTimeoutValue = properties.getPropertyAsInt("Ice.Override.Timeout");
                if (overrideTimeoutValue < 1 && overrideTimeoutValue != -1)
                {
                    overrideTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.Timeout `");
                    msg.Append(properties.getProperty("Ice.Override.Timeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideTimeout      = false;
                overrideTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.ConnectTimeout");
            if (val.Length > 0)
            {
                overrideConnectTimeout      = true;
                overrideConnectTimeoutValue = properties.getPropertyAsInt("Ice.Override.ConnectTimeout");
                if (overrideConnectTimeoutValue < 1 && overrideConnectTimeoutValue != -1)
                {
                    overrideConnectTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.ConnectTimeout `");
                    msg.Append(properties.getProperty("Ice.Override.ConnectTimeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideConnectTimeout      = false;
                overrideConnectTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.CloseTimeout");
            if (val.Length > 0)
            {
                overrideCloseTimeout      = true;
                overrideCloseTimeoutValue = properties.getPropertyAsInt("Ice.Override.CloseTimeout");
                if (overrideCloseTimeoutValue < 1 && overrideCloseTimeoutValue != -1)
                {
                    overrideCloseTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.CloseTimeout `");
                    msg.Append(properties.getProperty("Ice.Override.CloseTimeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideCloseTimeout      = false;
                overrideCloseTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.Compress");
            if (val.Length > 0)
            {
                overrideCompress      = true;
                overrideCompressValue = properties.getPropertyAsInt("Ice.Override.Compress") > 0;
                if (!BZip2.supported() && overrideCompressValue)
                {
                    string lib = AssemblyUtil.isWindows ? "bzip2.dll" : "libbz2.so.1";
                    Console.Error.WriteLine("warning: " + lib + " not found, Ice.Override.Compress ignored.");
                    overrideCompressValue = false;
                }
            }
            else
            {
                overrideCompress      = !BZip2.supported();
                overrideCompressValue = false;
            }

            val = properties.getProperty("Ice.Override.Secure");
            if (val.Length > 0)
            {
                overrideSecure      = true;
                overrideSecureValue = properties.getPropertyAsInt("Ice.Override.Secure") > 0;
            }
            else
            {
                overrideSecure      = false;
                overrideSecureValue = false;
            }

            defaultCollocationOptimization =
                properties.getPropertyAsIntWithDefault("Ice.Default.CollocationOptimized", 1) > 0;

            val = properties.getPropertyWithDefault("Ice.Default.EndpointSelection", "Random");
            if (val.Equals("Random"))
            {
                defaultEndpointSelection = Ice.EndpointSelectionType.Random;
            }
            else if (val.Equals("Ordered"))
            {
                defaultEndpointSelection = Ice.EndpointSelectionType.Ordered;
            }
            else
            {
                Ice.EndpointSelectionTypeParseException ex = new Ice.EndpointSelectionTypeParseException();
                ex.str = "illegal value `" + val + "'; expected `Random' or `Ordered'";
                throw ex;
            }

            defaultTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.Timeout", 60000);
            if (defaultTimeout < 1 && defaultTimeout != -1)
            {
                defaultTimeout = 60000;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.Timeout `");
                msg.Append(properties.getProperty("Ice.Default.Timeout"));
                msg.Append("': defaulting to 60000");
                logger.warning(msg.ToString());
            }

            defaultLocatorCacheTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.LocatorCacheTimeout", -1);
            if (defaultLocatorCacheTimeout < -1)
            {
                defaultLocatorCacheTimeout = -1;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.LocatorCacheTimeout `");
                msg.Append(properties.getProperty("Ice.Default.LocatorCacheTimeout"));
                msg.Append("': defaulting to -1");
                logger.warning(msg.ToString());
            }

            defaultInvocationTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.InvocationTimeout", -1);
            if (defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1 && defaultInvocationTimeout != -2)
            {
                defaultInvocationTimeout = -1;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.InvocationTimeout `");
                msg.Append(properties.getProperty("Ice.Default.InvocationTimeout"));
                msg.Append("': defaulting to -1");
                logger.warning(msg.ToString());
            }

            defaultPreferSecure = properties.getPropertyAsIntWithDefault("Ice.Default.PreferSecure", 0) > 0;

            val = properties.getPropertyWithDefault("Ice.Default.EncodingVersion",
                                                    Ice.Util.encodingVersionToString(Ice.Util.currentEncoding));
            defaultEncoding = Ice.Util.stringToEncodingVersion(val);
            Protocol.checkSupportedEncoding(defaultEncoding);

            bool slicedFormat = properties.getPropertyAsIntWithDefault("Ice.Default.SlicedFormat", 0) > 0;

            defaultFormat = slicedFormat ? Ice.FormatType.SlicedFormat : Ice.FormatType.CompactFormat;
        }
示例#35
0
 internal static void traceSlicing(string kind, string typeId, string slicingCat, Ice.Logger logger)
 {
     lock (typeof(TraceUtil))
     {
         if (slicingIds.Add(typeId))
         {
             using (System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
             {
                 s.Write("unknown " + kind + " type `" + typeId + "'");
                 logger.trace(slicingCat, s.ToString());
             }
         }
     }
 }
示例#36
0
        //
        // Only for use by UdpEndpoint.
        //
        internal UdpTransceiver(Instance instance, string host, int port, string mcastInterface, bool connect)
        {
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _stats = instance.initializationData().stats;
            _state = connect ? StateNeedConnect : StateNotConnected;
            _incoming = true;

            try
            {
                _addr = Network.getAddressForServer(host, port, instance.protocolSupport());
                _fd = Network.createSocket(true, _addr.AddressFamily);
                setBufSize(instance);
                Network.setBlock(_fd, false);
                if(_traceLevels.network >= 2)
                {
                    string s = "attempting to bind to udp socket " + Network.addrToString(_addr);
                    _logger.trace(_traceLevels.networkCat, s);
                }
                if(Network.isMulticast(_addr))
                {
                    Network.setReuseAddress(_fd, true);
                    _mcastAddr = _addr;
                    if(AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows)
                    {
                        //
                        // Windows does not allow binding to the mcast address itself
                        // so we bind to INADDR_ANY (0.0.0.0) instead. As a result,
                        // bi-directional connection won't work because the source
                        // address won't the multicast address and the client will
                        // therefore reject the datagram.
                        //
                        if(_addr.AddressFamily == AddressFamily.InterNetwork)
                        {
                            _addr = new IPEndPoint(IPAddress.Any, port);
                        }
                        else
                        {
                            _addr = new IPEndPoint(IPAddress.IPv6Any, port);
                        }
                    }
                    _addr = Network.doBind(_fd, _addr);
                    if(port == 0)
                    {
                        _mcastAddr.Port = _addr.Port;
                    }
                    Network.setMcastGroup(_fd, _mcastAddr.Address, mcastInterface);
                }
                else
                {
                    if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows)
                    {
                        //
                        // Enable SO_REUSEADDR on Unix platforms to allow
                        // re-using the socket even if it's in the TIME_WAIT
                        // state. On Windows, this doesn't appear to be
                        // necessary and enabling SO_REUSEADDR would actually
                        // not be a good thing since it allows a second
                        // process to bind to an address even it's already
                        // bound by another process.
                        //
                        // TODO: using SO_EXCLUSIVEADDRUSE on Windows would
                        // probably be better but it's only supported by recent
                        // Windows versions (XP SP2, Windows Server 2003).
                        //
                        Network.setReuseAddress(_fd, true);
                    }
                    _addr = Network.doBind(_fd, _addr);
                }

                if(_traceLevels.network >= 1)
                {
                    StringBuilder s = new StringBuilder("starting to receive udp packets\n");
            s.Append(ToString());

                    List<string> interfaces =
                        Network.getHostsForEndpointExpand(_addr.Address.ToString(), instance.protocolSupport(), true);
                    if(interfaces.Count != 0)
                    {
                        s.Append("\nlocal interfaces: ");
                        s.Append(String.Join(", ", interfaces.ToArray()));
                    }
                    _logger.trace(_traceLevels.networkCat, s.ToString());
                }
            }
            catch(Ice.LocalException)
            {
                _fd = null;
                throw;
            }
        }
示例#37
0
 internal PropertiesAdminI(IceInternal.Instance instance)
 {
     _properties = instance.initializationData().properties;
     _logger = instance.initializationData().logger;
 }
示例#38
0
 public MetricsAdminI(Ice.Properties properties, Ice.Logger logger)
 {
     _logger     = logger;
     _properties = properties;
     updateViews();
 }
示例#39
0
 public PropertiesAdminI(string name, Ice.Properties properties, Ice.Logger logger)
 {
     _name       = name;
     _properties = properties;
     _logger     = logger;
 }