Exemplo n.º 1
0
        public CommunicatorObserverI(IceInternal.MetricsAdminI metrics,
                                     Ice.Instrumentation.CommunicatorObserver del)
        {
            _metrics     = metrics;
            _delegate    = del;
            _connections = new ObserverFactoryWithDelegate <ConnectionMetrics, ConnectionObserverI,
                                                            Ice.Instrumentation.ConnectionObserver>(metrics, "Connection");
            _dispatch = new ObserverFactoryWithDelegate <DispatchMetrics, DispatchObserverI,
                                                         Ice.Instrumentation.DispatchObserver>(metrics, "Dispatch");
            _invocations = new ObserverFactoryWithDelegate <InvocationMetrics, InvocationObserverI,
                                                            Ice.Instrumentation.InvocationObserver>(metrics, "Invocation");
            _threads = new ObserverFactoryWithDelegate <ThreadMetrics, ThreadObserverI,
                                                        Ice.Instrumentation.ThreadObserver>(metrics, "Thread");
            _connects = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                         Ice.Instrumentation.Observer>(metrics, "ConnectionEstablishment");
            _endpointLookups = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegateI,
                                                                Ice.Instrumentation.Observer>(metrics, "EndpointLookup");

            try
            {
                _invocations.registerSubMap <RemoteMetrics>("Remote", typeof(InvocationMetrics).GetField("remotes"));
            }
            catch (Exception)
            {
                Debug.Assert(false);
            }
        }
Exemplo n.º 2
0
        public List <Connector> resolve(string host, int port, Ice.EndpointSelectionType selType, EndpointI endpoint)
        {
            //
            // Try to get the addresses without DNS lookup. If this doesn't
            // work, we retry with DNS lookup (and observer).
            //
            NetworkProxy networkProxy = _instance.networkProxy();

            if (networkProxy == null)
            {
                List <EndPoint> addrs = Network.getAddresses(host, port, _protocol, selType, _preferIPv6, false);
                if (addrs.Count > 0)
                {
                    return(endpoint.connectors(addrs, null));
                }
            }

            Ice.Instrumentation.CommunicatorObserver obsv     = _instance.getObserver();
            Ice.Instrumentation.Observer             observer = null;
            if (obsv != null)
            {
                observer = obsv.getEndpointLookupObserver(endpoint);
                if (observer != null)
                {
                    observer.attach();
                }
            }

            List <Connector> connectors = null;

            try
            {
                if (networkProxy != null)
                {
                    networkProxy = networkProxy.resolveHost();
                }

                connectors = endpoint.connectors(Network.getAddresses(host, port, _protocol, selType, _preferIPv6,
                                                                      true),
                                                 networkProxy);
            }
            catch (Ice.LocalException ex)
            {
                if (observer != null)
                {
                    observer.failed(ex.ice_name());
                }
                throw ex;
            }
            finally
            {
                if (observer != null)
                {
                    observer.detach();
                }
            }
            return(connectors);
        }
Exemplo n.º 3
0
        public void resolve(string host, int port, Ice.EndpointSelectionType selType, EndpointI endpoint,
                            EndpointI_connectors callback)
        {
            //
            // Try to get the addresses without DNS lookup. If this doesn't work, we queue a resolve
            // entry and the thread will take care of getting the endpoint addresses.
            //
            NetworkProxy networkProxy = _instance.networkProxy();

            if (networkProxy == null)
            {
                try
                {
                    List <EndPoint> addrs = Network.getAddresses(host, port, _protocol, selType, _preferIPv6, false);
                    if (addrs.Count > 0)
                    {
                        callback.connectors(endpoint.connectors(addrs, null));
                        return;
                    }
                }
                catch (Ice.LocalException ex)
                {
                    callback.exception(ex);
                    return;
                }
            }

            _m.Lock();
            try
            {
                Debug.Assert(!_destroyed);

                ResolveEntry entry = new ResolveEntry();
                entry.host     = host;
                entry.port     = port;
                entry.selType  = selType;
                entry.endpoint = endpoint;
                entry.callback = callback;

                Ice.Instrumentation.CommunicatorObserver obsv = _instance.getObserver();
                if (obsv != null)
                {
                    entry.observer = obsv.getEndpointLookupObserver(endpoint);
                    if (entry.observer != null)
                    {
                        entry.observer.attach();
                    }
                }

                _queue.AddLast(entry);
                _m.Notify();
            }
            finally
            {
                _m.Unlock();
            }
        }
