0 Replies - 170 Views - Last Post: 14 November 2012 - 08:44 AM Rate Topic: -----

#1 csbosss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-November 12

Question about:Run bully Algorithm&Ring Based Algorithm simulation

Posted 14 November 2012 - 08:44 AM

Hi guys,

This project has many java classes to deal with to represent the right simulation to run Ring based election algorithm and bully election algorithm.Graphic output represented correctly except the running algorithms which are RingNode.java + BullyNode.java and both of them extend Node.java themselves. The previous group has done the graphics part alone without connecting with the way that algorithm simulated + code for algorithms themselves. The previous group left two java code files to complete them RingNode.java + BullyNode.java and both of them extend Node.java. where other files keep them unchanged

My question is:
How I can connect all previous jobs into the running methods inside these two files as you can see below. I would like to know the starting points cause this is a first time I get other friends work and I have to complete it: how I could gather information from different files of canvas in which the two algorithms run(Note: if run the codes now , it will show you the canvas and you can create nodes by left click on mouse and link them using right click of mouse and algorithms buttons and starting node which is turn to yellow color ; but once you click on the buttons, it will not do anything waiting to be finished by me.
I also attach other link where you can see other people job for both algorithms simulation and get idea about it, in general.


Click here to see similar job both algorithm

----------------------------------------------------------------------------------------------------------------------------
These are the three files I have to deal with in term to make the project done. other files you can see them in attachment which let the project works correctly now the whole files.

RingNode.java
/*
  Distributed Systems: Practical Exercise 
  
  Implementation of the ring-based election algorithm should be provided in 
  this class. Do not alter the constructor.
  Complete the run method of this class. 
 
*/


public class RingNode extends Node implements Runnable{
    
    public RingNode(Node n){
	super();
	this.id = n.id;
	this.network = n.network;
	this.graphicalRep = n.graphicalRep;
        this.failed = n.failed;
    }


   public void run(){
       ;
    }   
}


and this is a bullyNode.java
/*
  Distributed Systems: Practical Exercise 
  
  Implementation of the bully election algorithm should be provided in 
  this class.
  Do not alter the constructor. 
  Complete the run method of this class. 
  
*/

public class BullyNode extends Node implements Runnable{
    final static int transmission_delay = 1000;
    final static int node_delay = 3000;
   
    public BullyNode(Node n){
        super();
	this.id = n.id;
	this.network = n.network;
	this.graphicalRep = n.graphicalRep;
	this.failed = n.failed;
    }

    public void run(){
	;
    }
}



Node.java
/*
  Distributed Systems: Practical Exercise 
  
  This class represent represents a general node in the network. Classes 
  RingNode and BullyNode extends this class.
  You should not change anything in this file.
  
*/


import java.awt.*;
import java.awt.geom.*;
import java.util.*;

public class Node extends Component implements Comparable{
    private final double width = 30.0;
    private final double height = 30.0;
    public  Color color = Color.blue;
    private static int NodeCount = 0;

    protected int id;
    protected boolean failed = false;

    Ellipse2D.Double graphicalRep;
    public Network network;



    public Node(){
	;
    }

    public Node(Point p, int id, Network network){
	super();
	this.id = id;
	this.network = network;
	graphicalRep = new Ellipse2D.Double(p.x, p.y, width, height);
    }

    public void receiveMessage(Message msg){
	;
    }

    public Vector neighbours(){
      Channel tempC = null;
      Vector linkedNodes = new Vector();
      for(int i = 0; i < network.getChannels().size(); i++){
         tempC = (Channel) network.getChannels().elementAt(i);
         if(tempC.getNode1().compareTo(this) == 0){
	     linkedNodes.addElement(network.getNode(tempC.getNode2()));
         }
      }
      return linkedNodes;
    }
    
    public Vector allNodes(){
	return network.getNodes();
    }

    public int getId(){
	return id;
    }



    public boolean isFailed(){
      return failed;
    }


    public void changeGraphicalState(){
	network.updateNodeGraphically(this);
    }
    

    public void discardMessage(Message msg){
	network.deleteMessage(msg);
    }


    public void setFailed(){
	failed = true;
    }

    

     public Channel getChannel(Node neighbour){
	Channel channel = null;
	for(int i = 0; i < network.getChannels().size(); i++){
	    Channel tempC = (Channel) network.getChannels().elementAt(i);
	    if(tempC.getNode1().compareTo(this) == 0 &
	       tempC.getNode2().compareTo(neighbour) == 0){
		channel = tempC;
	    }
	}
	return channel;
    }

    public void paint(Graphics g){
	Graphics2D g2 = (Graphics2D) g;
	g2.setPaint(color);
	g2.draw(graphicalRep);
	g2.setPaint(color);
	g2.fill(graphicalRep);
	g.setColor(Color.black);
	g.drawString(String.valueOf(id),
		     (int)graphicalRep.getX(),
		     (int) graphicalRep.getY());
	if(failed){
	    Rectangle rn1 = graphicalRep.getBounds();
	    Line2D.Double line1 = new Line2D.Double(rn1.x, rn1.y, 
						    rn1.x + rn1.width, 
						    rn1.y + rn1.height);
	    Line2D.Double line2 = new Line2D.Double(rn1.x + rn1.width, 
						    rn1.y, rn1.x, 
						    rn1.y + rn1.height);
	    Stroke stroke = new BasicStroke(7);
	    g2.setStroke(stroke);
	    g2.setColor(Color.black);
	    g2.draw(line1);
	    g2.draw(line2);
	    g2.setStroke(new BasicStroke());
	}
    }
    
    public int compareTo(Object o){
	Node temp = (Node) o;
	if(this.getId() < temp.getId()){ return -1;}
	else if(this.getId() == temp.getId()) { return 0;}
	else return 1;
    }
}



Please guys help me with this project and I just would like to say I am a good programmer but I was stopped java programming for about 5 years ,so I need the starter points and someone can help me not just general talking

thanks
Attached File  Election.zip (13.13K)
Number of downloads: 24
Abdullah
abdullah.albualI@gmail.com


Is This A Good Question/Topic? 0
  • +

Page 1 of 1