예제 #1
0
        private Task <T> ProcessTask <T, TReq, TRes>(TReq requestMsg)
            where T : class
            where TReq : IZMIRequestMessage
            where TRes : IZMIResponseMessage <T>
        {
            _executor.AddMessage(requestMsg);

            IMessage responseMessage;

            lock (_dictLock)
            {
                while (!_dictionary.TryGetValue(requestMsg, out responseMessage))
                {
                    Monitor.Wait(_dictLock);
                }
            }

            if (!(responseMessage is TRes responseWrapper))
            {
                Logger.LogError("Return message is not a GetQueriesResponseMessage");
                return(Task.FromResult(default(T)));
            }

            return(Task.FromResult(responseWrapper.Response));
        }
예제 #2
0
        public GossipModule(IExecutor executor, int gossipTimer, int retryDelay, int maxRetriesCount,
                            IGossipStrategy gossipStrategy = null)
        {
            _executor       = executor;
            _gossipStrategy = gossipStrategy ?? new RandomGossipStrategy();

            _gossipThread = new Thread(Gossip);
            _gossipThread.Start();

            _readerThread = new Thread(ReadMessages);
            _readerThread.Start();

            _gossipTimer     = gossipTimer;
            _retryDelay      = retryDelay;
            _maxRetriesCount = maxRetriesCount;

            lock (_timerMessageIdLock)
                _executor.AddMessage(new TimerAddCallbackMessage(GetType(), _timerMessageId++, _gossipTimer,
                                                                 DateTimeOffset.Now, AddGossipTimer));
        }