Exemplo n.º 4
0
 public void updateObserver()
 {
     // Must be called with the thread pool mutex locked
     Ice.Instrumentation.CommunicatorObserver obsv = _threadPool._instance.initializationData().observer;
     if (obsv != null)
     {
         _observer = obsv.getThreadObserver(_threadPool._prefix, _name, _state, _observer);
         if (_observer != null)
         {
             _observer.attach();
         }
     }
 }
Exemplo n.º 5
0
 internal void updateObserver(Ice.Instrumentation.CommunicatorObserver obsv)
 {
     lock (this)
     {
         Debug.Assert(obsv != null);
         _observer = obsv.getThreadObserver("Communicator",
                                            _thread.Name,
                                            Ice.Instrumentation.ThreadState.ThreadStateIdle,
                                            _observer);
         if (_observer != null)
         {
             _observer.attach();
         }
     }
 }
Exemplo n.º 6
0
 updateObserver()
 {
     lock (this)
     {
         Ice.Instrumentation.CommunicatorObserver obsv = _instance.initializationData().observer;
         if (obsv != null)
         {
             _observer = obsv.getThreadObserver("Communicator",
                                                _thread.getName(),
                                                Ice.Instrumentation.ThreadState.ThreadStateIdle,
                                                _observer);
             if (_observer != null)
             {
                 _observer.attach();
             }
         }
     }
 }
Exemplo n.º 7
0
 updateObserver()
 {
     _m.Lock();
     try
     {
         Ice.Instrumentation.CommunicatorObserver obsv = _instance.getObserver();
         if (obsv != null)
         {
             _observer = obsv.getThreadObserver("Communicator",
                                                _thread.getName(),
                                                Ice.Instrumentation.ThreadState.ThreadStateIdle,
                                                _observer);
             if (_observer != null)
             {
                 _observer.attach();
             }
         }
     }
     finally
     {
         _m.Unlock();
     }
 }
