Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: how to design totally ordered multicast

  1. #1
    someUser is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Question how to design totally ordered multicast

    Hi everyone

    I am pretty new to Java and therefore need help with designing the following task:

    I am supposed to implement a totally ordered multicast without using sockets. There's a pretty good explanation here on Page 9ff. I did understand the logic behind the totally ordered multicast with the lamport clocks, however I have no idea how to implement this in Java.

    So this is my idea:
    I need to have two (or more) objects representing processes that send messages to each other, store the messages in their queue ordered by timestamp, and only process the message, when the message is ahead of the queue and all other processes have acknowledged this message.

    So far, I have tried to do this with a mediator pattern from this link.

    The colleagues are my processes.

    The main-Method of the supposed Client class from "Design Patterns Uncovered" I changed to

    Java Code:
    public static void main(String[] args) 
      {
          ApplicationMediator mediator = new ApplicationMediator(); 
          
          ConcreteColleague process1 = new ConcreteColleague(mediator, 1);
          ConcreteColleague process2 = new ConcreteColleague(mediator, 2);
         
          mediator.addColleague(process1);
          mediator.addColleague(process2);
    
          //new Message with Text, messageID(1) and timestamp(5)
          process1.send(new Message("messageText", 1, 5)); 
          
      }

    I added a Message class as well, which has the Attributes messageText, id, timestamp and ackArray[]. There are some getter-Method's and the Methods (in Pseudocode)

    Java Code:
    public class Message{
    
    String messageText;
    int id;
    int timestamp;
    int ackArray[];
    
    public Message(String text, int id, int timestamp){
     //set attributes....
    }
    
    //some getter-Methods
    
    //set true at the position of ProcessID in the Array
    public void ackMessage(id){
     ackArray[id] = true;
    } 
    
    //when all processes have set there position in the array to true, then the method returns true, otherwise false
    public Boolean getAcks(){
          //loop through Array ackArray and see if all id's are true if so
         return true;
         //else
          return false;
    }
    }
    Instead of having different Colleague Classes, I just have the ConcreteColleague and have an Attribute processID, which identifies the Colleague. My idea was to add a TreeMap to the colleagues representing the queue, which stores the messages in the receive-Method and then add the acknowlegement to the Array in the Message-Class

    Java Code:
    public class ConcreteColleague extends Colleague
    {
           int id;
           SortedMap<Integer, Message> messageQueue = new TreeMap<Integer, Message>();
    
           public ConcreteColleague (int id){this.id = id}
           
    
    public void receive(Message message)
            {
               System.out.println("Colleague " + id + " received: " + message.getMessage());
               messageQueue.put(message.getMessageID(), message);
               message.ackMessage(id);
           }
    }
    
    }
    This seems to work. The two instances of concreteColleague in the main-Method print out the received messages all right. But now in the ConcreteColleague class I'd have to check regularly the first message in the queue if it got all the acknowlegments to actually process the message:

    Java Code:
     public void checkMessage(){
             if(messageQueue.get(messageQueue.firstKey()).getAcks()){
                  System.out.println("Proceed with message " + messageQueue.get(messageQueue.firstKey()).getMessageID());
                  //... delete first message in Queue
              }
    }
    But where and when do i call this method? I've tried to implement the Runnable Interface to the ConcreteColleague and then add the run-Method to run everything in a thread:

    Java Code:
    public void run(){
    
    while(true){
       if (messageQueue.size()  > 0){
             checkMessage();
    }
    }
    }
    but then, when I do the following in the Client-Class:

    Java Code:
    ....
    
    Thread t1 = new Thread( process1 );
    t1.start();
     
    process1.send(....);
    ....
    the send-Method is never reached.

    Can someone help me fixing this design problem? I have really no idea how to do this pattern with threads. I don't even know if it's the right approach to do this. I hope you understand the code-idea above, otherwise just ask.
    If I have to start with a different approach, I'd be delighted to just have the general idea how to create my classes and how they interact with each other. Any help is much appreciated, since I'm sitting desperately in front of this task since two weeks.

    Greetings
    Brian

  2. #2
    someUser is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Re: how to design totally ordered multicast

    I know it's only two days since my question, but I'm desperate. Does no one have a little hint for me? Or am I not clear enough with my question? Just let me know, if it's not understandable.

    Thanks...

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,539
    Rep Power
    5

    Default Re: how to design totally ordered multicast

    Well, I am going to respond so you won't be left in a lurch. My background is network engineering and I am very familiar with deploying various network protocols and how they work. However, that does not mean I could assist you in any reasonable time frame on the topic of implementing a multicast algorithm (assuming the two forms of multicast are similar). Some folks here might be able to help but most (myself included) would be more inclined to help with Java specific questions. Note: The article looks interesting so I will probably read it in the near future.

    Regards,
    Jim
    gimbal2 likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Interresting multicast stuff this
    By mujo in forum Networking
    Replies: 0
    Last Post: 11-09-2012, 03:32 PM
  2. Multicast Tool 0.1.2
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-02-2011, 06:49 PM
  3. Multicast Tool
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-01-2011, 06:40 PM
  4. Multicast group seems to be a noop
    By toadaly in forum Advanced Java
    Replies: 0
    Last Post: 04-10-2009, 06:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •