private void Trace(string msg, Reference r, Endpoint[] endpoints)
        {
            var s = new System.Text.StringBuilder();

            s.Append(msg + "\n");
            if (r.GetAdapterId().Length > 0)
            {
                s.Append("adapter = " + r.GetAdapterId() + "\n");
            }
            else
            {
                s.Append("well-known proxy = " + r.ToString() + "\n");
            }

            s.Append("endpoints = ");
            int sz = endpoints.Length;

            for (int i = 0; i < sz; i++)
            {
                s.Append(endpoints[i].ToString());
                if (i + 1 < sz)
                {
                    s.Append(":");
                }
            }

            r.GetCommunicator().Logger.Trace(r.GetCommunicator().TraceLevels.locationCat, s.ToString());
        }
        internal void ClearCache(Reference rf)
        {
            Debug.Assert(rf.IsIndirect());
            if (!rf.IsWellKnown())
            {
                Endpoint[]? endpoints = _table.RemoveAdapterEndpoints(rf.GetAdapterId());

                if (endpoints != null && rf.GetCommunicator().TraceLevels.location >= 2)
                {
                    Trace("removed endpoints for adapter from locator cache", rf, endpoints);
                }
            }
            else
            {
                Reference?r = _table.RemoveObjectReference(rf.GetIdentity());
                if (r != null)
                {
                    if (!r.IsIndirect())
                    {
                        if (rf.GetCommunicator().TraceLevels.location >= 2)
                        {
                            Trace("removed endpoints for well-known object from locator cache", rf, r.GetEndpoints());
                        }
                    }
                    else if (!r.IsWellKnown())
                    {
                        if (rf.GetCommunicator().TraceLevels.location >= 2)
                        {
                            Trace("removed adapter for well-known object from locator cache", rf, r);
                        }
                        ClearCache(r);
                    }
                }
            }
        }
