Beispiel #1
0
        /// <remarks>
        /// This method is thread safe.
        /// </remarks>
        public void ReleaseSync(IChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null)
            {
                throw new ArgumentNullException("chatView");
            }

            var chatKey = GetChatKey(chatView.ChatModel);

#if LOG4NET
            Logger.Debug("ReleaseSync() <" + chatKey + "> releasing " +
                         "<" + chatView.ID + ">");
#endif
            lock (SyncReleaseQueue) {
                SyncReleaseQueue.Add(chatKey, chatView);
            }
            AutoResetEvent syncWait = null;
            lock (SyncWaitQueue) {
                SyncWaitQueue.TryGetValue(chatKey, out syncWait);
            }
            // release the sync worker
            syncWait.Set();
        }
Beispiel #2
0
        public void Clear()
        {
            Trace.Call();

            lock (SyncWaitQueue)
                lock (SyncReleaseQueue) {
                    SyncWaitQueue.Clear();
                    SyncReleaseQueue.Clear();
                }
        }
Beispiel #3
0
        void SyncWorker(ChatModel chatModel)
        {
            try {
                var            chatKey  = GetChatKey(chatModel);
                AutoResetEvent syncWait = null;
                lock (SyncWaitQueue) {
                    SyncWaitQueue.TryGetValue(chatKey, out syncWait);
                }
                if (syncWait != null)
                {
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " +
                                 "sync lock release...");
#endif
                    // This chat was queued by QueueAdd() thus we need to wait
                    // till the ChatView is created and ready to be synced
                    syncWait.WaitOne();
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> " +
                                 "sync lock released");
#endif

                    // no longer need the sync lock
                    lock (SyncWaitQueue) {
                        SyncWaitQueue.Remove(chatKey);
                    }
                }

                IChatView chatView = null;
                lock (SyncReleaseQueue) {
                    if (!SyncReleaseQueue.TryGetValue(chatKey, out chatView))
                    {
#if LOG4NET
                        Logger.Warn("SyncWorker(): chatView is null! " +
                                    "probably a reconnect, bailing out...");
#endif
                        return;
                    }
                    // no longer need the release slot
                    // BUG: this breaks re-syncing an existing chat! For that
                    // reason the frontend _must_ notify us via Remove() if the
                    // chat sync state is no longer needed
                    //SyncReleaseQueue.Remove(chatKey);
                }

                Sync(chatView);
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("SyncWorker(): Exception!", ex);
#endif
                OnWorkerException(chatModel, ex);
            }
        }
Beispiel #4
0
        /// <remarks>
        /// This method is thread safe.
        /// </remarks>
        public void QueueAdd(ChatModel chatModel)
        {
            Trace.Call(chatModel);

            if (chatModel == null)
            {
                throw new ArgumentNullException("chatModel");
            }

            var chatKey = GetChatKey(chatModel);

            lock (SyncWaitQueue) {
                SyncWaitQueue.Add(chatKey, new AutoResetEvent(false));
#if LOG4NET
                Logger.Debug("QueueAdd() <" + chatKey + "> created sync lock");
#endif
            }
            WorkerQueue.Enqueue(delegate {
                AddWorker(chatModel);
            });
        }
Beispiel #5
0
        void SyncWorker(ChatModel chatModel)
        {
            try {
                var            chatKey  = GetChatKey(chatModel);
                AutoResetEvent syncWait = null;
                lock (SyncWaitQueue) {
                    SyncWaitQueue.TryGetValue(chatKey, out syncWait);
                }
                if (syncWait != null)
                {
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " +
                                 "sync lock release...");
#endif
                    // This chat was queued by QueueAdd() thus we need to wait
                    // till the ChatView is created and ready to be synced
                    syncWait.WaitOne();
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> " +
                                 "sync lock released");
#endif

                    // no longer need the sync lock
                    lock (SyncWaitQueue) {
                        SyncWaitQueue.Remove(chatKey);
                    }
                }

                IChatView chatView = null;
                lock (SyncReleaseQueue) {
                    SyncReleaseQueue.TryGetValue(chatKey, out chatView);
                }

                Sync(chatView);
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("SyncWorker(): Exception!", ex);
#endif
            }
        }