Ejemplo n.º 1
0
        private EndpointI[] setClientEndpoints(Ice.IObjectPrx clientProxy, bool hasRoutingTable)
        {
            lock (this)
            {
                if (_clientEndpoints == null)
                {
                    _hasRoutingTable = hasRoutingTable;
                    if (clientProxy == null)
                    {
                        //
                        // If getClientProxy() return nil, use router endpoints.
                        //
                        _clientEndpoints = _router.IceReference.getEndpoints();
                    }
                    else
                    {
                        clientProxy = clientProxy.Clone(clearRouter: true); // The client proxy cannot be routed.

                        //
                        // In order to avoid creating a new connection to the
                        // router, we must use the same timeout as the already
                        // existing connection.
                        //
                        if (_router.GetConnection() != null)
                        {
                            clientProxy = clientProxy.Clone(connectionTimeout: _router.GetConnection().timeout());
                        }

                        _clientEndpoints = clientProxy.IceReference.getEndpoints();
                    }
                }
                return(_clientEndpoints);
            }
        }
Ejemplo n.º 2
0
 public OutgoingAsyncT(Ice.IObjectPrx prx,
                       IOutgoingAsyncCompletionCallback completionCallback,
                       Ice.OutputStream?os = null,
                       Ice.InputStream?iss = null) :
     base(prx, completionCallback, os, iss)
 {
 }
Ejemplo n.º 3
0
        public void findAdapterById(string domainId, string adapterId, LookupReplyPrx reply,
                                    Ice.Current current)
        {
            if (!domainId.Equals(_domainId))
            {
                return; // Ignore
            }

            bool isReplicaGroup;

            Ice.IObjectPrx proxy = _registry.findAdapter(adapterId, out isReplicaGroup);
            if (proxy != null)
            {
                //
                // Reply to the multicast request using the given proxy.
                //
                try
                {
                    reply.foundAdapterByIdAsync(adapterId, proxy, isReplicaGroup);
                }
                catch (Ice.LocalException)
                {
                    // Ignore.
                }
            }
        }
Ejemplo n.º 4
0
 public OutgoingAsync(Ice.IObjectPrx prx, IOutgoingAsyncCompletionCallback completionCallback,
                      Ice.OutputStream?os = null, Ice.InputStream?iss = null) :
     base(prx, completionCallback, os, iss)
 {
     Encoding    = Protocol.getCompatibleEncoding(Proxy.IceReference.GetEncoding());
     Synchronous = false;
 }
Ejemplo n.º 5
0
        public bool addProxy(Ice.IObjectPrx proxy, AddProxyCallback callback)
        {
            Debug.Assert(proxy != null);
            lock (this)
            {
                if (!_hasRoutingTable)
                {
                    return(true); // The router implementation doesn't maintain a routing table.
                }
                if (_identities.Contains(proxy.Identity))
                {
                    //
                    // Only add the proxy to the router if it's not already in our local map.
                    //
                    return(true);
                }
            }

            _router.addProxiesAsync(new Ice.IObjectPrx[] { proxy }).ContinueWith(
                (t) =>
            {
                try
                {
                    addAndEvictProxies(proxy, t.Result);
                    callback.addedProxy();
                }
                catch (System.AggregateException ae)
                {
                    Debug.Assert(ae.InnerException is Ice.LocalException);
                    callback.setException((Ice.LocalException)ae.InnerException);
                }
            },
                System.Threading.Tasks.TaskScheduler.Current);
            return(false);
        }
Ejemplo n.º 6
0
 public OutgoingAsyncT(Ice.IObjectPrx prx,
                       IOutgoingAsyncCompletionCallback completionCallback,
                       Ice.OutgoingRequestFrame?requestFrame = null,
                       Ice.InputStream?iss = null) :
     base(prx, completionCallback, requestFrame, iss)
 {
 }
Ejemplo n.º 7
0
 public override void finished(Ice.IObjectPrx proxy)
 {
     if (proxy != null || _proxies.Count == 0)
     {
         sendResponse(proxy);
     }
     else if (_proxies.Count == 1)
     {
         sendResponse(_proxies.First());
     }
     else
     {
         List <Endpoint> endpoints = new List <Endpoint>();
         IObjectPrx?     result    = null;
         foreach (IObjectPrx prx in _proxies)
         {
             if (result == null)
             {
                 result = prx;
             }
             endpoints.AddRange(prx.Endpoints);
         }
         Debug.Assert(result != null);
         sendResponse(result.Clone(endpoints: endpoints.ToArray()));
     }
 }
