[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Manik Surtani
msurtani at belmont.prod.atl2.jboss.com
Wed Aug 30 13:08:18 EDT 2006
User: msurtani
Date: 06/08/30 13:08:18
Modified: src/org/jboss/cache/marshall
LegacyTreeCacheMarshaller.java
MethodCallFactory.java MethodDeclarations.java
TreeCacheMarshaller.java
TreeCacheMarshaller140.java
TreeCacheMarshaller200.java
Log:
Java5 optimisations
Revision Changes Path
1.7 +295 -297 JBossCache/src/org/jboss/cache/marshall/LegacyTreeCacheMarshaller.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LegacyTreeCacheMarshaller.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/LegacyTreeCacheMarshaller.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- LegacyTreeCacheMarshaller.java 25 Aug 2006 14:10:08 -0000 1.6
+++ LegacyTreeCacheMarshaller.java 30 Aug 2006 17:08:18 -0000 1.7
@@ -9,7 +9,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.marshall.MethodCall;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -32,8 +31,7 @@
*
* @author Ben Wang
* @author Manik Surtani
- *
- * @version $Id: LegacyTreeCacheMarshaller.java,v 1.6 2006/08/25 14:10:08 msurtani Exp $
+ * @version $Id: LegacyTreeCacheMarshaller.java,v 1.7 2006/08/30 17:08:18 msurtani Exp $
*/
public class LegacyTreeCacheMarshaller extends Marshaller
{
@@ -171,7 +169,7 @@
}
return MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod,
- new Object[]{fqn});
+ fqn);
}
// If the region has an associated CL, read the value using it
@@ -197,7 +195,7 @@
}
return MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod,
- new Object[]{fqn});
+ fqn);
}
}
@@ -225,7 +223,7 @@
if (region != null && region.isQueueing())
{
obj = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod,
- new Object[]{region.getFqn(), obj});
+ region.getFqn(), obj);
}
return obj;
@@ -331,16 +329,16 @@
{
Object[] orig = (Object[]) o;
toSerialize = new Object[orig.length];
- for (int i=0; i<orig.length; i++)
+ for (int i = 0; i < orig.length; i++)
{
- ((Object[])toSerialize)[i] = externMethodCall(orig[i]);
+ ((Object[]) toSerialize)[i] = externMethodCall(orig[i]);
}
}
else if (o instanceof List)
{
List orig = (List) o;
toSerialize = new ArrayList(orig.size());
- for (int i=0; i<orig.size(); i++)
+ for (int i = 0; i < orig.size(); i++)
{
((List) toSerialize).add(externMethodCall(orig.get(i)));
}
1.5 +12 -13 JBossCache/src/org/jboss/cache/marshall/MethodCallFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MethodCallFactory.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/MethodCallFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MethodCallFactory.java 25 Aug 2006 14:10:08 -0000 1.4
+++ MethodCallFactory.java 30 Aug 2006 17:08:18 -0000 1.5
@@ -12,7 +12,7 @@
* Factory class to create instances of org.jboss.cache.marshall.MethodCall
*
* @author <a href="galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class MethodCallFactory
{
@@ -23,9 +23,8 @@
* @param arguments list of parameters
* @return a new instance of MethodCall with the method id initialised
*/
- public static MethodCall create(Method method, Object[] arguments)
+ public static MethodCall create(Method method, Object ... arguments)
{
- MethodCall mc = new MethodCall(method, arguments, MethodDeclarations.lookupMethodId(method));
- return mc;
+ return new MethodCall(method, arguments, MethodDeclarations.lookupMethodId(method));
}
}
1.15 +2 -2 JBossCache/src/org/jboss/cache/marshall/MethodDeclarations.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MethodDeclarations.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/MethodDeclarations.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- MethodDeclarations.java 30 Aug 2006 16:26:01 -0000 1.14
+++ MethodDeclarations.java 30 Aug 2006 17:08:18 -0000 1.15
@@ -30,7 +30,7 @@
* allowing lookup operations both ways.
*
* @author <a href="galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @version $Revision: 1.14 $
+ * @version $Revision: 1.15 $
*/
public class MethodDeclarations
{
@@ -204,7 +204,7 @@
prepareMethod = TreeCache.class.getDeclaredMethod("prepare", GlobalTransaction.class, List.class, Address.class, boolean.class);
commitMethod = TreeCache.class.getDeclaredMethod("commit", GlobalTransaction.class);
rollbackMethod = TreeCache.class.getDeclaredMethod("rollback", GlobalTransaction.class);
- addChildMethodLocal = TreeCache.class.getDeclaredMethod("_addChild", GlobalTransaction.class, Fqn.class, Object.class, DataNode.class);
+ addChildMethodLocal = TreeCache.class.getDeclaredMethod("_addChild", GlobalTransaction.class, Fqn.class, Object.class, DataNode.class, boolean.class);
getKeyValueMethodLocal = TreeCache.class.getDeclaredMethod("_get", Fqn.class, Object.class, boolean.class);
getNodeMethodLocal = TreeCache.class.getDeclaredMethod("_get", Fqn.class);
getKeysMethodLocal = TreeCache.class.getDeclaredMethod("_getKeys", Fqn.class);
1.22 +163 -147 JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- TreeCacheMarshaller.java 25 Aug 2006 14:10:08 -0000 1.21
+++ TreeCacheMarshaller.java 30 Aug 2006 17:08:18 -0000 1.22
@@ -15,7 +15,6 @@
import org.jboss.invocation.MarshalledValueInputStream;
import org.jboss.invocation.MarshalledValueOutputStream;
import org.jgroups.blocks.RpcDispatcher;
-import org.jboss.cache.marshall.MethodCall;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -25,7 +24,7 @@
import java.util.List;
/**
- * <p>
+ * <p/>
* Marshaller implementation that does aplication specific marshalling in the <em>JGroups</em> <code>RpcDispatcher</code>
* level. Application
* that runs on specific class loader will only need to register beforehand with TreeCache the class loader
@@ -36,17 +35,20 @@
*
* @author Ben Wang
* Date: Aug 9, 2005
- * @version $Id: TreeCacheMarshaller.java,v 1.21 2006/08/25 14:10:08 msurtani Exp $
+ * @version $Id: TreeCacheMarshaller.java,v 1.22 2006/08/30 17:08:18 msurtani Exp $
*/
-public class TreeCacheMarshaller implements RpcDispatcher.Marshaller {
+public class TreeCacheMarshaller implements RpcDispatcher.Marshaller
+{
protected RegionManager manager_;
protected boolean defaultInactive_;
- /** Map<GlobalTransaction, Fqn> for prepared tx that have not committed */
- private ConcurrentHashMap transactions=new ConcurrentHashMap(16);
+ /**
+ * Map<GlobalTransaction, Fqn> for prepared tx that have not committed
+ */
+ private ConcurrentHashMap transactions = new ConcurrentHashMap(16);
- private Log log_=LogFactory.getLog(TreeCacheMarshaller.class);
+ private Log log_ = LogFactory.getLog(TreeCacheMarshaller.class);
public TreeCacheMarshaller()
{
@@ -87,6 +89,7 @@
/**
* Register the specific classloader under the <code>fqn</code> region.
+ *
* @param fqn
* @param cl
* @throws RegionNameConflictException thrown if there is a conflict in region definition.
@@ -95,10 +98,12 @@
throws RegionNameConflictException
{
Region existing = manager_.getRegion(fqn);
- if (existing == null) {
+ if (existing == null)
+ {
manager_.createRegion(fqn, cl, defaultInactive_);
}
- else {
+ else
+ {
existing.setClassLoader(cl);
}
}
@@ -106,6 +111,7 @@
/**
* Un-register the class loader. Caller will need to call this when the application is out of scope.
* Otherwise, the class loader will not get gc.
+ *
* @param fqn
*/
public void unregisterClassLoader(String fqn) throws RegionNotFoundException
@@ -129,7 +135,6 @@
* @return the classloader associated with the cache region rooted by
* <code>fqn</code>, or <code>null</code> if no classloader has
* been associated with the region.
- *
* @throws RegionNotFoundException
*/
public ClassLoader getClassLoader(String fqn) throws RegionNotFoundException
@@ -185,7 +190,6 @@
* rooted in the given Fqn.
*
* @param fqn
- *
* @throws RegionNameConflictException if there is a conflict in region definition.
*/
public void inactivate(String fqn) throws RegionNameConflictException
@@ -222,10 +226,8 @@
* rooted in the given Fqn.
*
* @param fqn
- *
* @return <code>true</code> if unmarshalling is disabled;
* <code>false</code> otherwise.
- *
* @see #activate
* @see #inactivate
*/
@@ -247,11 +249,13 @@
/**
* Idea is to write specific fqn information in the header such that during unm-marshalling we know
* which class loader to use.
+ *
* @param o
* @return
* @throws Exception
*/
- public byte[] objectToByteBuffer(Object o) throws Exception {
+ public byte[] objectToByteBuffer(Object o) throws Exception
+ {
/**
* Object is always MethodCall, it can be either: replicate or replicateAll (used in async repl queue)
* 1. replicate. Argument is another MethodCall. The followings are the one that we need to handle:
@@ -269,18 +273,19 @@
break;
default :
throw new IllegalStateException("TreeCacheMarshaller.objectToByteBuffer(): MethodCall name is either not "
- + " replicate or replicateAll but : " +call.getName());
+ + " replicate or replicateAll but : " + call.getName());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new MarshalledValueOutputStream(bos);
// Extract fqn and write it out in fixed format
- if(fqn == null) fqn = "NULL"; // can't write null. tis can be commit.
+ if (fqn == null) fqn = "NULL"; // can't write null. tis can be commit.
oos.writeUTF(fqn);
// Serialize the rest of MethodCall object
oos.writeObject(o);
- if (log_.isTraceEnabled()) {
+ if (log_.isTraceEnabled())
+ {
log_.trace("send");
log_.trace(getColumnDump(bos.toByteArray()));
}
@@ -290,12 +295,15 @@
/**
* This is the un-marshalling step. We will read in the fqn and thus obtain the user-specified classloader
* first.
+ *
* @param bytes
* @return
* @throws Exception
*/
- public Object objectFromByteBuffer(byte[] bytes) throws Exception {
- if (log_.isTraceEnabled()) {
+ public Object objectFromByteBuffer(byte[] bytes) throws Exception
+ {
+ if (log_.isTraceEnabled())
+ {
log_.trace("recv");
log_.trace(getColumnDump(bytes));
}
@@ -304,14 +312,15 @@
// Read the fqn first
String fqn = ois.readUTF();
- ClassLoader oldTcl = null;;
+ ClassLoader oldTcl = null;
+ ;
Region region = null;
- if(fqn != null && !fqn.equals("NULL"))
+ if (fqn != null && !fqn.equals("NULL"))
{
// obtain a region from RegionManager, if not, will use default.
region = getRegion(fqn);
- if(region != null)
+ if (region != null)
{
// If the region has been marked inactive, we still have
// to return a MethodCall or RpcDispatcher will log an Error.
@@ -324,7 +333,7 @@
}
return MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod,
- new Object[] { fqn} );
+ fqn);
}
// If the region has an associated CL, read the value using it
@@ -350,7 +359,7 @@
}
return MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod,
- new Object[] { fqn} );
+ fqn);
}
}
@@ -359,7 +368,8 @@
try
{
obj = ois.readObject();
- } finally
+ }
+ finally
{
if (oldTcl != null)
{
@@ -377,7 +387,7 @@
if (region != null && region.isQueueing())
{
obj = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod,
- new Object[] { region.getFqn(), obj });
+ region.getFqn(), obj);
}
return obj;
@@ -385,23 +395,25 @@
/**
* This is "replicate" call with a single MethodCall argument.
+ *
* @param call
*/
protected String extractFqnFromMethodCall(MethodCall call)
{
- MethodCall c0 = (MethodCall)call.getArgs()[0];
+ MethodCall c0 = (MethodCall) call.getArgs()[0];
return extractFqn(c0);
}
/**
* This is "replicate" call with a list of MethodCall argument.
+ *
* @param call
*/
protected String extractFqnFromListOfMethodCall(MethodCall call)
{
Object[] args = call.getArgs();
// We simply pick the first one and assume everyone will need to operate under the same region!
- MethodCall c0 = (MethodCall)((List)args[0]).get(0);
+ MethodCall c0 = (MethodCall) ((List) args[0]).get(0);
return extractFqn(c0);
}
@@ -412,7 +424,7 @@
throw new NullPointerException("method call is null");
}
- Method meth=method_call.getMethod();
+ Method meth = method_call.getMethod();
String fqnStr = null;
Object[] args = method_call.getArgs();
switch (method_call.getMethodId())
@@ -420,8 +432,8 @@
case MethodDeclarations.optimisticPrepareMethod_id:
case MethodDeclarations.prepareMethod_id:
// Prepare method has a list of modifications. We will just take the first one and extract.
- List modifications=(List)args[1];
- fqnStr = extractFqn((MethodCall)modifications.get(0));
+ List modifications = (List) args[1];
+ fqnStr = extractFqn((MethodCall) modifications.get(0));
// the last arg of a prepare call is the one-phase flag
boolean one_phase_commit = ((Boolean) args[args.length - 1]).booleanValue();
@@ -454,13 +466,13 @@
default :
if (MethodDeclarations.isCrudMethod(method_call.getMethodId()))
{
- Fqn fqn2 = (Fqn)args[1];
+ Fqn fqn2 = (Fqn) args[1];
fqnStr = fqn2.toString();
}
else
{
throw new IllegalArgumentException("TreeCacheMarshaller.extractFqn(): Unknown method call name: "
- +meth.getName());
+ + meth.getName());
}
break;
@@ -493,8 +505,10 @@
int offs = 0;
StringBuffer sb = new StringBuffer(length * 4);
StringBuffer tx = new StringBuffer();
- for (int i=0; i<length; i++) {
- if (i % col == 0) {
+ for (int i = 0; i < length; i++)
+ {
+ if (i % col == 0)
+ {
sb.append(tx).append('\n');
tx.setLength(0);
}
@@ -511,7 +525,8 @@
sb.append(' ');
}
int remain = col - (length % col);
- if (remain != col) {
+ if (remain != col)
+ {
for (int i = 0; i < remain * 3; i++)
{
sb.append(' ');
@@ -521,7 +536,8 @@
return sb.toString();
}
- private static void appendHex(StringBuffer sb, byte b) {
+ private static void appendHex(StringBuffer sb, byte b)
+ {
sb.append(Character.forDigit((b >> 4) & 0x0f, 16));
sb.append(Character.forDigit(b & 0x0f, 16));
}
1.3 +439 -440 JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller140.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller140.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller140.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- TreeCacheMarshaller140.java 25 Aug 2006 14:10:08 -0000 1.2
+++ TreeCacheMarshaller140.java 30 Aug 2006 17:08:18 -0000 1.3
@@ -13,7 +13,6 @@
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.rpc.RpcTreeCache;
import org.jgroups.Address;
-import org.jboss.cache.marshall.MethodCall;
import org.jgroups.stack.IpAddress;
import java.io.IOException;
@@ -103,7 +102,7 @@
{
log.debug("Received call on an ququing Fqn region (" + fqn + "). Calling enqueueMethodCallMethod");
}
- retValue = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod, new Object[]{fqn, originalRetValue});
+ retValue = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod, fqn, originalRetValue);
}
}
catch (InactiveRegionException e)
@@ -112,7 +111,7 @@
{
log.debug("Received call on an inactive Fqn region (" + fqn + "). Calling notifyCallOnInactiveMetod");
}
- retValue = MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod, new Object[]{fqn});
+ retValue = MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod, fqn);
}
}
else
1.3 +2 -2 JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller200.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- TreeCacheMarshaller200.java 30 Aug 2006 08:41:53 -0000 1.2
+++ TreeCacheMarshaller200.java 30 Aug 2006 17:08:18 -0000 1.3
@@ -104,7 +104,7 @@
{
log.debug("Received call on an ququing Fqn region (" + fqn + "). Calling enqueueMethodCallMethod");
}
- retValue = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod, new Object[]{fqn, originalRetValue});
+ retValue = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod, fqn, originalRetValue);
}
}
catch (TreeCacheMarshaller200.InactiveRegionException e)
@@ -113,7 +113,7 @@
{
log.debug("Received call on an inactive Fqn region (" + fqn + "). Calling notifyCallOnInactiveMetod");
}
- retValue = MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod, new Object[]{fqn});
+ retValue = MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod, fqn);
}
}
else
More information about the jboss-cvs-commits
mailing list