示例#1
0
        public void Report(TopicFailure request)
        {
            var recoveryAction = HandleFailure(new FailureDescriptor
            {
                PathToDbFile      = Connections.PathToDbFile(Connections.TopicsDir, request.Name),
                DbLock            = Locks.TakeTopicLock(request.Name),
                CooperatorAddress = request.Cooperator,
                RecoveryCategory  = "topics",
                DbName            = request.Name
            });

            Propagators.ScheduleTopicOperation(request.Name, recoveryAction);
        }
示例#2
0
        public void Create(CreateSubscription request)
        {
            var topicLock = Locks.TakeTopicLock(request.TopicName);

            lock (topicLock)
            {
                if (Locks.TopicsRecoveryLocks.ContainsKey(request.TopicName))
                {
                    throw new Exception($"Topic {request.TopicName} is inconsistent");
                }

                using (var connection = Connections.ConnectToInitializedTopic(request.TopicName))
                {
                    Create(connection, request);
                }
            }
        }
示例#3
0
        public void Delete(DeleteTopic request)
        {
            var topicLock = Locks.TakeTopicLock(request.TopicName);

            lock (topicLock)
            {
                if (Locks.TopicsRecoveryLocks.ContainsKey(request.TopicName))
                {
                    throw new Exception($"Topic {request.TopicName} is inconsistent");
                }

                Connections.RemoveTopic(request.TopicName);
                Monitor.PulseAll(topicLock);
                Propagators.ScheduleTopicOperation(request.TopicName, () => Propagate(request));
                Locks.RemoveTopicLock(request.TopicName);
            }
        }
示例#4
0
        Announcement ReadFromDb(IDbConnection connection, Subscriber subscriber, ReadAnnouncement request)
        {
            var topicLock = Locks.TakeTopicLock(request.TopicName);

            lock (topicLock)
            {
                var query        = NextAnnouncement.make(connection, subscriber);
                var announcement = connection.FirstOrDefault(query);
                while (announcement == null)
                {
                    Monitor.Wait(topicLock);
                    announcement = connection.FirstOrDefault(query);
                }

                return(announcement);
            }
        }
示例#5
0
        public void Delete(DeleteSubscription request)
        {
            var topicLock = Locks.TakeTopicLock(request.TopicName);

            lock (topicLock)
            {
                if (Locks.TopicsRecoveryLocks.ContainsKey(request.TopicName))
                {
                    throw new Exception($"Topic {request.TopicName} is inconsistent");
                }

                using (var connection = Connections.ConnectToInitializedTopic(request.TopicName))
                {
                    connection.DeleteById <Subscriber>(request.SubscriberId);
                }

                Propagators.ScheduleTopicOperation(request.TopicName, () => Propagate(request));
            }
        }
示例#6
0
        public void Create(CreateTopic request)
        {
            var topicLock = Locks.TakeTopicLock(request.Name);

            lock (topicLock)
            {
                if (Locks.TopicsRecoveryLocks.ContainsKey(request.Name))
                {
                    throw new Exception($"Topic {request.Name} is inconsistent");
                }

                using (var connection = Connections.ConnectToTopic(request.Name))
                {
                    connection.CreateTableIfNotExists <Announcement>();
                    connection.CreateTableIfNotExists <Subscriber>();
                }

                if (!string.IsNullOrEmpty(request.Cooperator))
                {
                    Propagators.ScheduleTopicOperation(request.Name, () => PropagateRequest(request));
                }
            }
        }