Ejemplo n.º 8
0
 public override void finished(Ice.IObjectPrx proxy)
 {
     foreach (var cb in callbacks_)
     {
         cb.SetResult(proxy);
     }
     callbacks_.Clear();
 }
Ejemplo n.º 9
0
 public OutgoingAsync(Ice.IObjectPrx prx, IOutgoingAsyncCompletionCallback completionCallback,
                      Ice.OutgoingRequestFrame?requestFrame = null, Ice.InputStream?iss = null, bool oneway = false) :
     base(prx, completionCallback, requestFrame, iss)
 {
     Encoding    = Proxy.Encoding;
     Synchronous = false;
     IsOneway    = oneway;
 }
Ejemplo n.º 10
0
 public ConnectRequestHandler(Reference @ref, Ice.IObjectPrx proxy)
 {
     _reference      = @ref;
     _proxy          = proxy;
     _initialized    = false;
     _flushing       = false;
     _requestHandler = this;
 }
Ejemplo n.º 11
0
 private void sendResponse(Ice.IObjectPrx proxy)
 {
     foreach (var cb in callbacks_)
     {
         cb.SetResult(proxy);
     }
     callbacks_.Clear();
 }
Ejemplo n.º 12
0
 public ConnectRequestHandler(Reference @ref, Ice.IObjectPrx proxy)
 {
     _reference      = @ref;
     _response       = _reference.GetMode() == Ice.InvocationMode.Twoway;
     _proxy          = proxy;
     _initialized    = false;
     _flushing       = false;
     _requestHandler = this;
 }
Ejemplo n.º 13
0
 protected ProxyOutgoingAsyncBase(Ice.IObjectPrx prx,
                                  IOutgoingAsyncCompletionCallback completionCallback,
                                  Ice.OutputStream?os = null,
                                  Ice.InputStream?iss = null) :
     base(prx.Communicator, completionCallback, os, iss)
 {
     Proxy = prx;
     Mode  = Ice.OperationMode.Normal;
     _cnt  = 0;
     _sent = false;
 }
Ejemplo n.º 14
0
 public IRequestHandler Connect(Ice.IObjectPrx proxy)
 {
     lock (this)
     {
         if (!Initialized())
         {
             _proxies.Add(proxy);
         }
         return(_requestHandler);
     }
 }
Ejemplo n.º 15
0
        public EndpointI[] getServerEndpoints()
        {
            Ice.IObjectPrx serverProxy = _router.getServerProxy();
            if (serverProxy == null)
            {
                throw new Ice.NoEndpointException();
            }

            serverProxy = serverProxy.Clone(clearRouter: true); // The server proxy cannot be routed.
            return(serverProxy.IceReference.getEndpoints());
        }
Ejemplo n.º 16
0
 protected ProxyOutgoingAsyncBase(Ice.IObjectPrx prx,
                                  IOutgoingAsyncCompletionCallback completionCallback,
                                  OutgoingRequestFrame?requestFrame = null,
                                  Ice.InputStream?iss = null) :
     base(prx.Communicator, completionCallback, requestFrame, null, iss)
 {
     Proxy        = prx;
     IsIdempotent = false;
     IsOneway     = false;
     _cnt         = 0;
     _sent        = false;
 }
Ejemplo n.º 17
0
        finishRequest(Reference reference, List <Reference> wellKnownRefs, Ice.IObjectPrx proxy, bool notRegistered)
        {
            if (proxy == null || proxy.IceReference.isIndirect())
            {
                //
                // Remove the cached references of well-known objects for which we tried
                // to resolved the endpoints if these endpoints are empty.
                //
                foreach (Reference r in wellKnownRefs)
                {
                    _table.removeObjectReference(r.getIdentity());
                }
            }

            if (!reference.isWellKnown())
            {
                if (proxy != null && !proxy.IceReference.isIndirect())
                {
                    // Cache the adapter endpoints.
                    _table.addAdapterEndpoints(reference.getAdapterId(), proxy.IceReference.getEndpoints());
                }
                else if (notRegistered) // If the adapter isn't registered anymore, remove it from the cache.
                {
                    _table.removeAdapterEndpoints(reference.getAdapterId());
                }

                lock (this)
                {
                    Debug.Assert(_adapterRequests.ContainsKey(reference.getAdapterId()));
                    _adapterRequests.Remove(reference.getAdapterId());
                }
            }
            else
            {
                if (proxy != null && !proxy.IceReference.isWellKnown())
                {
                    // Cache the well-known object reference.
                    _table.addObjectReference(reference.getIdentity(), proxy.IceReference);
                }
                else if (notRegistered) // If the well-known object isn't registered anymore, remove it from the cache.
                {
                    _table.removeObjectReference(reference.getIdentity());
                }

                lock (this)
                {
                    Debug.Assert(_objectRequests.ContainsKey(reference.getIdentity()));
                    _objectRequests.Remove(reference.getIdentity());
                }
            }
        }
