Permalink
Browse files

Merge branch 'JGRP-1141' (typed RpcDispatcher methods)

  • Loading branch information...
2 parents 492a6dc + a310c3f commit 63307a835da0a62bf271d2991393e9a7fffbd105 Bela Ban committed May 24, 2011
Showing with 360 additions and 613 deletions.
  1. +46 −0 doc/API_Changes.txt
  2. +25 −21 src/org/jgroups/blocks/GroupRequest.java
  3. +14 −10 src/org/jgroups/blocks/MessageDispatcher.java
  4. +0 −378 src/org/jgroups/blocks/MultiRequest.java
  5. +1 −1 src/org/jgroups/blocks/ReplCache.java
  6. +1 −1 src/org/jgroups/blocks/Request.java
  7. +25 −11 src/org/jgroups/blocks/RequestCorrelator.java
  8. +1 −1 src/org/jgroups/blocks/RequestHandler.java
  9. +27 −41 src/org/jgroups/blocks/RpcDispatcher.java
  10. +1 −1 src/org/jgroups/blocks/RspCollector.java
  11. +18 −17 src/org/jgroups/blocks/UnicastRequest.java
  12. +1 −1 src/org/jgroups/blocks/mux/MuxMessageDispatcher.java
  13. +1 −1 src/org/jgroups/blocks/mux/MuxRpcDispatcher.java
  14. +10 −12 src/org/jgroups/demos/QuoteClient.java
  15. +1 −1 src/org/jgroups/demos/RelayDemoRpc.java
  16. +43 −13 src/org/jgroups/util/Rsp.java
  17. +38 −40 src/org/jgroups/util/RspList.java
  18. +2 −2 tests/junit-functional/org/jgroups/blocks/GroupRequestTest.java
  19. +1 −1 tests/junit-functional/org/jgroups/tests/RspListTest.java
  20. +2 −2 tests/junit/org/jgroups/blocks/MuxMessageDispatcherTest.java
  21. +2 −2 tests/junit/org/jgroups/blocks/MuxRpcDispatcherTest.java
  22. +4 −4 tests/junit/org/jgroups/blocks/RpcDispatcherSerializationTest.java
  23. +80 −40 tests/junit/org/jgroups/blocks/RpcDispatcherTest.java
  24. +1 −1 tests/junit/org/jgroups/tests/ChannelTestBase.java
  25. +13 −9 tests/junit/org/jgroups/tests/Deadlock2Test.java
  26. +2 −2 tests/other/org/jgroups/tests/UnicastTestRpcDist.java
