示例#1
0
 public bool TryGetClientCacheEntry(
     ResolvedServiceEndpoint endpoint,
     string listenerName,
     out CommunicationClientCacheEntry <TCommunicationClient> cacheEntry)
 {
     return(this.cache.TryGetValue(
                new PartitionClientCacheKey(endpoint, listenerName),
                out cacheEntry));
 }
示例#2
0
        public bool TryGetClientCacheEntry(
            Guid partitionId,
            ResolvedServiceEndpoint endpoint,
            string listenerName,
            out CommunicationClientCacheEntry <TCommunicationClient> cacheEntry)
        {
            var partitionClientCache = this.clientCache.GetOrAdd(
                partitionId,
                new PartitionClientCache(partitionId, this.traceId));

            return(partitionClientCache.TryGetClientCacheEntry(endpoint, listenerName, out cacheEntry));
        }
示例#3
0
        //
        // This method validates if client stored in the cache entry is valid. If the client is valid,
        // this method sets the 'client' out param and returns true. If the client is not valid, it returns
        // false.
        //
        private bool ValidateLockedClientCacheEntry(
            CommunicationClientCacheEntry <TCommunicationClient> cacheEntry,
            ResolvedServicePartition rsp,
            out TCommunicationClient client)
        {
            client = cacheEntry.Client;
            var faultedClient = default(TCommunicationClient);

            // check if we have a cached client
            if (client != null)
            {
                // we have a cached client, check when was it created
                if (cacheEntry.Rsp.CompareVersion(rsp) >= 0)
                {
                    // it was created with the same RSP or higher version RSP
                    // check if the client is still valid and not faulted
                    if (!this.ValidateClient(client))
                    {
                        // client is not valid, abort the client, and recreate
                        this.AbortClient(client);
                        faultedClient     = client;
                        cacheEntry.Client = default(TCommunicationClient);
                        client            = default(TCommunicationClient);
                    }
                    else
                    {
                        // client is valid, return the valid client
                        return(true);
                    }
                }
                else
                {
                    // we have cached client, but it was created with older version of RSP
                    // check if the client is still valid
                    if (this.ValidateClient(cacheEntry.GetEndpoint(), client))
                    {
                        // the client is valid, but was initially created with an older version of RSP,
                        // this could happen in cases when services listen on the same endpoint after failover.
                        // replace the RSP in the entry and client, so that we use the right RSP incase of complaint
                        // based resolution in future.
                        cacheEntry.Rsp = rsp;
                        client.ResolvedServicePartition = rsp;
                        return(true);
                    }
                    else
                    {
                        // the client is not valid, abort the client
                        this.AbortClient(client);
                        faultedClient     = client;
                        cacheEntry.Client = default(TCommunicationClient);
                        client            = default(TCommunicationClient);
                    }
                }
            }

            if (faultedClient != null)
            {
                this.OnClientDisconnected(faultedClient);
            }

            return(false);
        }