Example #1
0
 //
 // Only for use by Instance.
 //
 internal ObjectAdapterFactory(Instance instance, Ice.Communicator communicator)
 {
     instance_ = instance;
     _communicator = communicator;
     _adapterNamesInUse = new HashSet<string>();
     _adapters = new List<Ice.ObjectAdapterI>();
 }
Example #2
0
 //
 // Only for use by Instance.
 //
 internal ConnectionMonitor(Instance instance, int interval)
 {
     instance_ = instance;
     _interval = interval;
     _scheduledInterval = 0;
     _connections = new HashSet<Ice.ConnectionI>();
 }
Example #3
0
 public TcpEndpointI(Instance instance, string ho, int po, int ti, string conId, bool co) : base(conId)
 {
     _instance = instance;
     _host = ho;
     _port = po;
     _timeout = ti;
     _compress = co;
     calcHashValue();
 }
Example #4
0
 public ProtocolInstance(Instance instance, short type, string protocol)
 {
     instance_ = instance;
     traceLevel_ = instance_.traceLevels().network;
     traceCategory_ = instance_.traceLevels().networkCat;
     logger_ = instance_.initializationData().logger;
     properties_ = instance_.initializationData().properties;
     type_ = type;
     protocol_ = protocol;
 }
Example #5
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;
 }
Example #6
0
 public FixedReference(Instance instance,
                       Ice.Communicator communicator,
                       Ice.Identity identity,
                       string facet,
                       Reference.Mode mode,
                       bool secure,
                       Ice.ConnectionI connection)
     : base(instance, communicator, identity, facet, mode, secure)
 {
     _fixedConnection = connection;
 }
Example #7
0
 public UdpEndpointI(Instance instance, string ho, int po, string mif, int mttl, bool conn, string conId, 
                     bool co) : base(conId)
 {
     instance_ = instance;
     _host = ho;
     _port = po;
     _mcastInterface = mif;
     _mcastTtl = mttl;
     _connect = conn;
     connectionId_ = conId;
     _compress = co;
     calcHashValue();
 }
Example #8
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();
        }
Example #9
0
 static public InvocationObserver get(Instance instance, string op)
 {
     CommunicatorObserver obsv = instance.initializationData().observer;
     if(obsv != null)
     {
         InvocationObserver observer = obsv.getInvocationObserver(null, op, _emptyContext);
         if(observer != null)
         {
             observer.attach();
         }
         return observer;
     }
     return null;
 }
Example #10
0
        //
        // Only for use by TcpEndpoint
        //
        internal UdpConnector(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl, string connectionId)
        {
            instance_ = instance;
            _addr = addr;
            _mcastInterface = mcastInterface;
            _mcastTtl = mcastTtl;
            _connectionId = connectionId;

            _hashCode = 5381;
            IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _mcastInterface);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _mcastTtl);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
        }
Example #11
0
        //
        // Only for use by TcpEndpoint
        //
        internal TcpConnector(Instance instance, EndPoint addr, NetworkProxy proxy, int timeout, string connectionId)
        {
            _instance = instance;
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _addr = addr;
            _proxy = proxy;
            _timeout = timeout;
            _connectionId = connectionId;

            _hashCode = 5381;
            IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout);
            IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
        }
Example #12
0
        internal AsyncIOThread(Instance instance)
        {
            _instance = instance;

            _thread = new HelperThread(this);
            if(instance.initializationData().properties.getProperty("Ice.ThreadPriority").Length > 0)
            {
                ThreadPriority priority = IceInternal.Util.stringToThreadPriority(
                                           instance.initializationData().properties.getProperty("Ice.ThreadPriority"));
                _thread.Start(priority);
            }
            else
            {
                _thread.Start(ThreadPriority.Normal);
            }
        }
Example #13
0
        public Incoming(Instance instance, ResponseHandler handler, Ice.ConnectionI connection,
            Ice.ObjectAdapter adapter, bool response, byte compress, int requestId)
            : base(instance, handler, connection, adapter, response, compress, requestId)
        {
            //
            // Prepare the response if necessary.
            //
            if(response)
            {
                os_.writeBlob(IceInternal.Protocol.replyHdr);

                //
                // Add the request ID.
                //
                os_.writeInt(requestId);
            }
        }
Example #14
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;
            }
        }
