Permalink
Browse files

- Made ViewId mandatory in View

- Removed implementation of Cloneable.clone() (replaced with copy())
  • Loading branch information...
1 parent 16844ce commit 27207672c1af40b93bf46fab5885e8b013861acf Bela Ban committed Oct 21, 2011
@@ -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;
@@ -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);
@@ -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
*
@@ -67,23 +67,15 @@ public MergeView(Address creator, long id, List<Address> members, List<View> sub
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);
@@ -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);
}
View
@@ -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() {
}
@@ -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;}
/**
@@ -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();
}
/**
@@ -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();
}
/**
@@ -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);
@@ -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));
}
@@ -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
@@ -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);
}
/**
@@ -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);
}
@@ -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());
}
}
@@ -217,7 +217,7 @@ public int size() {
return tmp_size;
}
- public Object clone() throws CloneNotSupportedException {
+ public IpAddress copy() {
return new IpAddress(ip_addr, port);
}
@@ -272,7 +272,7 @@ public int size() {
return SIZE;
}
- public Object clone() throws CloneNotSupportedException {
+ public UUID copy() {
return new UUID(mostSigBits, leastSigBits);
}
@@ -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);
Oops, something went wrong.

0 comments on commit 2720767

Please sign in to comment.