Author: manik.surtani(a)jboss.com
Date: 2008-04-30 13:04:26 -0400 (Wed, 30 Apr 2008)
New Revision: 5780
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
Log:
Further optimisations around unnecessary construction of response lists
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-30 16:44:48 UTC
(rev 5779)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-30 17:04:26 UTC
(rev 5780)
@@ -42,7 +42,6 @@
import org.jgroups.util.RspList;
import javax.transaction.TransactionManager;
-import java.io.NotSerializableException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -406,17 +405,14 @@
RspList rsps = disp.invokeRemoteCommands(recipients, command, modeToUse, timeout,
isUsingBuddyReplication, useOutOfBandMessage, responseFilter);
- // a null response is 99% likely to be due to a marshalling problem - we throw a
NSE, this needs to be changed when
- // JGroups supports
http://jira.jboss.com/jira/browse/JGRP-193
- if (rsps == null)
- {
- throw new NotSerializableException("RpcDispatcher returned a null. This is
most often caused by args for " + command.getClass().getSimpleName() + " not
being serializable.");
- }
if (mode == GroupRequest.GET_NONE) return Collections.emptyList();// async case
if (trace)
log.trace("(" + getLocalAddress() + "): responses for method
" + command.getClass().getSimpleName() + ":\n" + rsps);
+ // short-circuit no-return-value calls.
+ if (rsps == null) return Collections.emptyList();
+
List<Object> retval = new ArrayList<Object>(rsps.size());
for (Rsp rsp : rsps.values())
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java 2008-04-30
16:44:48 UTC (rev 5779)
+++
core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java 2008-04-30
17:04:26 UTC (rev 5780)
@@ -16,8 +16,10 @@
import org.jgroups.MessageListener;
import org.jgroups.blocks.RpcDispatcher;
import org.jgroups.blocks.RspFilter;
+import org.jgroups.util.Rsp;
import org.jgroups.util.RspList;
+import java.io.NotSerializableException;
import java.util.Vector;
/**
@@ -66,7 +68,7 @@
* is aware of {@link org.jboss.cache.commands.ReplicableCommand} objects.
*/
public RspList invokeRemoteCommands(Vector<Address> dests, ReplicableCommand
command, int mode, long timeout,
- boolean use_anycasting, boolean oob, RspFilter
filter)
+ boolean use_anycasting, boolean oob, RspFilter
filter) throws NotSerializableException
{
if (dests != null && dests.isEmpty())
{
@@ -94,9 +96,30 @@
msg.setFlag(Message.OOB);
RspList retval = super.castMessage(dests, msg, mode, timeout, use_anycasting,
filter);
if (log.isTraceEnabled()) log.trace("responses: " + retval);
- return retval;
+
+ // a null response is 99% likely to be due to a marshalling problem - we throw a
NSE, this needs to be changed when
+ // JGroups supports
http://jira.jboss.com/jira/browse/JGRP-193
+ // the serialization problem could be on the remote end and this is why we cannot
catch this above, when marshalling.
+ if (retval == null)
+ {
+ throw new NotSerializableException("RpcDispatcher returned a null. This is
most often caused by args for " + command.getClass().getSimpleName() + " not
being serializable.");
+ }
+
+ if (retval.isEmpty() || containsOnlyNulls(retval))
+ return null;
+ else
+ return retval;
}
+ private boolean containsOnlyNulls(RspList l)
+ {
+ for (Rsp r : l.values())
+ {
+ if (r.getValue() != null) return false;
+ }
+ return true;
+ }
+
/**
* Message contains a Command. Execute it against *this* object and return result.
*/