View
@@ -49,6 +49,52 @@ API changes in 3.0.0
- Removed Address.isMulticastAddress(): a null address is a multicast address
+- Rsp, RspList, RpcDispatcher.callRemoteMethodsXXX() and MessageDispatcher.cast/sendXXX() methods now use
+ generics, so the code below:
+
+ RspList rsps=disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000));
+ for(Map.Entry<Address,Rsp> rsp: rsps.entrySet())
+ System.out.println(rsp.getKey() + ": " + rsp.getValue().getValue());
+
+ has to be changed to:
+
+ RspList<Date> rsps=disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000));
+ for(Map.Entry<Address,Rsp<Date>> rsp: rsps.entrySet())
+ System.out.println(rsp.getKey() + ": " + rsp.getValue().getValue());
+
+- RpcDispatcher.callRemoteMethod() now throws an exception if the target method threw an exception
+
+- RpcDispatcher.callRemoteMethods() return a RspList. If a member P threw an exception, then the Rsp for
+ P will have it in the field 'exception'. The 'result' field is *not* used for exceptions any longer !
+
+ An example to check for exceptions is:
+
+
+ Multicast:
+
+ RspList<Long> rsps=dispatcher.callRemoteMethods(null, "foo", null, null, new RequestOptions(...));
+ for(Rsp<Long> rsp: rsps.values) {
+ if(rsp.getException() != null) {
+ // we have an exception
+ }
+ else {
+ Long val=rsp.getValue();
+ // do something with the value
+ }
+ }
+
+ Unicast:
+
+ try {
+ Rsp<Long> rsp=disp.callRemoteMethod(target, "foo", null, null, new RequestOptions(...));
+ Long val=rsp.getValue();
+ // do something with the return value
+ }
+ catch(Throwable t) {
+ // "foo" threw an exception
+ }
+
+
@@ -48,11 +48,11 @@
*
* @author Bela Ban
*/
-public class GroupRequest extends Request {
+public class GroupRequest<T> extends Request {
/** Correlates requests and responses */
@GuardedBy("lock")
- private final Map<Address,Rsp> requests;
+ private final Map<Address,Rsp<T>> requests;
@GuardedBy("lock")
int num_received, num_not_received, num_suspected;
@@ -72,21 +72,21 @@
public GroupRequest(Message msg, RequestCorrelator corr, Collection<Address> targets, RequestOptions options) {
super(msg, corr, null, options);
int size=targets.size();
- requests=new HashMap<Address,Rsp>(size);
+ requests=new HashMap<Address,Rsp<T>>(size);
setTargets(targets);
}
public GroupRequest(Message m, RequestCorrelator corr, Address target, RequestOptions options) {
super(m, corr, null, options);
- requests=new HashMap<Address,Rsp>(1);
+ requests=new HashMap<Address,Rsp<T>>(1);
setTarget(target);
}
public GroupRequest(Message m, Transport transport, Collection<Address> mbrs, RequestOptions options) {
super(m, null, transport, options);
int size=mbrs.size();
- requests=new HashMap<Address,Rsp>(size);
+ requests=new HashMap<Address,Rsp<T>>(size);
setTargets(mbrs);
}
@@ -111,18 +111,22 @@ public void sendRequest() throws Exception {
* Adds a response to the response table. When all responses have been received,
* <code>execute()</code> returns.
*/
- public void receiveResponse(Object response_value, Address sender) {
+ public void receiveResponse(Object response_value, Address sender, boolean is_exception) {
if(done)
return;
- Rsp rsp=requests.get(sender);
+ Rsp<T> rsp=requests.get(sender);
if(rsp == null)
return;
RspFilter rsp_filter=options.getRspFilter();
boolean responseReceived=false;
if(!rsp.wasReceived()) {
- if((responseReceived=(rsp_filter == null) || rsp_filter.isAcceptable(response_value, sender)))
- rsp.setValue(response_value);
+ if((responseReceived=(rsp_filter == null) || rsp_filter.isAcceptable(response_value, sender))) {
+ if(is_exception && response_value instanceof Throwable)
+ rsp.setException((Throwable)response_value);
+ else
+ rsp.setValue((T)response_value);
+ }
rsp.setReceived(responseReceived);
}
@@ -155,7 +159,7 @@ public void suspect(Address suspected_member) {
return;
boolean changed=false;
- Rsp rsp=requests.get(suspected_member);
+ Rsp<T> rsp=requests.get(suspected_member);
if(rsp != null) {
if(rsp.setSuspected(true)) {
rsp.setValue(null);
@@ -204,10 +208,10 @@ public void viewChange(View new_view) {
lock.lock();
try {
- for(Map.Entry<Address,Rsp> entry: requests.entrySet()) {
+ for(Map.Entry<Address,Rsp<T>> entry: requests.entrySet()) {
Address mbr=entry.getKey();
if(!mbrs.contains(mbr)) {
- Rsp rsp=entry.getValue();
+ Rsp<T> rsp=entry.getValue();
rsp.setValue(null);
if(rsp.setSuspected(true)) {
num_suspected++;
@@ -231,14 +235,14 @@ public void viewChange(View new_view) {
/** Returns the results as a RspList */
- public RspList getResults() {
- Collection<Rsp> rsps=requests.values();
- return new RspList(rsps);
+ public RspList<T> getResults() {
+ Collection<Rsp<T>> rsps=requests.values();
+ return new RspList<T>(rsps);
}
- public RspList get() throws InterruptedException, ExecutionException {
+ public RspList<T> get() throws InterruptedException, ExecutionException {
lock.lock();
try {
waitForResults(0);
@@ -249,7 +253,7 @@ public RspList get() throws InterruptedException, ExecutionException {
return getResults();
}
- public RspList get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
+ public RspList<T> get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
boolean ok;
lock.lock();
try {
@@ -269,9 +273,9 @@ public String toString() {
if(!requests.isEmpty()) {
ret.append(", entries:\n");
- for(Map.Entry<Address,Rsp> entry: requests.entrySet()) {
+ for(Map.Entry<Address,Rsp<T>> entry: requests.entrySet()) {
Address mbr=entry.getKey();
- Rsp rsp=entry.getValue();
+ Rsp<T> rsp=entry.getValue();
ret.append(mbr).append(": ").append(rsp).append("\n");
}
}
@@ -282,13 +286,13 @@ public String toString() {
/* --------------------------------- Private Methods -------------------------------------*/
private void setTarget(Address mbr) {
- requests.put(mbr, new Rsp(mbr));
+ requests.put(mbr, new Rsp<T>(mbr));
num_not_received=1;
}
private void setTargets(Collection<Address> mbrs) {
for(Address mbr: mbrs)
- requests.put(mbr, new Rsp(mbr));
+ requests.put(mbr, new Rsp<T>(mbr));
num_not_received=requests.size();
}
@@ -236,18 +236,18 @@ else if (canReplace) {
* @return
* @since 2.9
*/
- public RspList castMessage(final Collection<Address> dests, Message msg, RequestOptions options) {
- GroupRequest req=cast(dests, msg, options, true);
+ public <T> RspList<T> castMessage(final Collection<Address> dests, Message msg, RequestOptions options) {
+ GroupRequest<T> req=cast(dests, msg, options, true);
return req != null? req.getResults() : RspList.EMPTY_RSP_LIST;
}
- public NotifyingFuture<RspList> castMessageWithFuture(final Collection<Address> dests, Message msg, RequestOptions options) {
- GroupRequest req=cast(dests, msg, options, false);
+ public <T> NotifyingFuture<RspList<T>> castMessageWithFuture(final Collection<Address> dests, Message msg, RequestOptions options) {
+ GroupRequest<T> req=cast(dests, msg, options, false);
return req != null? req : new NullFuture<RspList>(RspList.EMPTY_RSP_LIST);
}
- protected GroupRequest cast(final Collection<Address> dests, Message msg, RequestOptions options, boolean block_for_results) {
+ protected <T> GroupRequest<T> cast(final Collection<Address> dests, Message msg, RequestOptions options, boolean block_for_results) {
List<Address> real_dests;
// we need to clone because we don't want to modify the original
@@ -289,7 +289,7 @@ protected GroupRequest cast(final Collection<Address> dests, Message msg, Reques
return null;
}
- GroupRequest req=new GroupRequest(msg, corr, real_dests, options);
+ GroupRequest<T> req=new GroupRequest<T>(msg, corr, real_dests, options);
if(options != null) {
req.setResponseFilter(options.getRspFilter());
req.setAnycasting(options.getAnycasting());
@@ -315,7 +315,7 @@ public void done(long req_id) {
- public Object sendMessage(Message msg, RequestOptions opts) throws TimeoutException, SuspectedException {
+ public <T> T sendMessage(Message msg, RequestOptions opts) throws Throwable {
Address dest=msg.getDest();
if(dest == null) {
if(log.isErrorEnabled())
@@ -329,7 +329,7 @@ public Object sendMessage(Message msg, RequestOptions opts) throws TimeoutExcept
msg.setScope(opts.getScope());
}
- UnicastRequest req=new UnicastRequest(msg, corr, dest, opts);
+ UnicastRequest<T> req=new UnicastRequest<T>(msg, corr, dest, opts);
try {
req.execute();
}
@@ -340,9 +340,13 @@ public Object sendMessage(Message msg, RequestOptions opts) throws TimeoutExcept
if(opts != null && opts.getMode() == ResponseMode.GET_NONE)
return null;
- Rsp rsp=req.getResult();
+ Rsp<T> rsp=req.getResult();
if(rsp.wasSuspected())
throw new SuspectedException(dest);
+
+ if(rsp.getException() != null)
+ throw rsp.getException();
+
if(!rsp.wasReceived())
throw new TimeoutException("timeout sending message to " + dest);
return rsp.getValue();
@@ -379,7 +383,7 @@ public Object sendMessage(Message msg, RequestOptions opts) throws TimeoutExcept
/* ------------------------ RequestHandler Interface ---------------------- */
- public Object handle(Message msg) {
+ public Object handle(Message msg) throws Throwable {
if(req_handler != null) {
return req_handler.handle(msg);
}
Oops, something went wrong.

0 comments on commit 63307a8

Please sign in to comment.