Example #15
0
 internal EndpointHostResolver(Instance instance)
 {
     _instance = instance;
     _protocol = instance.protocolSupport();
     _preferIPv6 = instance.preferIPv6();
     _thread = new HelperThread(this);
     updateObserver();
     if(instance.initializationData().properties.getProperty("Ice.ThreadPriority").Length > 0)
     {
         ThreadPriority priority = IceInternal.Util.stringToThreadPriority(
             instance.initializationData().properties.getProperty("Ice.ThreadPriority"));
         _thread.Start(priority);
     }
     else
     {
         _thread.Start(ThreadPriority.Normal);
     }
 }
Example #16
0
        //
        // Only for use by TcpEndpoint
        //
        internal UdpConnector(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl,
                              byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor,
                              string connectionId)
        {
            instance_ = instance;
            _addr = addr;
            _mcastInterface = mcastInterface;
            _mcastTtl = mcastTtl;
            _protocolMajor = protocolMajor;
            _protocolMinor = protocolMinor;
            _encodingMajor = encodingMajor;
            _encodingMinor = encodingMinor;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _mcastInterface.GetHashCode();
            _hashCode = 5 * _hashCode + _mcastTtl.GetHashCode();
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
Example #17
0
        protected internal IncomingBase(Instance instance, ResponseHandler handler, Ice.ConnectionI connection, 
                                        Ice.ObjectAdapter adapter, bool response, byte compress, int requestId)
        {
            instance_ = instance;
            responseHandler_ = handler;
            response_ = response;
            compress_ = compress;
            if(response_)
            {
                os_ = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
            }

            current_ = new Ice.Current();
            current_.id = new Ice.Identity();
            current_.adapter = adapter;
            current_.con = connection;
            current_.requestId = requestId;

            cookie_ = null;
        }
Example #18
0
        //
        // Only for use by Instance
        //
        internal ProxyFactory(Instance instance)
        {
            instance_ = instance;

            string[] arr = instance_.initializationData().properties.getPropertyAsList("Ice.RetryIntervals");

            if(arr.Length > 0)
            {
                _retryIntervals = new int[arr.Length];

                for (int i = 0; i < arr.Length; i++)
                {
                    int v;

                    try
                    {
                        v = System.Int32.Parse(arr[i], CultureInfo.InvariantCulture);
                    }
                    catch(System.FormatException)
                    {
                        v = 0;
                    }

                    //
                    // If -1 is the first value, no retry and wait intervals.
                    //
                    if(i == 0 && v == -1)
                    {
                        _retryIntervals = new int[0];
                        break;
                    }

                    _retryIntervals[i] = v > 0?v:0;
                }
            }
            else
            {
                _retryIntervals = new int[1];
                _retryIntervals[0] = 0;
            }
        }
Example #19
0
        internal AsyncIOThread(Instance instance)
        {
            _instance = instance;

            _thread = new HelperThread(this);
            updateObserver();
#if !SILVERLIGHT
            if(instance.initializationData().properties.getProperty("Ice.ThreadPriority").Length > 0)
            {
                ThreadPriority priority = IceInternal.Util.stringToThreadPriority(
                                           instance.initializationData().properties.getProperty("Ice.ThreadPriority"));
                _thread.Start(priority);
            }
            else
            {
                _thread.Start(ThreadPriority.Normal);
            }
#else
            _thread.Start();
#endif
        }
Example #20
0
        public BatchRequestQueue(Instance instance, bool datagram)
        {
            Ice.InitializationData initData = instance.initializationData();
            _interceptor = initData.batchRequestInterceptor;
            _batchStreamInUse = false;
            _batchRequestNum = 0;
            _batchStream = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
            _batchStream.writeBlob(Protocol.requestBatchHdr);
            _batchMarker = _batchStream.size();
            _request = new BatchRequestI(this);

            _maxSize = instance.batchAutoFlushSize();
            if(_maxSize > 0 && datagram)
            {
                int udpSndSize = initData.properties.getPropertyAsIntWithDefault("Ice.UDP.SndSize",
                                                                                 65535 - _udpOverhead);
                if(udpSndSize < _maxSize)
                {
                    _maxSize = udpSndSize;
                }
            }
        }
Example #21
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;
            }
        }
Example #22
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;
            }
        }
Example #23
0
 public void destroy()
 {
     lock(this)
     {
         Dictionary<RetryTask, object> keep = new Dictionary<RetryTask, object>();
         foreach(RetryTask task in _requests.Keys)
         {
             if(_instance.timer().cancel(task))
             {
                 task.destroy();
             }
             else
             {
                 keep.Add(task, null);
             }
         }
         _requests = keep;
         _instance = null;
         while(_requests.Count > 0)
         {
             System.Threading.Monitor.Wait(this);
         }
     }
 }
