Exemple #1
0
        void StartConnection()
        {
            lock (startingLock)
            {
                if (updatingRedis != null)
                {
                    return;
                }
                sendingNormal = true;
                isStopping    = false;

                redisConnection = ConnectionMultiplexer.Connect(redisConfiguration);
                redisDatabase   = redisConnection.GetDatabase(redisDb);
                publisher       = redisDatabase.Multiplexer.GetSubscriber();
                subscriber      = redisDatabase.Multiplexer.GetSubscriber();
                subscriber.Subscribe(mainChannel, OnMainChannelReceived);

                foreach (var clientId in clients.Keys)
                {
                    RedisChannel redisChannel = new RedisChannel(privateChannelNamePrefix + clientId.ToString("N"), RedisChannel.PatternMode.Literal);
                    if (targets.TryAdd(redisChannel, clientId))
                    {
                        subscriber.Subscribe(redisChannel, OnPrivateChannelReceived);
                    }
                }

                updatingRedisCancellation        = new CancellationTokenSource();
                updatingToken                    = updatingRedisCancellation.Token;
                updatingRedisWaitingCancellation = new CancellationTokenSource();

                startingLock.Reset();

                updatingRedis = Task.Run(async() => await UpdateRedisAsync());
                startingLock.Wait();
                AdapterStarted?.Invoke(this, EventArgs.Empty);
            }
        }
Exemple #2
0
        void StartProcessing()
        {
            lock (startingLock) //only for starting lock
            {
                if (readingJob != null)
                {
                    return;
                }
                isStopping    = false;
                sendingNormal = true;
                startingLock.Reset();
                shuttingdownTokenSource = new CancellationTokenSource();
                shuttingdownToken       = shuttingdownTokenSource.Token;
                sendingBuffers          = new BlockingCollection <byte[]>();

                readingJob = Task.Run(() => ReadingProcessor());
                writingJob = Task.Run(async() => await WritingProcessorAsync());
                keepingJob = Task.Run(async() => await KeepingProcessorAsync());

                startingLock.Wait();

                AdapterStarted?.Invoke(this, EventArgs.Empty);
            }
        }