Skip to content

Commit

Permalink
- Made ViewId mandatory in View
Browse files Browse the repository at this point in the history
- Removed implementation of Cloneable.clone() (replaced with copy())
  • Loading branch information
belaban committed Oct 21, 2011
1 parent 16844ce commit 2720767
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 144 deletions.
2 changes: 1 addition & 1 deletion src/org/jgroups/Address.java
Expand Up @@ -16,7 +16,7 @@
* @see PhysicalAddress
* @see UUID
*/
public interface Address extends Streamable, Comparable<Address>, Cloneable {
public interface Address extends Streamable, Comparable<Address> {
// flags used for marshalling
public static final byte NULL = 1 << 0;
public static final byte UUID_ADDR = 1 << 1;
Expand Down
11 changes: 2 additions & 9 deletions src/org/jgroups/Membership.java
Expand Up @@ -15,7 +15,7 @@
* @since 2.0
* @author Bela Ban
*/
public class Membership implements Cloneable {
public class Membership {
/* private vector to hold all the addresses */
private final List<Address> members=new LinkedList<Address>();
protected static final Log log=LogFactory.getLog(Membership.class);
Expand Down Expand Up @@ -212,17 +212,10 @@ public void sort() {
* @return an exact copy of this membership
*/
public Membership copy() {
return ((Membership)clone());
}


/**
* Returns a clone of this object. The list of members is copied to a new container
*/
public Object clone() {
return new Membership(this.members);
}


/**
* Returns the number of addresses in this membership
*
Expand Down
16 changes: 4 additions & 12 deletions src/org/jgroups/MergeView.java
Expand Up @@ -67,23 +67,15 @@ public List<View> getSubgroups() {
return subgroups;
}

/**
* Creates a copy of this view
*
* @return a copy of this view
*/
public Object clone() {
ViewId vid2=vid != null ? (ViewId)vid.clone() : null;

public View copy() {
ViewId vid2=vid.copy();
List<Address> members2=members != null ? new ArrayList<Address>(members) : null;
List<View> subgroups2=subgroups != null ? new ArrayList<View>(subgroups) : null;
return new MergeView(vid2, members2, subgroups2);
}


public View copy() {
return (MergeView)clone();
}


public String toString() {
StringBuilder sb=new StringBuilder();
sb.append("MergeView::").append(super.toString()).append(", subgroups=").append(subgroups);
Expand Down
4 changes: 0 additions & 4 deletions src/org/jgroups/Message.java
Expand Up @@ -516,10 +516,6 @@ public Message copy(boolean copy_buffer, short starting_id) {
}


protected Object clone() throws CloneNotSupportedException {
return copy();
}

public Message makeReply() {
return new Message(src_addr);
}
Expand Down
71 changes: 14 additions & 57 deletions src/org/jgroups/View.java
Expand Up @@ -18,26 +18,26 @@
* @since 2.0
* @author Bela Ban
*/
public class View implements Cloneable, Streamable, Iterable<Address> {
public class View implements Streamable, Iterable<Address> {

/**
* A view is uniquely identified by its ViewID. The view id contains the creator address and a
* Lamport time. The Lamport time is the highest timestamp seen or sent from a view. if a view
* change comes in with a lower Lamport time, the event is discarded.
*/
protected ViewId vid=null;
protected ViewId vid;

/**
* A list containing all the members of the view.This list is always ordered, with the
* coordinator being the first member. the second member will be the new coordinator if the
* current one disappears or leaves the group.
*/
protected List<Address> members=null;
protected List<Address> members;



/**
* Creates an empty view, should not be used
* Creates an empty view, should not be used, only used by (de-)serialization
*/
public View() {
}
Expand Down Expand Up @@ -72,10 +72,7 @@ public View(Address creator, long id, List<Address> members) {
*
* @return the view ID of this view
*/
public ViewId getVid() {
return vid;
}

public ViewId getVid() {return vid;}
public ViewId getViewId() {return vid;}

/**
Expand All @@ -85,7 +82,7 @@ public ViewId getVid() {
* @return the creator of this view in form of an Address object
*/
public Address getCreator() {
return vid != null ? vid.getCoordAddress() : null;
return vid.getCoordAddress();
}

/**
Expand Down Expand Up @@ -114,24 +111,13 @@ public boolean containsMember(Address mbr) {
public boolean equals(Object obj) {
if(!(obj instanceof View))
return false;
if(vid != null) {
int rc=vid.compareTo(((View)obj).vid);
if(rc != 0)
return false;
if(members != null && ((View)obj).members != null) {
return members.equals(((View)obj).members);
}
}
else {
if(((View)obj).vid == null)
return true;
}
return false;
int rc=vid.compareTo(((View)obj).vid);
return rc == 0 && members != null && ((View)obj).members != null && members.equals(((View)obj).members);
}


public int hashCode() {
return vid != null? vid.hashCode() : 0;
return vid.hashCode();
}

/**
Expand All @@ -145,20 +131,10 @@ public int size() {


public View copy() {
ViewId vid2=vid != null ? (ViewId)vid.clone() : null;
return new View(vid2, new ArrayList<Address>(members));
return new View(vid.copy(), new ArrayList<Address>(members));
}


/**
* Creates a copy of this view
* @return a copy of this view
*/
public Object clone() {
ViewId vid2=vid != null ? (ViewId)vid.clone() : null;
return new View(vid2, new ArrayList<Address>(members));
}


public String toString() {
StringBuilder ret=new StringBuilder(64);
Expand All @@ -169,38 +145,19 @@ public String toString() {


public void writeTo(DataOutput out) throws Exception {
// vid
if(vid != null) {
out.writeBoolean(true);
vid.writeTo(out);
}
else
out.writeBoolean(false);

// members:
vid.writeTo(out);
Util.writeAddresses(members, out);
}

@SuppressWarnings("unchecked")
public void readFrom(DataInput in) throws Exception {
boolean b;
// vid:
b=in.readBoolean();
if(b) {
vid=new ViewId();
vid.readFrom(in);
}

// members:
vid=new ViewId();
vid.readFrom(in);
members=(List<Address>)Util.readAddresses(in, ArrayList.class);
}

public int serializedSize() {
int retval=Global.BYTE_SIZE; // presence for vid
if(vid != null)
retval+=vid.serializedSize();
retval+=Util.size(members);
return retval;
return (int)(vid.serializedSize() + Util.size(members));
}


Expand Down
14 changes: 2 additions & 12 deletions src/org/jgroups/ViewId.java
Expand Up @@ -12,7 +12,7 @@
* Ordering between views is important for example in a virtual synchrony protocol where
* all views seen by a member have to be ordered.
*/
public class ViewId implements Comparable, Cloneable, Streamable {
public class ViewId implements Comparable, Streamable {
Address coord_addr=null; // Address of the issuer of this view
long id=0; // Lamport time of the view

Expand Down Expand Up @@ -65,19 +65,9 @@ public String toString() {
return "[" + coord_addr + '|' + id + ']';
}

/**
* Cloneable interface
* Returns a new ViewID object containing the same address and lamport timestamp as this view
*/
public Object clone() {
return new ViewId(coord_addr, id);
}

/**
* Old Copy method, deprecated because it is substituted by clone()
*/
public ViewId copy() {
return (ViewId)clone();
return new ViewId(coord_addr, id);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/org/jgroups/protocols/pbcast/GMS.java
Expand Up @@ -341,14 +341,18 @@ public void start() throws Exception {
if(merge_killer_interval > 0) {
merge_killer=timer.scheduleWithFixedDelay(new Runnable() {
public void run() {
long timestamp=merger.getMergeIdTimestamp();
if(timestamp > 0) {
long diff=System.currentTimeMillis() - timestamp;
if(diff >= merge_kill_timeout) {
if(merger.forceCancelMerge())
log.warn("force-cancelled merge task after " + diff + " ms");
try {
long timestamp=merger.getMergeIdTimestamp();
if(timestamp > 0) {
long diff=System.currentTimeMillis() - timestamp;
if(diff >= merge_kill_timeout) {
if(merger.forceCancelMerge())
log.warn("force-cancelled merge task after " + diff + " ms");
}
}
}
catch(Throwable t) {
}
}
},merge_killer_interval,merge_killer_interval, TimeUnit.MILLISECONDS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/pbcast/Merger.java
Expand Up @@ -699,7 +699,7 @@ private MergeData consolidateMergeData(List<MergeData> merge_rsps) {
}
// merge all membership lists into one (prevent duplicates)
new_mbrs.add(tmp_view.getMembers());
subgroups.add((View)tmp_view.clone());
subgroups.add(tmp_view.copy());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/stack/IpAddress.java
Expand Up @@ -217,7 +217,7 @@ public int size() {
return tmp_size;
}

public Object clone() throws CloneNotSupportedException {
public IpAddress copy() {
return new IpAddress(ip_addr, port);
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/util/UUID.java
Expand Up @@ -272,7 +272,7 @@ public int size() {
return SIZE;
}

public Object clone() throws CloneNotSupportedException {
public UUID copy() {
return new UUID(mostSigBits, leastSigBits);
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ public void testConstructor() {
public void testClone() {
v1=Arrays.asList(a1, a2, a3);
m2=new Membership(v1);
m1=(Membership)m2.clone();
m1=m2.copy();
assert m1.size() == m2.size();
assert m1.contains(a1);
assert m1.contains(a2);
Expand Down

0 comments on commit 2720767

Please sign in to comment.