Ejemplo n.º 18
0
 internal void foundObject(Ice.Identity id, string requestId, Ice.IObjectPrx proxy)
 {
     lock (this)
     {
         ObjectRequest request;
         if (_objectRequests.TryGetValue(id, out request) && request.getRequestId() == requestId)
         {
             request.response(proxy);
             _timer.cancel(request);
             _objectRequests.Remove(id);
         }
         // else ignore responses from old requests
     }
 }
Ejemplo n.º 19
0
 response(Ice.IObjectPrx proxy)
 {
     lock (this)
     {
         _locatorInfo.finishRequest(_ref, _wellKnownRefs, proxy, false);
         _response = true;
         _proxy    = proxy;
         Monitor.PulseAll(this);
     }
     foreach (RequestCallback callback in _callbacks)
     {
         callback.response(_locatorInfo, proxy);
     }
 }
Ejemplo n.º 20
0
        public void addProxy(Ice.IObjectPrx proxy)
        {
            Debug.Assert(proxy != null);
            lock (this)
            {
                if (_identities.Contains(proxy.Identity))
                {
                    //
                    // Only add the proxy to the router if it's not already in our local map.
                    //
                    return;
                }
            }

            addAndEvictProxies(proxy, _router.addProxies(new Ice.IObjectPrx[] { proxy }));
        }
Ejemplo n.º 21
0
 internal void foundAdapter(string adapterId, string requestId, Ice.IObjectPrx proxy, bool isReplicaGroup)
 {
     lock (this)
     {
         AdapterRequest request;
         if (_adapterRequests.TryGetValue(adapterId, out request) && request.getRequestId() == requestId)
         {
             if (request.response(proxy, isReplicaGroup))
             {
                 _timer.cancel(request);
                 _adapterRequests.Remove(request.getId());
             }
         }
         // else ignore responses from old requests
     }
 }
Ejemplo n.º 22
0
        internal Ice.IObjectPrx findObject(Ice.Identity id)
        {
            lock (this)
            {
                if (id.name.Length == 0)
                {
                    return(null);
                }

                Ice.IObjectPrx prx = _wellKnownProxy.Clone(id);

                List <string> adapterIds = new List <string>();
                foreach (KeyValuePair <string, HashSet <string> > entry in _replicaGroups)
                {
                    try
                    {
                        prx.Clone(adapterId: entry.Key).IcePing();
                        adapterIds.Add(entry.Key);
                    }
                    catch (Ice.Exception)
                    {
                    }
                }
                if (adapterIds.Count == 0)
                {
                    foreach (KeyValuePair <string, Ice.IObjectPrx> entry in _adapters)
                    {
                        try
                        {
                            prx.Clone(adapterId: entry.Key).IcePing();
                            adapterIds.Add(entry.Key);
                        }
                        catch (Ice.Exception)
                        {
                        }
                    }
                }

                if (adapterIds.Count == 0)
                {
                    return(null);
                }
                //adapterIds.Suffle();
                return(prx.Clone(adapterId: adapterIds[0]));
            }
        }
Ejemplo n.º 23
0
            response(LocatorInfo locatorInfo, Ice.IObjectPrx proxy)
            {
                EndpointI[] 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 == null ? System.Array.Empty <EndpointI>() : endpoints, false);
                }
            }
Ejemplo n.º 24
0
        internal Ice.IObjectPrx findAdapter(string adapterId, out bool isReplicaGroup)
        {
            lock (this)
            {
                Ice.IObjectPrx result = null;
                if (_adapters.TryGetValue(adapterId, out result))
                {
                    isReplicaGroup = false;
                    return(result);
                }

                HashSet <string> adapterIds;
                if (_replicaGroups.TryGetValue(adapterId, out adapterIds))
                {
                    List <Ice.Endpoint> endpoints = new List <Ice.Endpoint>();
                    foreach (string a in adapterIds)
                    {
                        Ice.IObjectPrx proxy;
                        if (!_adapters.TryGetValue(a, out proxy))
                        {
                            continue; // TODO: Inconsistency
                        }

                        if (result == null)
                        {
                            result = proxy;
                        }

                        endpoints.AddRange(proxy.Endpoints);
                    }

                    if (result != null)
                    {
                        isReplicaGroup = true;
                        return(result.Clone(endpoints: endpoints.ToArray()));
                    }
                }

                isReplicaGroup = false;
                return(null);
            }
        }
