Exemple #1
0
        public int execute(JoinCommand command)
        {
            // delay
            this.delay();

            if (this.isFrozen)
            {
                this.frozenCommands.Add(command);

                while (true)
                {
                    // freeze
                }

                return(0);
            }
            else
            {
                Console.WriteLine("Recieved " + command.getType() + "-" +
                                  command.getSequenceNumber() + " command from " + command.getIssuerId());

                MeetingProposal meeting = this.getMeetingByTopic(command.getTopic());

                if (meeting == null)
                {
                    Console.WriteLine("Meeting {0} not found, Contacting other servers ...", command.getTopic());
                    meeting = this.restoreLostMeeting(command.getTopic());

                    // Console.WriteLine("Meeting {0} not found, Waiting ...");
                    // Thread.Sleep(2000);

                    if (meeting == null)
                    {
                        Console.WriteLine("Meeting {0} not found", command.getTopic());
                        return(0);
                    }
                }

                if (meeting.isClosed() || meeting.isCancelled())
                {
                    // a client can join a closed meeting if it was joined before the closing momment
                    if (command.getTimestamp().CompareTo(meeting.getClosingTimestamp()) < 0)
                    {
                        meeting.open();
                        this.joinMeeting(command.getIssuerId(), meeting, command.getDesiredSlots());
                        meeting.close();
                    }
                }
                else
                {
                    this.joinMeeting(command.getIssuerId(), meeting, command.getDesiredSlots());
                }

                this.informOtherServers(command);

                return(1);
            }
        }
Exemple #2
0
        private MeetingProposal closeMeeting(string client_id, string topic)
        {
            Monitor.Enter(this.meetings);
            MeetingProposal proposal = this.getMeetingByTopic(topic);

            if (proposal == null)
            {
                return(null);
            }

            proposal.close();
            Monitor.Exit(this.meetings);
            return(proposal);
        }
Exemple #3
0
        public int execute(CloseCommand command)
        {
            //TODO: check causal consistency and total order

            // delay
            this.delay();

            if (this.isFrozen)
            {
                this.frozenCommands.Add(command);

                while (true)
                {
                    // freeze
                }

                return(0);
            }
            else
            {
                Console.WriteLine("Recieved " + command.getType() + " command from " + command.getIssuerId());
                MeetingProposal meeting = this.closeMeeting(command.getIssuerId(), command.getTopic());

                if (meeting == null)
                {
                    meeting = this.restoreLostMeeting(command.getTopic());

                    if (meeting == null)
                    {
                        Console.WriteLine("Meeting not found");
                        return(0);
                    }
                }

                meeting.setClosingTimestamp(command.getTimestamp());
                meeting.close();

                this.informOtherServers(command);

                return(1);
            }
        }