Exemplo n.º 8
0
        public void invoke(ServantManager servantManager, Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.pos();

            //
            // Read the current.
            //
            _current.id.ice_readMembers(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.readStringSeq();
            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                _current.facet = facetPath[0];
            }
            else
            {
                _current.facet = "";
            }

            _current.operation = _is.readString();
            _current.mode      = (Ice.OperationMode)_is.readByte();
            _current.ctx       = new Dictionary <string, string>();
            int sz = _is.readSize();

            while (sz-- > 0)
            {
                string first  = _is.readString();
                string second = _is.readString();
                _current.ctx[first] = second;
            }

            Ice.Instrumentation.CommunicatorObserver obsv = _communicator.initializationData().observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.readInt();
                _is.pos(_is.pos() - 4);

                _observer = obsv.getDispatchObserver(_current, _is.pos() - start + size);
                if (_observer != null)
                {
                    _observer.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                _servant = servantManager.findServant(_current.id, _current.facet);
                if (_servant == null)
                {
                    _locator = servantManager.findServantLocator(_current.id.category);
                    if (_locator == null && _current.id.category.Length > 0)
                    {
                        _locator = servantManager.findServantLocator("");
                    }

                    if (_locator != null)
                    {
                        Debug.Assert(_locator != null);
                        try
                        {
                            _servant = _locator.locate(_current, out _cookie);
                        }
                        catch (Exception ex)
                        {
                            skipReadParams(); // Required for batch requests.
                            handleException(ex, false);
                            return;
                        }
                    }
                }
            }

            if (_servant == null)
            {
                try
                {
                    if (servantManager != null && servantManager.hasServant(_current.id))
                    {
                        throw new Ice.FacetNotExistException(_current.id, _current.facet, _current.operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(_current.id, _current.facet, _current.operation);
                    }
                }
                catch (Exception ex)
                {
                    skipReadParams(); // Required for batch requests
                    handleException(ex, false);
                    return;
                }
            }

            try
            {
                Task <Ice.OutputStream> task = _servant(this, _current);
                if (task == null)
                {
                    completed(null, false);
                }
                else
                {
                    if (task.IsCompleted)
                    {
                        _os = task.GetAwaiter().GetResult(); // Get the response
                        completed(null, false);
                    }
                    else
                    {
                        task.ContinueWith((Task <Ice.OutputStream> t) =>
                        {
                            try
                            {
                                _os = t.GetAwaiter().GetResult();
                                completed(null, true); // true = asynchronous
                            }
                            catch (Exception ex)
                            {
                                completed(ex, true); // true = asynchronous
                            }
                        },
                                          CancellationToken.None,
                                          TaskContinuationOptions.ExecuteSynchronously,
                                          scheduler: TaskScheduler.Current);
                    }
                }
            }
            catch (Exception ex)
            {
                completed(ex, false);
            }
        }
Exemplo n.º 9
0
        public void invoke(ServantManager servantManager, BasicStream stream)
        {
            _is = stream;

            int start = _is.pos();

            //
            // Read the current.
            //
            current_.id.read__(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.readStringSeq();
            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                current_.facet = facetPath[0];
            }
            else
            {
                current_.facet = "";
            }

            current_.operation = _is.readString();
            current_.mode      = (Ice.OperationMode)(int) _is.readByte();
            current_.ctx       = new Dictionary <string, string>();
            int sz = _is.readSize();

            while (sz-- > 0)
            {
                string first  = _is.readString();
                string second = _is.readString();
                current_.ctx[first] = second;
            }

            Ice.Instrumentation.CommunicatorObserver obsv = instance_.getObserver();
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.readInt();
                _is.pos(_is.pos() - 4);

                observer_ = obsv.getDispatchObserver(current_, _is.pos() - start + size);
                if (observer_ != null)
                {
                    observer_.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                servant_ = servantManager.findServant(current_.id, current_.facet);
                if (servant_ == null)
                {
                    locator_ = servantManager.findServantLocator(current_.id.category);
                    if (locator_ == null && current_.id.category.Length > 0)
                    {
                        locator_ = servantManager.findServantLocator("");
                    }

                    if (locator_ != null)
                    {
                        try
                        {
                            servant_ = locator_.locate(current_, out cookie_);
                        }
                        catch (Ice.UserException ex)
                        {
                            Ice.EncodingVersion encoding = _is.skipEncaps(); // Required for batch requests.

                            if (observer_ != null)
                            {
                                observer_.userException();
                            }

                            if (response_)
                            {
                                os_.writeByte(ReplyStatus.replyUserException);
                                os_.startWriteEncaps(encoding, Ice.FormatType.DefaultFormat);
                                os_.writeUserException(ex);
                                os_.endWriteEncaps();
                                if (observer_ != null)
                                {
                                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                                }
                                connection_.sendResponse(os_, compress_);
                            }
                            else
                            {
                                connection_.sendNoResponse();
                            }

                            if (observer_ != null)
                            {
                                observer_.detach();
                                observer_ = null;
                            }
                            connection_ = null;
                            return;
                        }
                        catch (System.Exception ex)
                        {
                            _is.skipEncaps(); // Required for batch requests.
                            handleException__(ex);
                            return;
                        }
                    }
                }
            }

            try
            {
                if (servant_ != null)
                {
                    //
                    // DispatchAsync is a "pseudo dispatch status", used internally only
                    // to indicate async dispatch.
                    //
                    if (servant_.dispatch__(this, current_) == Ice.DispatchStatus.DispatchAsync)
                    {
                        //
                        // If this was an asynchronous dispatch, we're done here.
                        //
                        return;
                    }

                    if (locator_ != null && !servantLocatorFinished__())
                    {
                        return;
                    }
                }
                else
                {
                    //
                    // Skip the input parameters, this is required for reading
                    // the next batch request if dispatching batch requests.
                    //
                    _is.skipEncaps();

                    if (servantManager != null && servantManager.hasServant(current_.id))
                    {
                        throw new Ice.FacetNotExistException(current_.id, current_.facet, current_.operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(current_.id, current_.facet, current_.operation);
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (servant_ != null && locator_ != null && !servantLocatorFinished__())
                {
                    return;
                }
                handleException__(ex);
                return;
            }

            //
            // Don't put the code below into the try block above. Exceptions
            // in the code below are considered fatal, and must propagate to
            // the caller of this operation.
            //

            Debug.Assert(connection_ != null);

            if (response_)
            {
                if (observer_ != null)
                {
                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                }
                connection_.sendResponse(os_, compress_);
            }
            else
            {
                connection_.sendNoResponse();
            }

            if (observer_ != null)
            {
                observer_.detach();
                observer_ = null;
            }
            connection_ = null;
        }