Permalink
Browse files

- Back-ported JGRP-1542 and JGRP-1543

- Changed version to 3.2.3
  • Loading branch information...
Bela Ban
Bela Ban committed Nov 27, 2012
1 parent 4aeff52 commit 96318863ddb455ba2dd55a843167c792e17de8e9
View
@@ -6,7 +6,7 @@
build.xml file for JGroups. Needs Ant (jakarta.apache.org) to run
</description>
- <property name="version" value="3.2.2.Final"/>
+ <property name="version" value="3.2.3.Final"/>
<property name="build.properties.file" value="build.properties"/>
<property file="${build.properties.file}"/>
<property name="root.dir" value="${basedir}"/>
View
@@ -5,7 +5,7 @@
<artifactId>jgroups</artifactId>
<packaging>bundle</packaging>
<name>JGroups</name>
- <version>3.2.2.Final</version>
+ <version>3.2.3.Final</version>
<url>http://www.jgroups.org</url>
<description>
Reliable cluster communication toolkit
@@ -26,24 +26,24 @@
* @author Bela Ban
*/
public class Message implements Streamable {
- protected Address dest_addr;
- protected Address src_addr;
+ protected Address dest_addr;
+ protected Address src_addr;
/** The payload */
- private byte[] buf;
+ protected byte[] buf;
/** The index into the payload (usually 0) */
- protected int offset;
+ protected int offset;
/** The number of bytes in the buffer (usually buf.length is buf not equal to null). */
- protected int length;
+ protected int length;
/** All headers are placed here */
- protected Headers headers;
+ protected Headers headers;
- private volatile short flags;
+ protected volatile short flags;
- private volatile byte transient_flags; // transient_flags is neither marshalled nor copied
+ protected volatile byte transient_flags; // transient_flags is neither marshalled nor copied
protected static final Log log=LogFactory.getLog(Message.class);
@@ -208,21 +208,14 @@ public Message(boolean create_headers) {
headers=createHeaders(3);
}
- public Address getDest() {
- return dest_addr;
- }
-
- public void setDest(Address new_dest) {
- dest_addr=new_dest;
- }
-
- public Address getSrc() {
- return src_addr;
- }
-
- public void setSrc(Address new_src) {
- src_addr=new_src;
- }
+ public Address getDest() {return dest_addr;}
+ public Address dest() {return dest_addr;}
+ public void setDest(Address new_dest) {dest_addr=new_dest;}
+ public Message dest(Address new_dest) {dest_addr=new_dest; return this;}
+ public Address getSrc() {return src_addr;}
+ public Address src() {return src_addr;}
+ public void setSrc(Address new_src) {src_addr=new_src;}
+ public Message src(Address new_src) {src_addr=new_src; return this;}
/**
* Returns a <em>reference</em> to the payload (byte buffer). Note that this buffer should not be
@@ -576,15 +569,23 @@ public Message copy(boolean copy_buffer, boolean copy_headers) {
* @return A message with headers whose ID are >= starting_id
*/
public Message copy(boolean copy_buffer, short starting_id) {
+ return copy(copy_buffer, starting_id, (short[])null);
+ }
+
+ /**
+ * Copies a message. Copies only headers with IDs >= starting_id or IDs which are in the copy_only_ids list
+ * @param copy_buffer
+ * @param starting_id
+ * @param copy_only_ids
+ * @return
+ */
+ public Message copy(boolean copy_buffer, short starting_id, short ... copy_only_ids) {
Message retval=copy(copy_buffer, false);
- if(starting_id > 0) {
- for(Map.Entry<Short,Header> entry: getHeaders().entrySet()) {
- short id=entry.getKey();
- if(id >= starting_id)
- retval.putHeader(id, entry.getValue());
- }
+ for(Map.Entry<Short,Header> entry: getHeaders().entrySet()) {
+ short id=entry.getKey();
+ if(id >= starting_id || containsId(id, copy_only_ids))
+ retval.putHeader(id, entry.getValue());
}
-
return retval;
}
@@ -676,7 +677,7 @@ public void writeTo(DataOutput out) throws Exception {
// 1. write the leading byte first
out.write(leading);
- // 2. the flags (e.g. OOB, LOW_PRIO)
+ // 2. the flags (e.g. OOB, LOW_PRIO), skip the transient flags
out.writeShort(flags);
// 3. dest_addr
@@ -891,14 +892,24 @@ public String transientFlagsToString() {
return sb.toString();
}
- private static void writeHeader(Header hdr, DataOutput out) throws Exception {
+ protected static void writeHeader(Header hdr, DataOutput out) throws Exception {
short magic_number=ClassConfigurator.getMagicNumber(hdr.getClass());
out.writeShort(magic_number);
hdr.writeTo(out);
}
- private static Header readHeader(DataInput in) throws Exception {
+ protected static boolean containsId(short id, short[] ids) {
+ if(ids == null)
+ return false;
+ for(short tmp: ids)
+ if(tmp == id)
+ return true;
+ return false;
+ }
+
+
+ protected static Header readHeader(DataInput in) throws Exception {
short magic_number=in.readShort();
Class clazz=ClassConfigurator.get(magic_number);
if(clazz == null)
@@ -909,12 +920,12 @@ private static Header readHeader(DataInput in) throws Exception {
return hdr;
}
- private static Headers createHeaders(int size) {
+ protected static Headers createHeaders(int size) {
return size > 0? new Headers(size) : new Headers(3);
}
- private static Headers createHeaders(Headers m) {
+ protected static Headers createHeaders(Headers m) {
return new Headers(m);
}
@@ -21,8 +21,8 @@
public class Version {
public static final short major = 3;
public static final short minor = 2;
- public static final short micro = 2;
- public static final String description="3.2.2.Final";
+ public static final short micro = 3;
+ public static final String description="3.2.3.Final";
public static final short version=encode(major, minor, micro);
public static final String string_version=print(version);
@@ -478,6 +478,76 @@ public void channelClosed(Channel channel) {
/* ----------------------------------------------------------------------- */
+ protected Object handleUpEvent(Event evt) throws Exception {
+ switch(evt.getType()) {
+ case Event.MSG:
+ if(msg_listener != null)
+ msg_listener.receive((Message) evt.getArg());
+ break;
+
+ case Event.GET_APPLSTATE: // reply with GET_APPLSTATE_OK
+ byte[] tmp_state=null;
+ if(msg_listener != null) {
+ ByteArrayOutputStream output=new ByteArrayOutputStream(1024);
+ msg_listener.getState(output);
+ tmp_state=output.toByteArray();
+ }
+ return new StateTransferInfo(null, 0L, tmp_state);
+
+ case Event.GET_STATE_OK:
+ if(msg_listener != null) {
+ StateTransferResult result=(StateTransferResult)evt.getArg();
+ ByteArrayInputStream input=new ByteArrayInputStream(result.getBuffer());
+ msg_listener.setState(input);
+ }
+ break;
+
+ case Event.STATE_TRANSFER_OUTPUTSTREAM:
+ OutputStream os=(OutputStream)evt.getArg();
+ if(msg_listener != null && os != null) {
+ msg_listener.getState(os);
+ }
+ break;
+
+ case Event.STATE_TRANSFER_INPUTSTREAM:
+ InputStream is=(InputStream)evt.getArg();
+ if(msg_listener != null && is!=null)
+ msg_listener.setState(is);
+ break;
+
+ case Event.VIEW_CHANGE:
+ View v=(View) evt.getArg();
+ List<Address> new_mbrs=v.getMembers();
+ setMembers(new_mbrs);
+ if(membership_listener != null)
+ membership_listener.viewAccepted(v);
+ break;
+
+ case Event.SET_LOCAL_ADDRESS:
+ if(log.isTraceEnabled())
+ log.trace("setting local_addr (" + local_addr + ") to " + evt.getArg());
+ local_addr=(Address)evt.getArg();
+ break;
+
+ case Event.SUSPECT:
+ if(membership_listener != null)
+ membership_listener.suspect((Address) evt.getArg());
+ break;
+
+ case Event.BLOCK:
+ if(membership_listener != null)
+ membership_listener.block();
+ break;
+ case Event.UNBLOCK:
+ if(membership_listener != null)
+ membership_listener.unblock();
+ break;
+ }
+
+ return null;
+ }
+
+
class MyProbeHandler implements DiagnosticsHandler.ProbeHandler {
public Map<String,String> handleProbe(String... keys) {
@@ -520,82 +590,6 @@ public String getName() {
}
-
- protected Object handleUpEvent(Event evt) throws Exception {
- switch(evt.getType()) {
- case Event.MSG:
- if(msg_listener != null) {
- msg_listener.receive((Message) evt.getArg());
- }
- break;
-
- case Event.GET_APPLSTATE: // reply with GET_APPLSTATE_OK
- byte[] tmp_state=null;
- if(msg_listener != null) {
- ByteArrayOutputStream output=new ByteArrayOutputStream(1024);
- msg_listener.getState(output);
- tmp_state=output.toByteArray();
- }
- return new StateTransferInfo(null, 0L, tmp_state);
-
- case Event.GET_STATE_OK:
- if(msg_listener != null) {
- StateTransferResult result=(StateTransferResult)evt.getArg();
- ByteArrayInputStream input=new ByteArrayInputStream(result.getBuffer());
- msg_listener.setState(input);
- }
- break;
-
- case Event.STATE_TRANSFER_OUTPUTSTREAM:
- OutputStream os=(OutputStream)evt.getArg();
- if(msg_listener != null && os != null) {
- msg_listener.getState(os);
- }
- break;
-
- case Event.STATE_TRANSFER_INPUTSTREAM:
- InputStream is=(InputStream)evt.getArg();
- if(msg_listener != null && is!=null)
- msg_listener.setState(is);
- break;
-
- case Event.VIEW_CHANGE:
- View v=(View) evt.getArg();
- List<Address> new_mbrs=v.getMembers();
- setMembers(new_mbrs);
- if(membership_listener != null)
- membership_listener.viewAccepted(v);
- break;
-
- case Event.SET_LOCAL_ADDRESS:
- if(log.isTraceEnabled())
- log.trace("setting local_addr (" + local_addr + ") to " + evt.getArg());
- local_addr=(Address)evt.getArg();
- break;
-
- case Event.SUSPECT:
- if(membership_listener != null)
- membership_listener.suspect((Address) evt.getArg());
- break;
-
- case Event.BLOCK:
- if(membership_listener != null)
- membership_listener.block();
- break;
- case Event.UNBLOCK:
- if(membership_listener != null)
- membership_listener.unblock();
- break;
- }
-
- return null;
- }
-
-
-
-
-
-
/**
* Called by channel (we registered before) when event is received. This is the UpHandler interface.
*/
@@ -252,7 +252,7 @@ public boolean receive(Event evt) {
SiteMaster site_master=(SiteMaster)evt.getArg();
short site=site_master.getSite();
setSiteUnreachable(site);
- return true;
+ break; // let others have a stab at this event, too
}
return false;
}
@@ -12,6 +12,7 @@
import java.io.DataOutput;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
/**
* Forwards a message to the current coordinator. When the coordinator changes, forwards all pending messages to
@@ -43,7 +44,7 @@
protected volatile Address local_addr;
/** ID to be used to identify forwarded messages. Wrap-around shouldn't be an issue. */
- protected long current_id=0;
+ protected final AtomicLong current_id=new AtomicLong(0);
protected final ForwardQueue fwd_queue=new ForwardQueue(log);
@@ -58,8 +59,10 @@ public FORWARD_TO_COORD() {
@ManagedAttribute(description="Number of messages for which no ack has been received yet")
- public int getPendingMessages() {return fwd_queue.size();}
- public List<Integer> providedUpServices() {return Arrays.asList(Event.FORWARD_TO_COORD);}
+ public int getForwardTableSize() {return fwd_queue.size();}
+ @ManagedAttribute(description="Total number of all seqnos maintained for all receivers")
+ public int getDeliveryTableSize() {return fwd_queue.deliveryTableSize();}
+ public List<Integer> providedUpServices() {return Arrays.asList(Event.FORWARD_TO_COORD);}
public void start() throws Exception {
super.start();
@@ -152,7 +155,7 @@ public Object up(Event evt) {
- protected synchronized long getNextId() {return current_id++;}
+ protected long getNextId() {return current_id.incrementAndGet();}
protected void handleViewChange(View view) {
@@ -220,7 +220,7 @@
/** Enable bundling for unicast messages. Ignored if enable_bundling is off */
@Property(description="Enable bundling of smaller messages into bigger ones for unicast messages. Default is false")
- protected boolean enable_unicast_bundling=false;
+ protected boolean enable_unicast_bundling=true;
@Property(description="Switch to enable diagnostic probing. Default is true")
protected boolean enable_diagnostics=true;
Oops, something went wrong.

0 comments on commit 9631886

Please sign in to comment.