Example #24
0
 public BatchOutgoing(Ice.ConnectionI connection, Instance instance, InvocationObserver observer)
 {
     _connection = connection;
     _sent = false;
     _observer = observer;
     _os = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
 }
Example #25
0
 internal FactoryACMMonitor(Instance instance, ACMConfig config)
 {
     _instance = instance;
     _config = config;
 }
Example #26
0
        public static Type findType(Instance instance, string csharpId)
        {
            lock(_mutex)
            {
                Type t;
                if (_typeTable.TryGetValue(csharpId, out t))
                {
                    return t;
                }
#if COMPACT || SILVERLIGHT
                string[] assemblies = instance.factoryAssemblies();
                for(int i = 0; i < assemblies.Length; ++i)
                {
                    string s = csharpId + "," + assemblies[i];
                    if((t = Type.GetType(s)) != null)
                    {
                        _typeTable[csharpId] = t;
                        return t;
                    }
                }
                //
                // As a last resort, look for the type in the standard Ice assemblies.
                // This avoids the need for a program to set a property such as:
                //
                // Ice.FactoryAssemblies=Ice
                //
                foreach(string a in _iceAssemblies)
                {
                    string s = csharpId + "," + a;
                    if((t = Type.GetType(s)) != null)
                    {
                        _typeTable[csharpId] = t;
                        return t;
                    }
                }
#else
                loadAssemblies(); // Lazy initialization
                foreach (Assembly a in _loadedAssemblies.Values)
                {
                    if((t = a.GetType(csharpId)) != null)
                    {
                        _typeTable[csharpId] = t;
                        return t;
                    }
                }
#endif
            }
            return null;
        }
Example #27
0
        //
        // Only for use by TcpConnector, TcpAcceptor
        //
        internal TcpTransceiver(Instance instance, Socket fd, EndPoint 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>";
            
#if ICE_SOCKET_ASYNC_API
            _readEventArgs = new SocketAsyncEventArgs();
            _readEventArgs.RemoteEndPoint = _addr;
            _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);

            _writeEventArgs = new SocketAsyncEventArgs();
            _writeEventArgs.RemoteEndPoint = _addr;
            _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
#if SILVERLIGHT
            String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol");
            if(policy.Equals("Http"))
            {
                _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
                _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
            }
            else if(!String.IsNullOrEmpty(policy))
            {
                _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'");
            }
#endif
#endif

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

            _maxReceivePacketSize = Network.getRecvBufferSize(fd);
            if(_maxReceivePacketSize < 512)
            {
                _maxReceivePacketSize = 0;
            }
        }
Example #28
0
File: Timer.cs Project: externl/ice
        public void destroy()
        {
            lock(this)
            {
                if(_instance == null)
                {
                    return;
                }

                _instance = null;
                System.Threading.Monitor.Pulse(this);

                _tokens.Clear();
                _tasks.Clear();
            }

            _thread.Join();
        }
Example #29
0
 internal CommunicatorI(InitializationData initData)
 {
     instance_ = new IceInternal.Instance(this, initData);
 }