Ejemplo n.º 25
0
 public bool response(Ice.IObjectPrx proxy, bool isReplicaGroup)
 {
     if (isReplicaGroup)
     {
         _proxies.Add(proxy);
         if (_latency == 0)
         {
             _latency = (long)((DateTime.Now.Ticks - _start) * lookup_.latencyMultiplier() / 10000.0);
             if (_latency == 0)
             {
                 _latency = 1; // 1ms
             }
             lookup_.timer().cancel(this);
             lookup_.timer().schedule(this, _latency);
         }
         return(false);
     }
     finished(proxy);
     return(true);
 }
Ejemplo n.º 26
0
 public Ice.Instrumentation.InvocationObserver getInvocationObserver(Ice.IObjectPrx prx, string operation,
                                                                     Dictionary <string, string> ctx)
 {
     if (_invocations.isEnabled())
     {
         try
         {
             Ice.Instrumentation.InvocationObserver del = null;
             if (_delegate != null)
             {
                 del = _delegate.getInvocationObserver(prx, operation, ctx);
             }
             return(_invocations.getObserver(new InvocationHelper(prx, operation, ctx), del));
         }
         catch (System.Exception ex)
         {
             _metrics.getLogger().error("unexpected exception trying to obtain observer:\n" + ex);
         }
     }
     return(null);
 }
Ejemplo n.º 27
0
        private void addAndEvictProxies(Ice.IObjectPrx proxy, Ice.IObjectPrx[] evictedProxies)
        {
            lock (this)
            {
                //
                // Check if the proxy hasn't already been evicted by a
                // concurrent addProxies call. If it's the case, don't
                // add it to our local map.
                //
                int index = _evictedIdentities.IndexOf(proxy.Identity);
                if (index >= 0)
                {
                    _evictedIdentities.RemoveAt(index);
                }
                else
                {
                    //
                    // If we successfully added the proxy to the router,
                    // we add it to our local map.
                    //
                    _identities.Add(proxy.Identity);
                }

                //
                // We also must remove whatever proxies the router evicted.
                //
                for (int i = 0; i < evictedProxies.Length; ++i)
                {
                    if (!_identities.Remove(evictedProxies[i].Identity))
                    {
                        //
                        // It's possible for the proxy to not have been
                        // added yet in the local map if two threads
                        // concurrently call addProxies.
                        //
                        _evictedIdentities.Add(evictedProxies[i].Identity);
                    }
                }
            }
        }
Ejemplo n.º 28
0
    static void connect(Ice.IObjectPrx proxy)
    {
        var conn = proxy.GetCachedConnection();

        if (conn != null)
        {
            conn.Close(Ice.ConnectionClose.GracefullyWithWait);
        }

        try
        {
            proxy.IcePing();
        }
        catch (Ice.LocalException)
        {
        }

        conn = proxy.GetCachedConnection();
        if (conn != null)
        {
            conn.Close(Ice.ConnectionClose.GracefullyWithWait);
        }
    }
Ejemplo n.º 29
0
        public void findObjectById(string domainId, Ice.Identity id, LookupReplyPrx reply,
                                   Ice.Current current)
        {
            if (!domainId.Equals(_domainId))
            {
                return; // Ignore
            }

            Ice.IObjectPrx proxy = _registry.findObject(id);
            if (proxy != null)
            {
                //
                // Reply to the mulicast request using the given proxy.
                //
                try
                {
                    reply.foundObjectByIdAsync(id, proxy);
                }
                catch (Ice.LocalException)
                {
                    // Ignore.
                }
            }
        }
Ejemplo n.º 30
0
 setReplicatedAdapterDirectProxyAsync(string adapterId, string replicaGroupId, Ice.IObjectPrx proxy,
                                      Ice.Current current)
 {
     lock (this)
     {
         if (proxy != null)
         {
             _adapters.Add(adapterId, proxy);
             HashSet <string> adapterIds;
             if (!_replicaGroups.TryGetValue(replicaGroupId, out adapterIds))
             {
                 adapterIds = new HashSet <string>();
                 _replicaGroups.Add(replicaGroupId, adapterIds);
             }
             adapterIds.Add(adapterId);
         }
         else
         {
             _adapters.Remove(adapterId);
             HashSet <string> adapterIds;
             if (_replicaGroups.TryGetValue(replicaGroupId, out adapterIds))
             {
                 adapterIds.Remove(adapterId);
                 if (adapterIds.Count == 0)
                 {
                     _replicaGroups.Remove(replicaGroupId);
                 }
             }
         }
     }
     return(null);
 }