示例#1
0
        void StopConnection()
        {
            if (isStopping)
            {
                return;
            }
            Guid[] allRemoteClients;
            lock (startingLock)
            {
                if (updatingRedis == null)
                {
                    return;
                }
                if (isStopping)
                {
                    return;
                }

                isStopping = true;

                RemoveAllClients();

                updatingRedisCancellation.Cancel();
                updatingRedis.Wait();
                updatingRedis = null;
                updatingRedisCancellation.Dispose();
                updatingRedisCancellation = null;
                updatingRedisWaitingCancellation.Dispose();
                updatingRedisWaitingCancellation = null;

                subscriber.UnsubscribeAll();

                redisConnection.Close();
                redisConnection.Dispose();
                redisDatabase   = null;
                redisConnection = null;

                allRemoteClients = GetAllRemoteClients().ToArray();
                foreach (var remoteClientId in allRemoteClients)
                {
                    clientTable.Remove(remoteClientId);
                }

                clientTable = new ClientTable(privateChannelNamePrefix);
                clients     = new ConcurrentDictionary <Guid, ClientEntity>();
                targets     = new ConcurrentDictionary <RedisChannel, Guid>();
                AdapterStopped?.Invoke(this, EventArgs.Empty);
            }
            if (RemoteClientRemoved != null)
            {
                foreach (var remoteClientId in allRemoteClients)
                {
                    RemoteClientRemoved(this, new ClientIdEventArgs(remoteClientId));
                }
            }
        }
示例#2
0
 /// <summary>
 /// Initializes an instance of RedisAdapter.
 /// </summary>
 /// <param name="redisConfiguration">The string configuration to use for Redis multiplexer.</param>
 /// <param name="mainChannelName">Main channel name.</param>
 /// <param name="privateChannelNamePrefix">Prefix in naming of the private channel.</param>
 /// <param name="redisDb">The id to get a database for. Used in getting Redis database.</param>
 /// <param name="clientTimeToLive">Time to live (TTL) value of the host in seconds. Any records of hosts expired will be removed.</param>
 /// <param name="clientRefreshingInterval">Interval between refresh command sending operations in seconds.</param>
 protected RedisAdapter(string redisConfiguration, string mainChannelName, string privateChannelNamePrefix, int redisDb, int clientTimeToLive, int clientRefreshingInterval)
 {
     this.redisConfiguration       = redisConfiguration;
     this.privateChannelNamePrefix = privateChannelNamePrefix;
     this.redisDb                  = redisDb;
     mainChannel                   = new RedisChannel(mainChannelName, RedisChannel.PatternMode.Literal);
     this.clientTimeToLive         = clientTimeToLive;
     this.clientRefreshingInterval = clientRefreshingInterval;
     clientTable                   = new ClientTable(privateChannelNamePrefix);
 }