Example #30
0
        public ThreadPool(Instance instance, string prefix, int timeout)
        {
            Ice.Properties properties = instance.initializationData().properties;

            _instance = instance;
            _dispatcher = instance.initializationData().dispatcher;
            _destroyed = false;
            _prefix = prefix;
            _threadIndex = 0;
            _inUse = 0;
            _serialize = properties.getPropertyAsInt(_prefix + ".Serialize") > 0;
            _serverIdleTime = timeout;

            string programName = properties.getProperty("Ice.ProgramName");
            if(programName.Length > 0)
            {
                _threadPrefix = programName + "-" + _prefix;
            }
            else
            {
                _threadPrefix = _prefix;
            }

            //
            // We use just one thread as the default. This is the fastest
            // possible setting, still allows one level of nesting, and
            // doesn't require to make the servants thread safe.
            //
            int size = properties.getPropertyAsIntWithDefault(_prefix + ".Size", 1);
            if(size < 1)
            {
                string s = _prefix + ".Size < 1; Size adjusted to 1";
                _instance.initializationData().logger.warning(s);
                size = 1;
            }

            int sizeMax = properties.getPropertyAsIntWithDefault(_prefix + ".SizeMax", size);
            if(sizeMax < size)
            {
                string s = _prefix + ".SizeMax < " + _prefix + ".Size; SizeMax adjusted to Size (" + size + ")";
                _instance.initializationData().logger.warning(s);
                sizeMax = size;
            }

            int sizeWarn = properties.getPropertyAsInt(_prefix + ".SizeWarn");
            if(sizeWarn != 0 && sizeWarn < size)
            {
                string s = _prefix + ".SizeWarn < " + _prefix + ".Size; adjusted SizeWarn to Size (" + size + ")";
                _instance.initializationData().logger.warning(s);
                sizeWarn = size;
            }
            else if(sizeWarn > sizeMax)
            {
                string s = _prefix + ".SizeWarn > " + _prefix + ".SizeMax; adjusted SizeWarn to SizeMax ("
                    + sizeMax + ")";
                _instance.initializationData().logger.warning(s);
                sizeWarn = sizeMax;
            }

            int threadIdleTime = properties.getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60);
            if(threadIdleTime < 0)
            {
                string s = _prefix + ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0";
                _instance.initializationData().logger.warning(s);
                threadIdleTime = 0;
            }

            _size = size;
            _sizeMax = sizeMax;
            _sizeWarn = sizeWarn;
            _threadIdleTime = threadIdleTime;

            int stackSize = properties.getPropertyAsInt(_prefix + ".StackSize");
            if(stackSize < 0)
            {
                string s = _prefix + ".StackSize < 0; Size adjusted to OS default";
                _instance.initializationData().logger.warning(s);
                stackSize = 0;
            }
            _stackSize = stackSize;
            _hasPriority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0;
            _priority = IceInternal.Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority"));
            if(!_hasPriority)
            {
                _hasPriority = properties.getProperty("Ice.ThreadPriority").Length > 0;
                _priority = IceInternal.Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority"));
            }

            if(_instance.traceLevels().threadPool >= 1)
            {
                string s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " +
                           _sizeWarn;
                _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s);
            }

            _workItems = new Queue<ThreadPoolWorkItem>();

            try
            {
                _threads = new List<WorkerThread>();
                for(int i = 0; i < _size; ++i)
                {
                    WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
                    if(_hasPriority)
                    {
                        thread.start(_priority);
                    }
                    else
                    {
                        thread.start(ThreadPriority.Normal);
                    }
                    _threads.Add(thread);
                }
            }
            catch(System.Exception ex)
            {
                string s = "cannot create thread for `" + _prefix + "':\n" + ex;
                _instance.initializationData().logger.error(s);

                destroy();
                joinWithAllThreads();
                throw;
            }
        }
Example #31
0
 public ObserverUpdaterI(Instance instance)
 {
     _instance = instance;
 }
Example #32
0
        private void getEndpointsException(Reference @ref, System.Exception exc)
        {
            try
            {
                throw exc;
            }
            catch (Ice.AdapterNotFoundException ex)
            {
                Instance instance = @ref.getInstance();
                if (instance.traceLevels().location >= 1)
                {
                    System.Text.StringBuilder s = new System.Text.StringBuilder();
                    s.Append("adapter not found\n");
                    s.Append("adapter = " + @ref.getAdapterId());
                    instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString());
                }

                Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex);
                e.kindOfObject = "object adapter";
                e.id           = @ref.getAdapterId();
                throw e;
            }
            catch (Ice.ObjectNotFoundException ex)
            {
                Instance instance = @ref.getInstance();
                if (instance.traceLevels().location >= 1)
                {
                    System.Text.StringBuilder s = new System.Text.StringBuilder();
                    s.Append("object not found\n");
                    s.Append("object = " + Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode()));
                    instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString());
                }

                Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex);
                e.kindOfObject = "object";
                e.id           = Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode());
                throw e;
            }
            catch (Ice.NotRegisteredException)
            {
                throw;
            }
            catch (Ice.LocalException ex)
            {
                Instance instance = @ref.getInstance();
                if (instance.traceLevels().location >= 1)
                {
                    System.Text.StringBuilder s = new System.Text.StringBuilder();
                    s.Append("couldn't contact the locator to retrieve endpoints\n");
                    if (@ref.getAdapterId().Length > 0)
                    {
                        s.Append("adapter = " + @ref.getAdapterId() + "\n");
                    }
                    else
                    {
                        s.Append("well-known proxy = " + @ref.ToString() + "\n");
                    }
                    s.Append("reason = " + ex);
                    instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString());
                }
                throw;
            }
            catch (System.Exception)
            {
                Debug.Assert(false);
            }
        }