Esempio n. 3
0
        private void GetEndpointsException(Reference reference, System.Exception exc)
        {
            try
            {
                throw exc;
            }
            catch (AdapterNotFoundException ex)
            {
                Communicator communicator = reference.GetCommunicator();
                if (communicator.TraceLevels.Location >= 1)
                {
                    var s = new System.Text.StringBuilder();
                    s.Append("adapter not found\n");
                    s.Append("adapter = " + reference.GetAdapterId());
                    communicator.Logger.Trace(communicator.TraceLevels.LocationCat, s.ToString());
                }

                throw new NotRegisteredException("object adapter", reference.GetAdapterId(), ex);
            }
            catch (ObjectNotFoundException ex)
            {
                Communicator communicator = reference.GetCommunicator();
                if (communicator.TraceLevels.Location >= 1)
                {
                    var s = new System.Text.StringBuilder();
                    s.Append("object not found\n");
                    s.Append("object = " + reference.GetIdentity().ToString(communicator.ToStringMode));
                    communicator.Logger.Trace(communicator.TraceLevels.LocationCat, s.ToString());
                }

                throw new NotRegisteredException("object",
                                                 reference.GetIdentity().ToString(communicator.ToStringMode), ex);
            }
            catch (NotRegisteredException)
            {
                throw;
            }
            catch (System.Exception ex)
            {
                Communicator communicator = reference.GetCommunicator();
                if (communicator.TraceLevels.Location >= 1)
                {
                    var s = new System.Text.StringBuilder();
                    s.Append("couldn't contact the locator to retrieve endpoints\n");
                    if (reference.GetAdapterId().Length > 0)
                    {
                        s.Append("adapter = " + reference.GetAdapterId() + "\n");
                    }
                    else
                    {
                        s.Append("well-known proxy = " + reference.ToString() + "\n");
                    }
                    s.Append("reason = " + ex);
                    communicator.Logger.Trace(communicator.TraceLevels.LocationCat, s.ToString());
                }
                throw;
            }
        }
        private void Trace(string msg, Reference r, Reference resolved)
        {
            Debug.Assert(r.IsWellKnown());

            var s = new System.Text.StringBuilder();

            s.Append(msg);
            s.Append("\n");
            s.Append("well-known proxy = ");
            s.Append(r.ToString());
            s.Append("\n");
            s.Append("adapter = ");
            s.Append(resolved.GetAdapterId());

            r.GetCommunicator().Logger.Trace(r.GetCommunicator().TraceLevels.locationCat, s.ToString());
        }
            public void Response(LocatorInfo locatorInfo, IObjectPrx?proxy)
            {
                Endpoint[]? endpoints = null;
                if (proxy != null)
                {
                    Reference r = proxy.IceReference;
                    if (_ref.IsWellKnown() && !Protocol.isSupported(_ref.GetEncoding(), r.GetEncoding()))
                    {
                        //
                        // If a well-known proxy and the returned
                        // proxy encoding isn't supported, we're done:
                        // there's no compatible endpoint we can use.
                        //
                    }
                    else if (!r.IsIndirect())
                    {
                        endpoints = r.GetEndpoints();
                    }
                    else if (_ref.IsWellKnown() && !r.IsWellKnown())
                    {
                        //
                        // We're resolving the endpoints of a well-known object and the proxy returned
                        // by the locator is an indirect proxy. We now need to resolve the endpoints
                        // of this indirect proxy.
                        //
                        if (_ref.GetCommunicator().TraceLevels.location >= 1)
                        {
                            locatorInfo.Trace("retrieved adapter for well-known object from locator, " +
                                              "adding to locator cache", _ref, r);
                        }
                        locatorInfo.GetEndpoints(r, _ref, _ttl, _callback);
                        return;
                    }
                }

                if (_ref.GetCommunicator().TraceLevels.location >= 1)
                {
                    locatorInfo.GetEndpointsTrace(_ref, endpoints, false);
                }
                if (_callback != null)
                {
                    _callback.SetEndpoints(endpoints ?? Array.Empty <Endpoint>(), false);
                }
            }
        private Request GetObjectRequest(Reference reference)
        {
            if (reference.GetCommunicator().TraceLevels.location >= 1)
            {
                Communicator communicator = reference.GetCommunicator();
                var          s            = new System.Text.StringBuilder();
                s.Append("searching for well-known object\nwell-known proxy = ");
                s.Append(reference.ToString());
                communicator.Logger.Trace(communicator.TraceLevels.locationCat, s.ToString());
            }

            lock (this)
            {
                if (_objectRequests.TryGetValue(reference.GetIdentity(), out Request request))
                {
                    return(request);
                }

                request = new ObjectRequest(this, reference);
                _objectRequests.Add(reference.GetIdentity(), request);
                return(request);
            }
        }
        private Request GetAdapterRequest(Reference reference)
        {
            if (reference.GetCommunicator().TraceLevels.location >= 1)
            {
                Communicator communicator = reference.GetCommunicator();
                var          s            = new System.Text.StringBuilder();
                s.Append("searching for adapter by id\nadapter = ");
                s.Append(reference.GetAdapterId());
                communicator.Logger.Trace(communicator.TraceLevels.locationCat, s.ToString());
            }

            lock (this)
            {
                if (_adapterRequests.TryGetValue(reference.GetAdapterId(), out Request request))
                {
                    return(request);
                }

                request = new AdapterRequest(this, reference);
                _adapterRequests.Add(reference.GetAdapterId(), request);
                return(request);
            }
        }
 private void GetEndpointsTrace(Reference reference, Endpoint[]?endpoints, bool cached)
 {
     if (endpoints != null && endpoints.Length > 0)
     {
         if (cached)
         {
             if (reference.IsWellKnown())
             {
                 Trace("found endpoints for well-known proxy in locator cache", reference, endpoints);
             }
             else
             {
                 Trace("found endpoints for adapter in locator cache", reference, endpoints);
             }
         }
         else
         {
             if (reference.IsWellKnown())
             {
                 Trace("retrieved endpoints for well-known proxy from locator, adding to locator cache",
                       reference, endpoints);
             }
             else
             {
                 Trace("retrieved endpoints for adapter from locator, adding to locator cache",
                       reference, endpoints);
             }
         }
     }
     else
     {
         Communicator communicator = reference.GetCommunicator();
         var          s            = new System.Text.StringBuilder();
         s.Append("no endpoints configured for ");
         if (reference.GetAdapterId().Length > 0)
         {
             s.Append("adapter\n");
             s.Append("adapter = " + reference.GetAdapterId());
         }
         else
         {
             s.Append("well-known object\n");
             s.Append("well-known proxy = " + reference.ToString());
         }
         communicator.Logger.Trace(communicator.TraceLevels.locationCat, s.ToString());
     }
 }
        GetEndpoints(Reference reference, Reference?wellKnownRef, int ttl, IGetEndpointsCallback?callback)
        {
            Debug.Assert(reference.IsIndirect());
            Endpoint[]? endpoints = null;
            bool cached;

            if (!reference.IsWellKnown())
            {
                endpoints = _table.GetAdapterEndpoints(reference.GetAdapterId(), ttl, out cached);
                if (!cached)
                {
                    if (_background && endpoints != null)
                    {
                        GetAdapterRequest(reference).AddCallback(reference, wellKnownRef, ttl, null);
                    }
                    else
                    {
                        GetAdapterRequest(reference).AddCallback(reference, wellKnownRef, ttl, callback);
                        return;
                    }
                }
            }
            else
            {
                Reference?r = _table.GetObjectReference(reference.GetIdentity(), ttl, out cached);
                if (!cached)
                {
                    if (_background && r != null)
                    {
                        GetObjectRequest(reference).AddCallback(reference, null, ttl, null);
                    }
                    else
                    {
                        GetObjectRequest(reference).AddCallback(reference, null, ttl, callback);
                        return;
                    }
                }

                Debug.Assert(r != null);
                if (!r.IsIndirect())
                {
                    endpoints = r.GetEndpoints();
                }
                else if (!r.IsWellKnown())
                {
                    if (reference.GetCommunicator().TraceLevels.location >= 1)
                    {
                        Trace("found adapter for well-known object in locator cache", reference, r);
                    }
                    GetEndpoints(r, reference, ttl, callback);
                    return;
                }
            }

            Debug.Assert(endpoints != null);
            if (reference.GetCommunicator().TraceLevels.location >= 1)
            {
                GetEndpointsTrace(reference, endpoints, true);
            }
            if (callback != null)
            {
                callback.SetEndpoints(endpoints, true);
            }
        }