15,16c15,16
<     private ViewId            view_id=null;
< 
---
>     private ViewId            view_id=null, old_view=null;
>     private long              highest_vid=0;   // Highest view_id.id seen so far
18d17
< 
39a39,43
>     private void SendJoinOneway(Object dest, Oid addr) throws Exception {
> 	RemoteMethodCall call=new RemoteMethodCall(host, "Join", addr);
> 	call.Send(dest, true, 0); // oneway
>     }
> 
46a51,56
>     private void SendLeaveOneway(Object dest, Oid addr) throws Exception {
> 	RemoteMethodCall call=new RemoteMethodCall(host, "Leave", addr);
> 	call.Send(dest, true, 0);  // oneway
>     }
> 
> 
83a94
>     private long Max(long x, long y) {return x > y ? x : y;}
84a96,101
>     /** Return the highest VID seen so far, incremented by 1 */
>     private void Increment(ViewId vid) {
> 	long new_vid=Max(vid.GetId(), highest_vid);
> 	vid.SetId(++new_vid);
> 	highest_vid=new_vid; Util.Print("Increment(): highest_vid is " + highest_vid);
>     }
108c125
<     public void Start() {
---
>     public synchronized void Start() {
114c131,133
< 	System.out.println("GmsImpl.Start(): my address is " + local_addr);
---
> 	Util.Print("\n----------------------------------------------------------\n" +
> 		   "GmsImpl.Start(): my address is " + local_addr + 
> 		   "\n----------------------------------------------------------");
116a136
> 	old_view=view_id.Copy();        // initial copy
126a147,148
> 	    initial_members.Sort(); // So I reach the current coord first
> 	    initial_members.Remove(local_addr);
135d156
< 		initial_members.Remove(local_addr);
167c188,189
< 	Boolean retval=null;
---
> 	Boolean  retval=null;
> 	Oid      coord;
169c191
< 	// Util.Print("Received Join(" + new_member + "), role=" + role);
---
> 	Util.Print("Received JOIN request(" + new_member + ")");
179,180c201,203
< 	if(!IsCoordinator()) {  // Non-Coordinator
< 	    Oid coord;
---
> 	if(IsCoordinator()) {  // Coordinator
> 
> 	    Util.Print("I am the coord, handling JOIN request...");
181a205,219
> 	    Increment(view_id);
> 	    if(!local_addr.equals(view_id.GetCoordAddress()))
> 		view_id.SetCoordAddress(local_addr);
> 	    members.Add(new_member);
> 	    try {
> 		Util.Print("** casting ViewChange: " + view_id + ":");
> 		CastViewChange();
> 		return true;
> 	    }
> 	    catch(Exception e) {
> 		System.err.println(e);
> 		return false;
> 	    }
> 	}
> 	else {       // Not Coordinator
184,185c222
< 		Util.Print("I am NOT the coordinator; " + coord + " is it; " +
< 			   "forwarding Join request to " + coord);
---
> 		Util.Print("Forwarding Join request to " + coord);
189,190c226,240
< 		    view_id=new ViewId(local_addr, view_id.GetId());  // coordinator change !
< 		    return Join(new_member);
---
> 		    view_id.SetCoordAddress(local_addr);
> 
>  		    try {
>  			SendJoinOneway(coord, new_member);
>  			return true;
>  		    }		    
>  		    catch(Exception e) {
>  			System.err.println(e);
>  			return false;
>  		    }
> 
> 
> 		    // return Join(new_member);
> 
> 
209,224d258
< 	else {       // Coordinator
< 	    view_id.Increment(); // this is the new view
< 
< 	    if(!local_addr.equals(view_id.GetCoordAddress()))
< 		view_id=new ViewId(local_addr, view_id.GetId());
< 
< 	    members.Add(new_member);
< 	    try {
< 		CastViewChange();
< 		return true;
< 	    }
< 	    catch(Exception e) {
< 		System.err.println(e);
< 		return false;
< 	    }
< 	}
237c271,272
< 	Boolean retval=null;
---
> 	Boolean  retval=null;
> 	Oid      coord;
249c284,286
< 	    view_id.Increment();
---
> 
> 	    Increment(view_id);
> 	    
251c288
< 		view_id=new ViewId(local_addr, view_id.GetId());
---
> 		view_id.SetCoordAddress(local_addr);
254a292
> 		Util.Print("** casting ViewChange: " + view_id + ":");
264,265d301
< 	    Oid coord;
< 	    
268,269c304
< 		Util.Print("I am NOT the coordinator; " + coord + " is it; " +
< 			   "forwarding Leave request to " + coord);
---
> 		Util.Print("Forwarding Leave request to " + coord);
273c308,322
< 		    return Leave(addr);
---
> 		    view_id.SetCoordAddress(local_addr);
> 		    
> 
> 		    try {
> 			SendLeaveOneway(coord, addr);
> 			return true;
> 		    }
> 		    catch(Exception e) {
> 			System.err.println(e);
> 			return false;
> 		    }
> 		    
> 
> 		    //return Leave(addr);
> 		    
298c347
<     public synchronized void ViewChange(ViewId id, Vector mems) {
---
>     public synchronized void ViewChange(ViewId new_view, Vector mems) {
300,301c349,364
< 	
< 	Util.Print("GmsImpl.ViewChange: ID=" + id + ", members=" + mems);
---
> 
> 	highest_vid=Max(new_view.GetId(), highest_vid);
> 
> 	int rc=new_view.Compare(old_view);  // rc should always be a positive number
> 
> 
> 	Util.Print("\nOld view_id is " + old_view);
> 	// Util.Print("GmsImpl.ViewChange: ID=" + new_view + ", members=" + mems);
> 	Util.Print("==> VIEW is " + new_view);
> 	Util.Print("Comparison: " + rc + "\n");
> 
> 	if(rc <= 0) {
> 	    Util.Print("ViewChange, rc is " + rc);
> 	    Util.DumpStack(true);
> 	}
> 
306c369,374
< 	if(role == CLIENT_ROLE)
---
> 	if(role == CLIENT_ROLE) {
> 	    view_id.SetCoordAddress(new_view.GetCoordAddress());
> 	    view_id.SetId(new_view.GetId());
> 	    
> 	    old_view=view_id.Copy();
> 	    
307a376
> 	}
311,312d379
< 	    // Util.Print("coord=" + coord);
< 	    
316,321c383,393
< 	    
< 	    if(coord != null && local_addr.equals(coord) &&    // I'm coord
< 	       !local_addr.equals(id.GetCoordAddress())) {     // but that's not what view says !
< 		members.Merge(mems);
< 		try {
< 		    CastMerge();
---
> 
> 
> 	    if(coord != null && local_addr.equals(coord)) {  // coordinator
> 		if(!local_addr.equals(new_view.GetCoordAddress())) {
> 		    members.Merge(mems);
> 		    try {
> 			CastMerge();
> 		    }
> 		    catch(Exception e) {
> 			System.err.println(e);
> 		    }
323,324c395,399
< 		catch(Exception e) {
< 		    System.err.println(e);
---
> 		else {
> 		    view_id.SetCoordAddress(new_view.GetCoordAddress());
> 		    view_id.SetId(new_view.GetId());		    
> 		    old_view=view_id.Copy();		    
> 		    members.Set(mems);
327,328c402,405
< 	    else {		
< 		view_id=id;	
---
> 	    else {                                           // not coordinator
> 		view_id.SetCoordAddress(new_view.GetCoordAddress());
> 		view_id.SetId(new_view.GetId());		
> 		old_view=view_id.Copy();		
330a408
> 
341c419
< 	if(connecting) {
---
> 	if(connecting)
343,344d420
< 	    notifyAll();
< 	}
345a422,423
> 
> 
