Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Made ViewId mandatory in View

- Removed implementation of Cloneable.clone() (replaced with copy())
  • Loading branch information...
commit 27207672c1af40b93bf46fab5885e8b013861acf 1 parent 16844ce
@belaban authored
View
2  src/org/jgroups/Address.java
@@ -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;
View
11 src/org/jgroups/Membership.java
@@ -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
*
View
16 src/org/jgroups/MergeView.java
@@ -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);
View
4 src/org/jgroups/Message.java
@@ -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
71 src/org/jgroups/View.java
@@ -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));
}
View
14 src/org/jgroups/ViewId.java
@@ -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);
}
/**
View
16 src/org/jgroups/protocols/pbcast/GMS.java
@@ -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);
}
View
2  src/org/jgroups/protocols/pbcast/Merger.java
@@ -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());
}
}
View
2  src/org/jgroups/stack/IpAddress.java
@@ -217,7 +217,7 @@ public int size() {
return tmp_size;
}
- public Object clone() throws CloneNotSupportedException {
+ public IpAddress copy() {
return new IpAddress(ip_addr, port);
}
View
2  src/org/jgroups/util/UUID.java
@@ -272,7 +272,7 @@ public int size() {
return SIZE;
}
- public Object clone() throws CloneNotSupportedException {
+ public UUID copy() {
return new UUID(mostSigBits, leastSigBits);
}
View
2  tests/junit-functional/org/jgroups/tests/MembershipTest.java
@@ -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);
View
52 tests/junit-functional/org/jgroups/tests/SizeTest.java
@@ -167,7 +167,7 @@ public static void testFdHeaders() throws Exception {
IpAddress a1=new IpAddress("127.0.0.1", 5555);
IpAddress a2=new IpAddress("127.0.0.1", 6666);
- Vector<Address> suspects=new Vector<Address>();
+ List<Address> suspects=new ArrayList<Address>();
suspects.add(a1);
suspects.add(a2);
hdr=new FD.FdHeader(FD.FdHeader.SUSPECT, suspects, a1);
@@ -186,7 +186,7 @@ public static void testFdHeaders() throws Exception {
_testSize(sockhdr);
- Map<Address,IpAddress> cache=new Hashtable<Address,IpAddress>();
+ Map<Address,IpAddress> cache=new HashMap<Address,IpAddress>();
cache.put(a1, a2);
cache.put(a2, a1);
sockhdr=new FD_SOCK.FdHeader(FD_SOCK.FdHeader.SUSPECT, cache);
@@ -209,7 +209,7 @@ public static void testFdSockHeaders() throws Exception {
hdr=new FD_SOCK.FdHeader(FD_SOCK.FdHeader.GET_CACHE, set);
_testSize(hdr);
- Hashtable<Address,IpAddress> map=new Hashtable<Address,IpAddress>();
+ Map<Address,IpAddress> map=new HashMap<Address,IpAddress>();
map.put(new IpAddress("127.0.0.1", 5000), new IpAddress(4553));
map.put(new IpAddress("127.0.0.1", 6000), new IpAddress(4523));
map.put(new IpAddress(7000), new IpAddress(4553));
@@ -331,7 +331,7 @@ public static void testSequencerHeader() throws Exception {
public static void testAddressVector() throws Exception {
- Vector<Address> v=new Vector<Address>();
+ List<Address> v=new ArrayList<Address>();
_testSize(v);
v.add(new IpAddress(1111));
_testSize(v);
@@ -379,27 +379,27 @@ public static void testMergeId() throws Exception {
public static void testView() throws Exception {
- View v=new View();
+ Address one=Util.createRandomAddress("A");
+ ViewId vid=new ViewId(one, 322649);
+ List<Address> mbrs=new ArrayList<Address>();
+ mbrs.add(one);
+ View v=new View(vid, mbrs);
_testSize(v);
-
- ViewId vid=new ViewId(UUID.randomUUID(), 322649);
- Vector<Address> mbrs=new Vector<Address>();
+
+ mbrs.add(Util.createRandomAddress("B"));
v=new View(vid, mbrs);
_testSize(v);
- mbrs.add(UUID.randomUUID());
- _testSize(v);
- mbrs.add(UUID.randomUUID());
+
+ mbrs.add(Util.createRandomAddress("C"));
+ v=new View(vid, mbrs);
_testSize(v);
}
public static void testMergeView() throws Exception {
- View v=new MergeView();
- _testSize(v);
-
ViewId vid=new ViewId(UUID.randomUUID(), 322649);
- Vector<Address> mbrs=new Vector<Address>();
- v=new MergeView(vid, mbrs, null);
+ List<Address> mbrs=new ArrayList<Address>();
+ View v=new MergeView(vid, mbrs, null);
_testSize(v);
mbrs.add(UUID.randomUUID());
_testSize(v);
@@ -410,8 +410,8 @@ public static void testMergeView() throws Exception {
public static void testMergeView2() throws Exception {
- Vector<Address> m1, m2 , m3, all;
- Vector<View> subgroups;
+ List<Address> m1, m2 , m3, all;
+ List<View> subgroups;
Address a,b,c,d,e,f;
View v1, v2, v3, view_all;
@@ -422,8 +422,8 @@ public static void testMergeView2() throws Exception {
e=Util.createRandomAddress();
f=Util.createRandomAddress();
- m1=new Vector<Address>(); m2=new Vector<Address>(); m3=new Vector<Address>(); all=new Vector<Address>();
- subgroups=new Vector<View>();
+ m1=new ArrayList<Address>(); m2=new ArrayList<Address>(); m3=new ArrayList<Address>(); all=new ArrayList<Address>();
+ subgroups=new ArrayList<View>();
m1.add(a); m1.add(b); m1.add(c);
m2.add(d);
m3.add(e); m3.add(f);
@@ -444,8 +444,8 @@ public static void testMergeView2() throws Exception {
public static void testMergeView3() throws Exception {
- Vector<Address> m1, m2 , m3, all;
- Vector<View> subgroups;
+ List<Address> m1, m2 , m3, all;
+ List<View> subgroups;
Address a,b,c,d,e,f;
View v1, v2, v3, v4, view_all;
@@ -456,15 +456,15 @@ public static void testMergeView3() throws Exception {
e=new IpAddress(5000);
f=new IpAddress(6000);
- m1=new Vector<Address>(); m2=new Vector<Address>(); m3=new Vector<Address>(); all=new Vector<Address>();
- subgroups=new Vector<View>();
+ m1=new ArrayList<Address>(); m2=new ArrayList<Address>(); m3=new ArrayList<Address>(); all=new ArrayList<Address>();
+ subgroups=new ArrayList<View>();
m1.add(a); m1.add(b); m1.add(c);
m2.add(d);
m3.add(e); m3.add(f);
all.add(a); all.add(b); all.add(c); all.add(d); all.add(e); all.add(f);
v1=new View(a, 1, m1);
- v2=new MergeView(d, 2, m2, new Vector<View>());
+ v2=new MergeView(d, 2, m2, new ArrayList<View>());
v3=new View(e, 3, m3);
v4=new MergeView(e, 4, m3, null);
subgroups.add(v1);
@@ -523,7 +523,7 @@ public static void testGmsHeader() throws Exception {
GMS.GmsHeader hdr=new GMS.GmsHeader(GMS.GmsHeader.JOIN_REQ, addr);
_testSize(hdr);
- Vector<Address> members=new Vector<Address>();
+ List<Address> members=new ArrayList<Address>();
members.add(addr);
members.add(addr);
View v=new View(addr, 33, members);
View
4 tests/junit-functional/org/jgroups/tests/ViewIdTest.java
@@ -20,7 +20,7 @@
public void setUp() throws UnknownHostException {
v1=new ViewId(Util.createRandomAddress(), 22);
v2=new ViewId(Util.createRandomAddress(), 21);
- v3=(ViewId)v1.clone();
+ v3=v1.copy();
}
@@ -34,7 +34,7 @@ public void test1() {
public void test2() {
- ViewId v4=(ViewId)v1.clone();
+ ViewId v4=v1.copy();
assert v1.equals(v4);
}
View
15 tests/junit-functional/org/jgroups/tests/ViewTest.java
@@ -10,14 +10,14 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Vector;
@Test(groups=Global.FUNCTIONAL)
public class ViewTest {
- Address a, b, c, d, e, f, g, h, i, j, k;
+ Address a, b, c, d, e, f, g, h, i;
View view;
List<Address> members;
@@ -61,19 +61,14 @@ public void testEquals() {
}
public void testEquals2() {
- View v1=new View(new ViewId(a, 12345), new Vector<Address>(members));
- View v2=new View(a, 12345, new Vector<Address>(members));
+ View v1=new View(new ViewId(a, 12345), new ArrayList<Address>(members));
+ View v2=new View(a, 12345, new ArrayList<Address>(members));
assert v1.equals(v2);
- View v3=new View(a, 12543, new Vector<Address>(members));
+ View v3=new View(a, 12543, new ArrayList<Address>(members));
assert !v1.equals(v3);
}
- public static void testEquals3() {
- View v1=new View(), v2=new View();
- assert v1.equals(v2);
- }
-
public void testCopy() {
View view2=view.copy();
System.out.println("view = " + view);
View
11 tests/junit/org/jgroups/tests/LargeMergeTest.java
@@ -31,7 +31,7 @@
*/
@Test(groups=Global.FUNCTIONAL,sequential=true)
public class LargeMergeTest {
- static final int NUM=80; // number of members
+ static final int NUM=50; // number of members
protected final JChannel[] channels=new JChannel[NUM];
@@ -180,4 +180,13 @@ public void destroy() {
super.stop();
}
}
+
+
+ @Test(enabled=false)
+ public static void main(String args[]) throws Exception {
+ LargeMergeTest test=new LargeMergeTest();
+ test.setUp();
+ test.testClusterFormationAfterMerge();
+ test.tearDown();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.