Author: manik.surtani(a)jboss.com
Date: 2008-01-03 14:17:09 -0500 (Thu, 03 Jan 2008)
New Revision: 4968
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/Fqn.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
core/trunk/src/test/java/org/jboss/cache/FqnTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java
core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Optimised fqns and interceptors
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-03 13:29:35 UTC (rev
4967)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-03 19:17:09 UTC (rev
4968)
@@ -183,6 +183,8 @@
private CacheSPI spi;
private Interceptor interceptorChain;
+ private boolean trace;
+
/**
* Constructs an uninitialized CacheImpl.
*/
@@ -1074,7 +1076,7 @@
return;// node does not exist. Maybe it has been recursively removed.
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evictSubtree(" + subtree + ")");
}
@@ -1124,7 +1126,7 @@
boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
boolean broken = LockUtil.breakTransactionLock(lock, deadOwner, localTx, this);
- if (broken && log.isTraceEnabled())
+ if (broken && trace)
{
log.trace("Broke lock for node " + node.getFqn() +
" held by " + deadOwner);
@@ -1244,7 +1246,7 @@
public Object _get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws
CacheException
{
InvocationContext ctx = spi.getInvocationContext();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(new
StringBuffer("_get(").append("\"").append(fqn).append("\",
\"").append(key).append("\", \"").
append(sendNodeEvent).append("\")"));
@@ -1888,14 +1890,14 @@
}
if (validMembers.isEmpty())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("destination list is empty, discarding call");
}
return null;
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("callRemoteMethods(): valid members are " + validMembers +
" methods: " + method_call.getArgs()[0]);
}
@@ -1921,7 +1923,7 @@
return Collections.EMPTY_LIST;// async case
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + getLocalAddress() + "): responses for method
" + method_call.getName() + ":\n" + rsps);
}
@@ -1949,7 +1951,7 @@
if (value instanceof Exception && !(value instanceof
ReplicationException))
{
// if we have any application-level exceptions make sure we throw them!!
- if (log.isTraceEnabled()) log.trace("Recieved exception'" +
value + "' from " + rsp.getSender());
+ if (trace) log.trace("Recieved exception'" + value +
"' from " + rsp.getSender());
throw (Exception) value;
}
retval.add(value);
@@ -2105,7 +2107,7 @@
public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops,
boolean erase_contents)
throws CacheException
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_put(" + tx + ", \"" + fqn + "\",
" + data + " undo=" + create_undo_ops + " erase=" +
erase_contents + ")");
}
@@ -2167,7 +2169,7 @@
public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean
create_undo_ops)
throws CacheException
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(new StringBuffer("_put(").append(tx).append(",
\"").
append(fqn).append("\", k=").append(key).append(",
v=").append(value).append(")"));
@@ -2268,7 +2270,7 @@
NodeSPI parent_node;
MethodCall undo_op = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_remove(" + tx + ", \"" + fqn +
"\", undo=" + create_undo_ops + ")");
}
@@ -2296,7 +2298,7 @@
n = findNode(fqn, version, true);
if (n == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("node " + fqn + " not found");
}
@@ -2389,7 +2391,7 @@
MethodCall undo_op = null;
Object old_value = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_remove(" + tx + ", \"" + fqn +
"\", key=" + key + ")");
}
@@ -2469,7 +2471,7 @@
{
MethodCall undo_op = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_removeData(" + tx + ", \"" + fqn +
"\")");
}
@@ -2560,7 +2562,7 @@
boolean create_undo_ops = false;
boolean sendNodeEvent = false;
boolean eviction = true;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evict(" + fqn + ")");
}
@@ -2591,7 +2593,7 @@
if (!exists(fqn))
return true;// node does not exist
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evict(" + fqn + ", " + version +
")");
}
@@ -2696,7 +2698,7 @@
throws CacheException
{
NodeSPI childNode = (NodeSPI) cn;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_addChild(\"" + parent_fqn + "\",
\"" + child_name + "\", node=" + childNode + ")");
}
@@ -2794,7 +2796,7 @@
// for now, perform a very simple series of getData calls.
InvocationContext ctx = spi.getInvocationContext();
- if (log.isTraceEnabled()) log.trace("Caller is asking for " + fqn);
+ if (trace) log.trace("Caller is asking for " + fqn);
try
{
@@ -2806,7 +2808,7 @@
Node actualNode = spi.getNode(fqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (log.isTraceEnabled()) log.trace("In local tree, this is " +
actualNode);
+ if (trace) log.trace("In local tree, this is " + actualNode);
Fqn backupNodeFqn = null;
if (actualNode == null && searchSubtrees)
@@ -2829,7 +2831,7 @@
ctx.getOptionOverrides().setSkipDataGravitation(true);
actualNode = spi.getNode(backupNodeFqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Looking for " + backupNodeFqn + ".
Search result: " + actualNode);
if (actualNode != null) break;
}
@@ -3101,6 +3103,7 @@
}
// replace .s with _s otherwise Log4J will strip them out
log = LogFactory.getLog(category.toString());
+ trace = log.isTraceEnabled();
}
/**
@@ -3322,7 +3325,7 @@
TransactionEntry ent = configuration.isNodeLockingOptimistic() ? new
OptimisticTransactionEntry() : new TransactionEntry();
ent.setTransaction(tx);
transactionTable.put(gtx, ent);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("created new GTX: " + gtx + ", local TX=" +
tx);
}
@@ -3409,7 +3412,7 @@
if (n == null)
{
String errStr = "node " + fqn + " not found (gtx=" + tx +
", caller=" + Thread.currentThread() + ")";
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(errStr);
}
@@ -3433,7 +3436,7 @@
}
- if (log.isTraceEnabled()) log.trace("Performing a real remove for node "
+ f + ", marked for removal.");
+ if (trace) log.trace("Performing a real remove for node " + f + ",
marked for removal.");
if (skipMarkerCheck || n.isDeleted())
{
if (n.getFqn().isRoot())
@@ -3482,7 +3485,7 @@
{
// we need to check the version of the data node...
DataVersion nodeVersion = toReturn.getVersion();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("looking for optimistic node [" + fqn + "] with
version [" + version + "]. My version is [" + nodeVersion +
"]");
}
@@ -3569,7 +3572,7 @@
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Cache cluster properties: " +
configuration.getClusterConfig());
}
@@ -3597,7 +3600,7 @@
disp.setRequestMarshaller(marshaller);
disp.setResponseMarshaller(marshaller);
- if (log.isTraceEnabled()) log.trace("Started with RpcDispatcher " +
disp);
+ if (trace) log.trace("Started with RpcDispatcher " + disp);
}
private JChannel getMultiplexerChannel() throws CacheException
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -68,23 +68,24 @@
* Separator between FQN elements.
*/
public static final String SEPARATOR = "/";
-
+
private static final long serialVersionUID = -5351930616956603651L;
-
+
private static final Log log = LogFactory.getLog(Fqn.class);
-
+
private List<E> elements;
private transient int hash_code = 0;
+ private int size = 0;
/**
* Immutable root FQN.
*/
@SuppressWarnings("unchecked")
public static final Fqn ROOT = new Fqn();
-
+
/**
* A cached string representation of this Fqn, used by toString to it isn't
calculated again every time.
- */
+ */
private String cachedStringRep;
/**
@@ -93,6 +94,7 @@
public Fqn()
{
elements = Collections.emptyList();
+ size = 0;
}
/**
@@ -120,10 +122,12 @@
{
// if not safe make a defensive copy
elements = safe ? names : new ArrayList<E>(names);
+ size = elements.size();
}
else
{
elements = Collections.emptyList();
+ size = 0;
}
}
@@ -162,6 +166,7 @@
elements.addAll(base.elements);
elements.addAll(relative);
this.elements = elements;
+ size = elements.size();
}
/**
@@ -176,6 +181,7 @@
elements.addAll(base.elements);
elements.addAll(Arrays.asList(childNames));
this.elements = elements;
+ size = elements.size();
}
/**
@@ -244,7 +250,7 @@
*/
public Fqn<E> getSubFqn(int startIndex, int endIndex)
{
- return new Fqn<E>(elements.subList(startIndex, endIndex));
+ return new Fqn<E>(elements.subList(startIndex, endIndex), true);
}
/**
@@ -252,7 +258,7 @@
*/
public int size()
{
- return elements.size();
+ return size;
}
/**
@@ -271,7 +277,7 @@
public E getLastElement()
{
if (isRoot()) return null;
- return elements.get(elements.size() - 1);
+ return elements.get(size - 1);
}
/**
@@ -280,7 +286,7 @@
*/
public boolean hasElement(E element)
{
- return elements.lastIndexOf(element) != -1;
+ return elements.indexOf(element) != -1;
}
/**
@@ -314,7 +320,7 @@
return false;
}
Fqn<?> other = (Fqn<?>) obj;
- return elements.equals(other.elements);
+ return size == other.size() && elements.equals(other.elements);
}
/**
@@ -362,7 +368,7 @@
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeShort(elements.size());
+ out.writeShort(size);
for (E element : elements)
{
out.writeObject(element);
@@ -372,9 +378,9 @@
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
- short length = in.readShort();
- this.elements = new ArrayList<E>(length);
- for (int i = 0; i < length; i++)
+ size = in.readShort();
+ this.elements = new ArrayList<E>(size);
+ for (int i = 0; i < size; i++)
{
E e = (E) in.readObject();
elements.add(e);
@@ -398,7 +404,7 @@
*/
public boolean isChildOf(Fqn<E> parentFqn)
{
- return parentFqn.elements.size() != elements.size() &&
isChildOrEquals(parentFqn);
+ return parentFqn.size() != size && isChildOrEquals(parentFqn);
}
/**
@@ -418,7 +424,7 @@
public boolean isChildOrEquals(Fqn<E> parentFqn)
{
List<E> parentList = parentFqn.elements;
- if (parentList.size() > elements.size())
+ if (parentList.size() > size)
{
return false;
}
@@ -470,18 +476,19 @@
*/
public Fqn<E> getParent()
{
- switch (elements.size())
+ switch (size)
{
case 0:
case 1:
return root();
default:
- return new Fqn<E>(elements.subList(0, elements.size() - 1));
+ return new Fqn<E>(elements.subList(0, size - 1));
}
}
-
+
@SuppressWarnings("unchecked")
- public static <T> Fqn<T> root() {
+ public static <T> Fqn<T> root()
+ {
return ROOT;
}
@@ -492,7 +499,7 @@
*/
public boolean isRoot()
{
- return elements.isEmpty();
+ return size == 0;
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -211,8 +211,7 @@
public static String getGroupNameFromAddress(Object address)
{
- String s = address.toString();
- return s.replace(':', '_');
+ return address.toString().replace(':', '_');
}
/**
@@ -622,12 +621,13 @@
{
if (isBackupFqn(origFqn))
throw new CacheException("Cannot make a backup Fqn from a backup Fqn!
Attempting to create a backup of " + origFqn);
- List<Object> elements = new ArrayList<Object>();
+
+ List<Object> elements = new ArrayList<Object>(origFqn.size() + 2);
elements.add(BUDDY_BACKUP_SUBTREE);
elements.add(buddyGroupName);
elements.addAll(origFqn.peekElements());
- return new Fqn(elements);
+ return new Fqn(elements, true);
}
/**
@@ -640,17 +640,15 @@
*/
public static Fqn getBackupFqn(Fqn buddyGroupRoot, Fqn origFqn)
{
- if (origFqn.isChildOf(buddyGroupRoot))
- {
- return origFqn;
- }
+ if (isBackupFqn(origFqn))
+ throw new CacheException("Cannot make a backup Fqn from a backup Fqn!
Attempting to create a backup of " + origFqn);
- List<Object> elements = new ArrayList<Object>();
+ List<Object> elements = new ArrayList<Object>(origFqn.size() + 2);
elements.add(BUDDY_BACKUP_SUBTREE);
elements.add(buddyGroupRoot.get(1));
elements.addAll(origFqn.peekElements());
- return new Fqn(elements);
+ return new Fqn(elements, true);
}
public static boolean isBackupFqn(Fqn name)
@@ -683,7 +681,7 @@
public MethodCall transformFqns(MethodCall call, boolean transformForCurrentCall)
{
- if (call != null && call.getArgs() != null)
+ if (call != null && call.getArgs() != null && call.getMethodId() !=
MethodDeclarations.commitMethod_id)
{
MethodCall call2 = MethodCallFactory.create(call.getMethod(),
call.getArgs().clone());
handleArgs(call2.getArgs(), transformForCurrentCall);
@@ -1009,13 +1007,7 @@
if (args[i] instanceof MethodCall)
{
MethodCall call = (MethodCall) args[i];
- boolean transformFqns = true;
- if (call.getMethodId() ==
MethodDeclarations.dataGravitationCleanupMethod_id)
- {
- transformFqns = false;
- }
-
- args[i] = transformFqns((MethodCall) args[i], transformFqns);
+ args[i] = transformFqns((MethodCall) args[i], call.getMethodId() !=
MethodDeclarations.dataGravitationCleanupMethod_id);
}
if (args[i] instanceof List && args[i] != null)
@@ -1023,8 +1015,6 @@
Object[] asArray = ((List) args[i]).toArray();
handleArgs(asArray, transformForCurrentCall);
List<Object> newList = new ArrayList<Object>(asArray.length);
- // Oops! JDK 5.0!
- //Collections.addAll(newList, asArray);
newList.addAll(Arrays.asList(asArray));
args[i] = newList;
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -47,18 +47,15 @@
public ActivationInterceptor()
{
- this.useCacheStore = false;
- isActivation = true;
+ initLogger();
}
@Override
protected Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx,
Fqn fqn, boolean createUndoOps) throws Throwable
{
Object returnValue = super.handleRemoveDataMethod(ctx, tx, fqn, createUndoOps);
- if (log.isTraceEnabled())
- {
+ if (trace)
log.trace("This is a remove data operation; removing the data from the
loader, no activation processing needed.");
- }
loader.removeData(fqn);
return returnValue;
}
@@ -67,10 +64,8 @@
protected Object handleRemoveNodeMethod(InvocationContext ctx, GlobalTransaction tx,
Fqn fqn, boolean createUndoOps) throws Throwable
{
Object returnValue = super.handleRemoveNodeMethod(ctx, tx, fqn, createUndoOps);
- if (log.isTraceEnabled())
- {
+ if (trace)
log.trace("This is a remove operation; removing the node from the loader,
no activation processing needed.");
- }
loader.remove(fqn);
return returnValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -70,24 +70,24 @@
}
}
- protected void replicateCall(MethodCall call, boolean sync, Option o) throws
Throwable
+ protected void replicateCall(InvocationContext ctx, MethodCall call, boolean sync,
Option o) throws Throwable
{
- replicateCall(null, call, sync, o);
+ replicateCall(ctx, null, call, sync, o);
}
- protected void replicateCall(List<Address> recipients, MethodCall call, boolean
sync, Option o) throws Throwable
+ protected void replicateCall(InvocationContext ctx, List<Address> recipients,
MethodCall call, boolean sync, Option o) throws Throwable
{
- replicateCall(recipients, call, sync, o, true);
+ replicateCall(ctx, recipients, call, sync, o, true);
}
- protected void replicateCall(List<Address> recipients, MethodCall call, boolean
sync, Option o, boolean wrapMethodCallInReplicateMethod) throws Throwable
+ protected void replicateCall(InvocationContext ctx, List<Address> recipients,
MethodCall call, boolean sync, Option o, boolean wrapMethodCallInReplicateMethod) throws
Throwable
{
- if (log.isTraceEnabled()) log.trace("Broadcasting call " + call + "
to recipient list " + recipients);
- Transaction tx = null;
- if (cache.getTransactionManager() != null && (tx =
cache.getTransactionManager().getTransaction()) != null)
+ if (trace) log.trace("Broadcasting call " + call + " to recipient
list " + recipients);
+ Transaction tx = ctx.getTransaction();
+ if (tx != null)
{
- GlobalTransaction gtx = cache.getTransactionTable().get(tx);
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
TransactionEntry te = cache.getTransactionTable().get(gtx);
if (te != null)
{
@@ -107,7 +107,7 @@
if (callRecipients == null)
{
callRecipients = usingBuddyReplication ? buddyManager.getBuddyAddresses() :
cache.getMembers();
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Setting call recipients to " + callRecipients +
" since the original list of recipients passed in is null.");
}
@@ -121,10 +121,7 @@
sync, // is synchronised?
true, // ignore self?
(int) syncReplTimeout);
- if (log.isTraceEnabled())
- {
- log.trace("responses=" + rsps);
- }
+ if (trace) log.trace("responses=" + rsps);
if (sync) checkResponses(rsps);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -44,8 +44,11 @@
protected void setTransactionalContext(Transaction tx, GlobalTransaction gtx,
InvocationContext ctx)
{
- log.trace("Setting up transactional context.");
- if (log.isTraceEnabled()) log.trace("Setting tx as " + tx + " and
gtx as " + gtx);
+ if (trace)
+ {
+ log.trace("Setting up transactional context.");
+ log.trace("Setting tx as " + tx + " and gtx as " + gtx);
+ }
ctx.setTransaction(tx);
ctx.setGlobalTransaction(gtx);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -45,7 +44,7 @@
public CacheLoaderInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
/**
@@ -211,8 +210,7 @@
protected Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction
globalTransaction) throws Throwable
{
// clean up nodesCreated map
- boolean traceEnabled = log.isTraceEnabled();
- log.trace("Removing temporarily created nodes from treecache");
+ if (trace) log.trace("Removing temporarily created nodes from
treecache");
// this needs to be done in reverse order.
List list = getTransactionEntry(ctx).getDummyNodesCreatedByCacheLoader();
@@ -228,7 +226,7 @@
}
catch (CacheException e)
{
- if (traceEnabled) log.trace("Unable to evict node " + fqn, e);
+ if (trace) log.trace("Unable to evict node " + fqn, e);
}
}
}
@@ -270,7 +268,7 @@
NodeSPI n = cache.peek(fqn, true, true);
boolean mustLoad = mustLoad(n, key, allKeys);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("load element " + fqn + " mustLoad=" + mustLoad);
}
@@ -333,12 +331,12 @@
if (node != null && node.isChildrenLoaded())
{
- log.trace("Children already loaded!");
+ if (trace) log.trace("Children already loaded!");
return;
}
Set children_names = loader.getChildrenNames(fqn);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("load children " + fqn + " children=" +
children_names);
}
@@ -396,7 +394,7 @@
{
if (n == null)
{
- log.trace("must load, node null");
+ if (trace) log.trace("must load, node null");
return true;
}
@@ -404,7 +402,7 @@
if (!n.isValid() && cache.getConfiguration().isNodeLockingOptimistic())
{
// attempt to load again; this only happens if we have tombstones lying around,
or we are using invalidation.
- log.trace("loading again from cache loader since in-memory node is marked
as invalid");
+ if (trace) log.trace("loading again from cache loader since in-memory node
is marked as invalid");
return true;
}
@@ -414,18 +412,18 @@
// if we are not looking for a specific key don't bother loading!
if (key == null)
{
- log.trace("don't load, key requested is null");
+ if (trace) log.trace("don't load, key requested is null");
return false;
}
if (n.getKeysDirect().contains(key))
{
- log.trace("don't load, already have necessary key in memory");
+ if (trace) log.trace("don't load, already have necessary key in
memory");
return false;
}
}
if (!n.isDataLoaded())
{
- log.trace("must Load, uninitialized");
+ if (trace) log.trace("must Load, uninitialized");
return true;
}
return false;
@@ -520,11 +518,11 @@
*/
private NodeSPI loadNode(InvocationContext ctx, Fqn fqn, NodeSPI n, TransactionEntry
entry) throws Exception
{
- if (log.isTraceEnabled()) log.trace("loadNode " + fqn);
+ if (trace) log.trace("loadNode " + fqn);
Map nodeData = loadData(fqn);
if (nodeData != null)
{
- log.trace("Node data is not null, loading");
+ if (trace) log.trace("Node data is not null, loading");
cache.getNotifier().notifyNodeLoaded(fqn, true, Collections.emptyMap(), ctx);
if (isActivation)
@@ -548,7 +546,7 @@
if (n != null && !n.isDataLoaded())
{
- log.trace("Setting dataLoaded to true");
+ if (trace) log.trace("Setting dataLoaded to true");
n.setDataLoaded(true);
}
return n;
@@ -561,7 +559,7 @@
{
NodeSPI n = createNodes(fqn, entry);
n.setDataLoaded(false);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("createTempNode n " + n);
}
@@ -623,7 +621,7 @@
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
- if (log.isTraceEnabled()) log.trace("nodeExists " + nodeExists);
+ if (trace) log.trace("nodeExists " + nodeExists);
if (configuration.getExposeManagementStatistics() &&
getStatisticsEnabled())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -21,7 +21,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.optimistic.DataVersion;
@@ -50,7 +49,7 @@
public CacheMgmtInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -48,7 +47,7 @@
public CacheStoreInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Start
@@ -68,7 +67,7 @@
{
if (!ctx.isOriginLocal() && loaderConfig.isShared())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Passing up method call and bypassing this interceptor since
the cache loader is shared and this call originated remotely.");
}
@@ -82,11 +81,11 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader
yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
if (ctx.isTxHasMods())
{
// this is a commit call.
- if (log.isTraceEnabled()) log.trace("Calling loader.commit() for gtx
" + gtx);
+ if (trace) log.trace("Calling loader.commit() for gtx " + gtx);
// sync call (a write) on the loader
// ignore modified FQNs
// List fqnsModified =
getFqnsFromModificationList(tx_table.get(gtx).getCacheLoaderModifications());
@@ -119,7 +118,7 @@
}
else
{
- log.trace("Commit called with no modifications; ignoring.");
+ if (trace) log.trace("Commit called with no modifications;
ignoring.");
}
}
return nextInterceptor(ctx);
@@ -130,7 +129,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader
yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
if (ctx.isTxHasMods())
{
// this is a rollback method
@@ -146,7 +145,7 @@
}
else
{
- log.trace("Rollback called with no modifications; ignoring.");
+ if (trace) log.trace("Rollback called with no modifications;
ignoring.");
}
}
return nextInterceptor(ctx);
@@ -157,7 +156,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader
yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
prepareCacheLoader(gtx, ctx.getMethodCall().isOnePhaseCommitPrepareMehod());
}
return nextInterceptor(ctx);
@@ -168,7 +167,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader
yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
prepareCacheLoader(gtx, ctx.getMethodCall().isOnePhaseCommitPrepareMehod());
}
return nextInterceptor(ctx);
@@ -368,10 +367,10 @@
modifications = entry.getCacheLoaderModifications();
if (modifications.size() == 0)
{
- log.trace("Transaction has not logged any modifications!");
+ if (trace) log.trace("Transaction has not logged any
modifications!");
return;
}
- if (log.isTraceEnabled()) log.trace("Cache loader modification list: " +
modifications);
+ if (trace) log.trace("Cache loader modification list: " +
modifications);
List cache_loader_modifications = new ArrayList();
for (MethodCall methodCall : modifications)
{
@@ -388,7 +387,7 @@
}
}
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Converted method calls to cache loader modifications. List
size: " + cache_loader_modifications.size());
}
@@ -410,7 +409,7 @@
*/
private Modification convertMethodCallToModification(MethodCall methodCall,
Set<Fqn> affectedFqns) throws Exception
{
- if (log.isTraceEnabled()) log.trace("Converting method call " +
methodCall + " to modification.");
+ if (trace) log.trace("Converting method call " + methodCall + " to
modification.");
Method method = methodCall.getMethod();
Object[] args;
if (method == null)
@@ -457,7 +456,7 @@
throw new CacheException("method call " + method.getName() + "
cannot be converted to a modification");
}
affectedFqns.add(fqn);
- if (log.isTraceEnabled()) log.trace("Converted " + methodCall + " to
Modification of type " + mod.getType());
+ if (trace) log.trace("Converted " + methodCall + " to Modification
of type " + mod.getType());
return mod;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -28,6 +28,11 @@
private CacheImpl cacheImpl;
private CacheSPI remoteDelegate;
+ public CallInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(CacheImpl cacheImpl,
@ComponentName("remoteDelegate")CacheSPI remoteDelegate)
{
@@ -42,7 +47,7 @@
if (!MethodDeclarations.isTransactionLifecycleMethod(m.getMethodId()))
{
- if (log.isTraceEnabled()) log.trace("Passing up method " + m + "
so it gets invoked on cache.");
+ if (trace) log.trace("Passing up method " + m + " so it gets
invoked on cache.");
try
{
retval = m.invoke(m.getMethodId() ==
MethodDeclarations.dataGravitationCleanupMethod_id ? remoteDelegate : cacheImpl);
@@ -54,7 +59,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("Suppressing invocation of method
" + m + " on cache.");
+ if (trace) log.trace("Suppressing invocation of method " + m + "
on cache.");
}
Transaction tx = ctx.getTransaction();
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
@@ -61,7 +60,7 @@
public DataGravitatorInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -166,7 +165,7 @@
if (isGravitationEnabled(ctx))
{
// test that the Fqn being requested exists locally in the cache.
- if (log.isTraceEnabled()) log.trace("Checking local existence of fqn "
+ fqn);
+ if (trace) log.trace("Checking local existence of fqn " + fqn);
if (BuddyManager.isBackupFqn(fqn))
{
log.info("Is call for a backup Fqn, not performing any gravitation.
Direct calls on internal backup nodes are *not* supported.");
@@ -175,12 +174,12 @@
{
if (cache.peek(fqn, false) == null)
{
- log.trace("Gravitating from local backup tree");
+ if (trace) log.trace("Gravitating from local backup tree");
BackupData data = localBackupGet(fqn, ctx);
if (data == null)
{
- log.trace("Gravitating from remote backup tree");
+ if (trace) log.trace("Gravitating from remote backup tree");
// gravitate remotely.
data = remoteBackupGet(fqn);
}
@@ -191,7 +190,8 @@
// when I do the put() call to the cluster!
//createNode(data.backupData, true);
// Make sure I replicate to my buddies.
- log.trace("Passing the put call locally to make sure state is
persisted and ownership is correctly established.");
+ if (trace)
+ log.trace("Passing the put call locally to make sure state is
persisted and ownership is correctly established.");
createNode(data.backupData, false);
// very strange, the invocation contexts get twisted up here, and will
need preservation.
@@ -204,13 +204,13 @@
}
else
{
- log.trace("No need to gravitate; have this already.");
+ if (trace) log.trace("No need to gravitate; have this
already.");
}
}
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Suppressing data gravitation for this call.");
}
@@ -234,7 +234,7 @@
private void doPrepare(GlobalTransaction gtx, InvocationContext ctx) throws Throwable
{
MethodCall cleanup = transactionMods.get(gtx);
- if (log.isTraceEnabled()) log.trace("Broadcasting prepare for cleanup ops
" + cleanup);
+ if (trace) log.trace("Broadcasting prepare for cleanup ops " + cleanup);
if (cleanup != null)
{
MethodCall prepare;
@@ -249,11 +249,11 @@
prepare = MethodCallFactory.create(MethodDeclarations.prepareMethod, gtx,
mods, cache.getLocalAddress(), syncCommunications);
}
- replicateCall(getMembersOutsideBuddyGroup(), prepare, syncCommunications,
ctx.getOptionOverrides());
+ replicateCall(ctx, getMembersOutsideBuddyGroup(), prepare, syncCommunications,
ctx.getOptionOverrides());
}
else
{
- if (log.isTraceEnabled()) log.trace("Nothing to broadcast in prepare phase
for gtx " + gtx);
+ if (trace) log.trace("Nothing to broadcast in prepare phase for gtx "
+ gtx);
}
}
@@ -261,12 +261,12 @@
{
if (transactionMods.containsKey(gtx))
{
- if (log.isTraceEnabled()) log.trace("Broadcasting commit for gtx " +
gtx);
- replicateCall(getMembersOutsideBuddyGroup(),
MethodCallFactory.create(MethodDeclarations.commitMethod, gtx), syncCommunications,
ctx.getOptionOverrides());
+ if (trace) log.trace("Broadcasting commit for gtx " + gtx);
+ replicateCall(ctx, getMembersOutsideBuddyGroup(),
MethodCallFactory.create(MethodDeclarations.commitMethod, gtx), syncCommunications,
ctx.getOptionOverrides());
}
else
{
- if (log.isTraceEnabled()) log.trace("Nothing to broadcast in commit phase
for gtx " + gtx);
+ if (trace) log.trace("Nothing to broadcast in commit phase for gtx " +
gtx);
}
}
@@ -287,7 +287,7 @@
if (gr.isDataFound())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Got response " + gr);
}
@@ -303,18 +303,18 @@
MethodCall cleanup =
MethodCallFactory.create(MethodDeclarations.dataGravitationCleanupMethod,
backup.primaryFqn, backup.backupFqn);
- if (log.isTraceEnabled()) log.trace("Performing cleanup on [" +
backup.primaryFqn + "]");
+ if (trace) log.trace("Performing cleanup on [" + backup.primaryFqn +
"]");
if (gtx == null)
{
// broadcast removes
// remove main Fqn
- if (log.isTraceEnabled()) log.trace("Performing cleanup on [" +
backup.backupFqn + "]");
+ if (trace) log.trace("Performing cleanup on [" + backup.backupFqn +
"]");
// remove backup Fqn
- replicateCall(cache.getMembers(), cleanup, syncCommunications,
ctx.getOptionOverrides(), false);
+ replicateCall(ctx, cache.getMembers(), cleanup, syncCommunications,
ctx.getOptionOverrides(), false);
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Data gravitation performed under global transaction " +
gtx + ". Not broadcasting cleanups until the tx commits. Adding to tx mod list
instead.");
}
@@ -326,7 +326,7 @@
private GravitateResult gravitateData(Fqn fqn) throws Exception
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("cache=" + cache.getLocalAddress() + "; requesting data
gravitation for Fqn " + fqn);
}
@@ -336,7 +336,7 @@
// doing a GET_ALL is crappy but necessary since JGroups' GET_FIRST could
return null results from nodes that do
// not have either the primary OR backup, and stop polling other valid nodes.
List resps = cache.getRPCManager().callRemoteMethods(mbrs, dGrav,
GroupRequest.GET_ALL, true, buddyManager.getBuddyCommunicationTimeout(), new
ResponseValidityFilter(mbrs, cache.getLocalAddress()));
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("got responses " + resps);
}
@@ -409,7 +409,7 @@
NodeSPI child_node = n.addChildDirect(new Fqn<Object>(child_name));
if (child_node == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("failed to find or create child " + child_name +
" of node " + n.getFqn());
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -7,7 +7,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
@@ -42,13 +41,13 @@
@Inject
void setRegionManager(RegionManager regionManager)
{
- log.trace("Having region manager " + regionManager + "
injected.");
+ if (trace) log.trace("Having region manager " + regionManager + "
injected.");
this.regionManager = regionManager;
}
public EvictionInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -100,7 +99,7 @@
{
if (newData == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Putting null data under fqn " + fqn +
".");
}
@@ -128,7 +127,7 @@
{
if (data == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Putting null data under fqn " + fqn +
".");
}
@@ -153,7 +152,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Element does not exist");
}
@@ -175,7 +174,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Node does not exist");
}
@@ -202,7 +201,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Element does not exist");
}
@@ -249,12 +248,12 @@
Region region = regionManager.getRegion(event.getFqn(), false);
region.putNodeEvent(event);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Adding event " + event + " to region at " +
region.getFqn());
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Finished updating node");
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -49,10 +49,17 @@
protected Log log = null;
protected Configuration configuration;
private boolean statsEnabled = false;
+ protected boolean trace;
public Interceptor()
{
+ initLogger();
+ }
+
+ protected void initLogger()
+ {
log = LogFactory.getLog(getClass());
+ trace = log.isTraceEnabled();
}
public void setNext(Interceptor i)
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -56,7 +55,7 @@
public InvalidationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
public void setCache(CacheSPI cache)
@@ -81,7 +80,7 @@
// skip replication!!
return true;
}
- if (log.isTraceEnabled()) log.trace("(" + cache.getLocalAddress() +
") method call " + ctx.getMethodCall());
+ if (trace) log.trace("(" + cache.getLocalAddress() + ") method call
" + ctx.getMethodCall());
return false;
}
@@ -338,7 +337,7 @@
if (log.isDebugEnabled()) log.debug("Cache [" + cache.getLocalAddress() +
"] replicating " + call);
// voila, invalidated!
- replicateCall(call, synchronous, ctx.getOptionOverrides());
+ replicateCall(ctx, call, synchronous, ctx.getOptionOverrides());
}
protected DataVersion getNodeVersion(TransactionWorkspace w, Fqn f)
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Option;
import org.jboss.cache.marshall.MethodCall;
@@ -25,7 +24,7 @@
{
public InvocationContextInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -37,9 +36,11 @@
Transaction suspendedTransaction = null;
boolean resumeSuspended = false;
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Invoked on cache instance [" + cache.getLocalAddress() +
"] and InvocationContext [" + ctx + "]");
+ if (MethodDeclarations.isBlockUnblockMethod(call.getMethodId())) return
nextInterceptor(ctx);
+
try
{
Transaction tx = getTransaction();
@@ -56,12 +57,12 @@
{
suspendedTransaction = txManager.suspend();
setTransactionalContext(null, null, ctx);
- if (log.isTraceEnabled()) log.trace("Suspending transaction "
+ suspendedTransaction);
+ if (trace) log.trace("Suspending transaction " +
suspendedTransaction);
resumeSuspended = true;
}
else
{
- log.trace("No ongoing transaction to suspend");
+ if (trace) log.trace("No ongoing transaction to suspend");
}
}
}
@@ -92,7 +93,7 @@
finally
{
// clean up any invocation-scope options set up
- log.trace("Resetting invocation-scope options");
+ if (trace) log.trace("Resetting invocation-scope options");
ctx.getOptionOverrides().reset();
if (resumeSuspended)
@@ -111,16 +112,9 @@
private GlobalTransaction getGlobalTransaction(Transaction tx, MethodCall call)
{
- GlobalTransaction gtx = null;
- if (MethodDeclarations.isTransactionLifecycleMethod(call.getMethodId()))
- {
- gtx = findGlobalTransaction(call.getArgs());
- gtx.setRemote(isRemoteGlobalTx(gtx));
- }
- else
- {
- gtx = cache.getCurrentTransaction(tx, false);
- }
+ GlobalTransaction gtx = findGlobalTransaction(call.getArgs());
+ if (gtx == null) gtx = cache.getCurrentTransaction(tx, false);
+ if (gtx != null) gtx.setRemote(isRemoteGlobalTx(gtx));
return gtx;
}
@@ -130,7 +124,7 @@
// this creates a context if one did not exist.
if (txManager == null)
{
- log.trace("no transaction manager configured, setting tx as null.");
+ if (trace) log.trace("no transaction manager configured, setting tx as
null.");
return null;
}
else
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -10,10 +10,8 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jgroups.Address;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* The purpose of this interceptor is to supply a nicer way of handling the interception
of desired methods:
@@ -36,32 +34,37 @@
public abstract class MethodDispacherInterceptor extends Interceptor
{
/**
- * List of the method the extending interceptor pverwrites. It is only those methods
that will be called.
+ * Methods that have been overridden. This is encoded in the bits of an integer, with
each ordinal position representing a method id.
+ * This was originally a Set but that proved way too inefficient with constant
boxing/unboxing of ints and doing Set.contains()
+ * for each invocation for each interceptor. - Manik, Jan '08.
*/
- private Set<Integer> overriddenMethods = new HashSet<Integer>();
+ private long overriddenMethods = 0;
protected MethodDispacherInterceptor()
{
findOverriddenMethods();
}
+ private boolean noHandlersRegistered(int id)
+ {
+ return (overriddenMethods & ((long) 1 << id)) < 1;
+ }
+
/**
* Acts like a 'switch case' that delegates the call to the appropriate
method.
*/
public Object invoke(InvocationContext ctx) throws Throwable
{
- if (log.isTraceEnabled())
- {
- log.trace("Invoked with method call " + ctx.getMethodCall());
- }
+ if (trace) log.trace("Invoked with method call " + ctx.getMethodCall());
+
if (skipMethodCall(ctx))
{
return nextInterceptor(ctx);
}
MethodCall m = ctx.getMethodCall();
- if (!overriddenMethods.contains(m.getMethodId()))
+ if (noHandlersRegistered(m.getMethodId()))
{
- log.trace("Not registered for any handlers, passing up the chain.");
+ if (trace) log.trace("Not registered for any handlers, passing up the
chain.");
return nextInterceptor(ctx);
}
Object[] args = m.getArgs();
@@ -468,7 +471,7 @@
*/
private Object defaultHandlersBehavior()
{
- throw new IllegalStateException("this is either called from a derived class or
nt overwritten and accidentally called. Either way, is not correct.");
+ throw new IllegalStateException("this is either called from a derived class or
not overridden and accidentally called. Either way, is not correct.");
}
/**
@@ -510,7 +513,6 @@
checkIfOverridden(MethodDeclarations.blockChannelMethodLocal_id,
"handleBlockChannelMethod", InvocationContext.class);
checkIfOverridden(MethodDeclarations.unblockChannelMethodLocal_id,
"handleUnblockChannelMethod", InvocationContext.class);
checkIfOverridden(MethodDeclarations.lockMethodLocal_id,
"handleLockMethod", InvocationContext.class, Fqn.class, NodeLock.LockType.class,
boolean.class);
-
}
private void checkIfOverridden(int methodId, String methodName, Class... args)
@@ -522,7 +524,7 @@
try
{
currentClass.getDeclaredMethod(methodName, args);
- this.overriddenMethods.add(methodId);
+ overriddenMethods |= ((long) 1 << methodId);
}
catch (NoSuchMethodException e)
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -14,7 +13,7 @@
{
public NotificationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -40,6 +40,11 @@
*/
private NodeFactory nodeFactory;
+ public OptimisticCreateIfNotExistsInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(NodeFactory nodeFactory)
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -29,15 +29,12 @@
{
protected TransactionManager txManager = null;
protected TransactionTable txTable = null;
- protected boolean trace;
@Inject
private void injectDependencies(TransactionManager txManager, TransactionTable
txTable)
{
this.txManager = txManager;
this.txTable = txTable;
- trace = log != null && log.isTraceEnabled();
-
}
protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws
CacheException
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -41,6 +41,11 @@
lockAcquisitionTimeout = cache.getConfiguration().getLockAcquisitionTimeout();
}
+ public OptimisticLockingInterceptor()
+ {
+ initLogger();
+ }
+
@Override
protected Object handleOptimisticPrepareMethod(InvocationContext ctx,
GlobalTransaction gtx, List modifications, Map data, Address address, boolean
onePhaseCommit) throws Throwable
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -51,6 +51,11 @@
this.nodeFactory = nodeFactory;
}
+ public OptimisticNodeInterceptor()
+ {
+ initLogger();
+ }
+
@Override
public Object invoke(InvocationContext ctx) throws Throwable
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -49,7 +48,7 @@
public OptimisticReplicationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -189,7 +188,7 @@
+ " (" + num_mods + " modifications");
}
- replicateCall(toBroadcast, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, toBroadcast, remoteCallSync, ctx.getOptionOverrides());
}
else
{
@@ -218,7 +217,7 @@
if (log.isDebugEnabled())
log.debug("running remote commit for " + gtx + " and
coord=" + cache.getLocalAddress());
- replicateCall(commit_method, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, commit_method, remoteCallSync, ctx.getOptionOverrides());
}
catch (Exception e)
{
@@ -242,7 +241,7 @@
if (log.isDebugEnabled())
log.debug("running remote rollback for " + gtx + " and
coord=" + cache.getLocalAddress());
- replicateCall(rollback_method, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, rollback_method, remoteCallSync,
ctx.getOptionOverrides());
}
catch (Exception e)
{
@@ -306,13 +305,13 @@
WorkspaceNode n = w.getNode(f);
if (n == null)
{
- if (log.isTraceEnabled()) log.trace("Fqn " + f + " not found in
workspace; not using a data version.");
+ if (trace) log.trace("Fqn " + f + " not found in workspace; not
using a data version.");
return null;
}
if (n.isVersioningImplicit())
{
DefaultDataVersion v = (DefaultDataVersion) n.getVersion();
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Fqn " + f + " has implicit versioning.
Broadcasting an incremented version.");
// potential bug here - need to check if we *need* to increment at all, because
of Configuration.isLockParentForChildInsertRemove()
@@ -320,7 +319,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("Fqn " + f + " has explicit
versioning. Broadcasting the version as-is.");
+ if (trace) log.trace("Fqn " + f + " has explicit versioning.
Broadcasting the version as-is.");
return n.getVersion();
}
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -47,6 +47,11 @@
{
private boolean useTombstones;
+ public OptimisticValidatorInterceptor()
+ {
+ initLogger();
+ }
+
@Override
public void setCache(CacheSPI cache)
{
@@ -189,7 +194,7 @@
boolean updateVersion = false;
if (workspaceNode.isChildrenModified())
{
- log.trace("Updating children since node has modified
children");
+ if (trace) log.trace("Updating children since node has modified
children");
// merge children.
List<Set<Fqn>> deltas = workspaceNode.getMergedChildren();
@@ -220,7 +225,7 @@
if (workspaceNode.isModified())
{
- log.trace("Merging data since node is dirty");
+ if (trace) log.trace("Merging data since node is dirty");
Map mergedData = workspaceNode.getMergedData();
underlyingNode.clearDataDirect();
underlyingNode.putAllDirect(mergedData);
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -27,7 +26,7 @@
public PassivationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@@ -60,7 +59,7 @@
}
catch (NodeNotLoadedException e)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Node " + fqn + " not loaded in memory; passivation
skipped");
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -53,19 +52,23 @@
{
private TransactionTable tx_table;
private CacheImpl cacheImpl;
+ private NodeSPI rootNode;
+
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks
held by that thread
*/
private Map<Thread, List<NodeLock>> lockTable;
+ // private ThreadLocal<List<NodeLock>> lockTable;
private long lock_acquisition_timeout;
public PessimisticLockInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Inject
public void injectDependencies(@ComponentName("LockTable")Map<Thread,
List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl,
TransactionTable txTable)
+// public void
injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>>
lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
{
this.lockTable = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
@@ -73,6 +76,13 @@
this.tx_table = txTable;
}
+ @Override
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ if (rootNode == null) rootNode = cache.getRoot();
+ return super.invoke(ctx);
+ }
+
protected Object handlePutDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn
fqn, Map data, boolean createUndoOps) throws Throwable
{
return handlePutMethod(ctx, fqn);
@@ -93,10 +103,9 @@
{
if ((ctx.getOptionOverrides() != null &&
ctx.getOptionOverrides().isSuppressLocking()) || configuration.getIsolationLevel() ==
IsolationLevel.NONE)
{
- log.trace("Suppressing locking");
- log.trace("Creating nodes if necessary");
+ if (trace) log.trace("Suppressing locking, creating nodes if
necessary");
int treeNodeSize = fqn.size();
- NodeSPI n = cache.getRoot();
+ NodeSPI n = rootNode;
for (int i = 0; i < treeNodeSize; i++)
{
Object childName = fqn.get(i);
@@ -149,7 +158,7 @@
protected Object handleCommitMethod(InvocationContext ctx, GlobalTransaction
globalTransaction) throws Throwable
{
commit(globalTransaction);
- log.trace("bypassed locking as method commit() doesn't require
locking");
+ if (trace) log.trace("bypassed locking as method commit() doesn't require
locking");
Object retVal = nextInterceptor(ctx);
tx_table.cleanup(globalTransaction);
return retVal;
@@ -158,7 +167,7 @@
protected Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction
globalTransaction) throws Throwable
{
TransactionEntry entry = tx_table.get(globalTransaction);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("called to rollback cache with GlobalTransaction=" +
globalTransaction);
}
@@ -178,7 +187,7 @@
// 1. Revert the modifications by running the undo-op list in reverse. This
*cannot* throw any exceptions !
entry.undoOperations(cache);
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("bypassed locking as method rollback() doesn't require
locking");
}
@@ -191,7 +200,7 @@
{
long timeout = ctx.getContextLockAcquisitionTimeout(lock_acquisition_timeout);
// this call will ensure the node gets a WL and it's current parent gets RL.
- if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved
[" + from + "]");
+ if (trace) log.trace("Attempting to get WL on node to be moved [" + from
+ "]");
if (from != null && !(configuration.getIsolationLevel() ==
IsolationLevel.NONE))
{
lock(ctx, from, NodeLock.LockType.WRITE, false, timeout, true, false);
@@ -204,7 +213,7 @@
if (to != null && !(configuration.getIsolationLevel() ==
IsolationLevel.NONE))
{
//now for an RL for the new parent.
- if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent
[" + to + "]");
+ if (trace) log.trace("Attempting to get RL on new parent [" + to +
"]");
lock(ctx, to, NodeLock.LockType.READ, false, timeout, false, false);
acquireLocksOnChildren(cache.peek(to, true), NodeLock.LockType.READ, ctx);
}
@@ -225,7 +234,7 @@
{
cache.getTransactionTable().get(ctx.getGlobalTransaction()).addRemovedNode(fqn);
}
- acquireLocksOnChildren(cache.getRoot().getChildDirect(fqn),
NodeLock.LockType.WRITE, ctx);
+ acquireLocksOnChildren(rootNode.getChildDirect(fqn), NodeLock.LockType.WRITE,
ctx);
Object retVal = nextInterceptor(ctx);
if (ctx.getGlobalTransaction() == null)
{
@@ -355,9 +364,9 @@
}
Object owner = (gtx != null) ? gtx : currentThread;
NodeSPI currentNode;
- if (log.isTraceEnabled()) log.trace("Attempting to lock node " + fqn +
" for owner " + owner);
+ if (trace) log.trace("Attempting to lock node " + fqn + " for owner
" + owner);
long expiryTime = System.currentTimeMillis() + timeout;
- currentNode = cache.getRoot();
+ currentNode = rootNode;
NodeSPI parent = null;
Object childName = null;
int currentIndex = -1;
@@ -369,11 +378,11 @@
{
currentNode = parent.addChildDirect(new Fqn(childName));
created = true;
- if (log.isTraceEnabled()) log.trace("Child node was null, so created
child node " + childName);
+ if (trace) log.trace("Child node was null, so created child node
" + childName);
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
log.trace("failed to find or create child " + childName +
" of node " + currentNode);
return false;
}
@@ -394,7 +403,7 @@
NodeSPI repeek = cache.peek(currentNode.getFqn(), true, true);
if (currentNode != repeek)
{
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Was waiting for and obtained a lock on a node that
doesn't exist anymore! Attempting lock acquisition again.");
// we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and
potentially recreate the node).
// check if the parent exists!!
@@ -403,9 +412,9 @@
if (cache.peek(parent.getFqn(), true, true) == null)
{
// crap!
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Parent has been deleted again. Go through the lock
method all over again.");
- currentNode = cache.getRoot();
+ currentNode = rootNode;
parent = null;
}
else
@@ -472,7 +481,7 @@
int treeNodeSize = targetFqn.size();
// write lock forced!!
boolean isTargetNode = currentNodeIndex == (treeNodeSize - 1);
- if (ctx.getOptionOverrides().isForceWriteLock() && isTargetNode) return
true;
+ if (isTargetNode && ctx.getOptionOverrides().isForceWriteLock()) return
true;
//this can be injected, from the caller as a param named wlParent
if (currentNode.isLockForChildInsertRemove())
{
@@ -480,7 +489,8 @@
{
return true;// we're doing a remove and we've reached the PARENT node
of the target to be removed.
}
- if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(),
targetFqn.get(currentNodeIndex + 1)), false) == null)
+ if (!isTargetNode && cache.peek(targetFqn.getAncestor(currentNodeIndex +
2), false) == null)
+ //if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(),
targetFqn.get(currentNodeIndex + 1)), false) == null)
{
return createIfNotExists;// we're at a node in the tree, not yet at the
target node, and we need to create the next node. So we need a WL here.
}
@@ -490,11 +500,11 @@
private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx,
NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException,
InterruptedException
{
- boolean acquired = node.getLock().acquire(owner, lockTimeout, lockType);
+ NodeLock lock = node.getLock();
+ boolean acquired = lock.acquire(owner, lockTimeout, lockType);
if (acquired)
{
// Record the lock for release on method return or tx commit/rollback
- NodeLock lock = node.getLock();
if (gtx != null)
{
cache.getTransactionTable().recordNodeLock(gtx, lock);
@@ -520,6 +530,7 @@
if (locks == null)
{
locks = Collections.synchronizedList(new LinkedList<NodeLock>());
+// lockTable.set(locks);
lockTable.put(currentThread, locks);
}
return locks;
@@ -544,7 +555,7 @@
*/
private void commit(GlobalTransaction gtx)
{
- if (log.isTraceEnabled()) log.trace("committing cache with gtx " + gtx);
+ if (trace) log.trace("committing cache with gtx " + gtx);
TransactionEntry entry = tx_table.get(gtx);
if (entry == null)
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Configuration;
@@ -26,7 +25,7 @@
{
public ReplicationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
protected boolean skipMethodCall(InvocationContext ctx)
@@ -34,7 +33,7 @@
Option optionOverride = ctx.getOptionOverrides();
if (optionOverride != null && optionOverride.isCacheModeLocal() &&
ctx.getTransaction() == null)
{
- log.trace("skip replication");
+ if (trace) log.trace("skip replication");
return true;
}
return false;
@@ -46,7 +45,7 @@
{
return nextInterceptor(ctx);
}
- replicateCall(ctx.getMethodCall(), configuration.isSyncCommitPhase(),
ctx.getOptionOverrides());
+ replicateCall(ctx, ctx.getMethodCall(), configuration.isSyncCommitPhase(),
ctx.getOptionOverrides());
return nextInterceptor(ctx);
}
@@ -69,7 +68,7 @@
}
if (!ctx.isLocalRollbackOnly())
{
- replicateCall(ctx.getMethodCall(), configuration.isSyncRollbackPhase(),
ctx.getOptionOverrides());
+ replicateCall(ctx, ctx.getMethodCall(), configuration.isSyncRollbackPhase(),
ctx.getOptionOverrides());
}
return nextInterceptor(ctx);
@@ -101,7 +100,7 @@
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
boolean isInitiatedHere = gtx != null && !gtx.isRemote();
- if (log.isTraceEnabled()) log.trace("isInitiatedHere? " + isInitiatedHere
+ "; gtx = " + gtx);
+ if (trace) log.trace("isInitiatedHere? " + isInitiatedHere + "; gtx
= " + gtx);
return !isTransactionalAndLocal(ctx) || !containsModifications(ctx);
}
@@ -202,7 +201,7 @@
if (ctx.getTransaction() == null && ctx.isOriginLocal())
{
MethodCall m = ctx.getMethodCall();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("invoking method " + m + ", members=" +
cache.getMembers() + ", mode=" +
configuration.getCacheMode() + ", exclude_self=" + true +
", timeout=" +
@@ -211,13 +210,13 @@
if (!isSynchronous(ctx.getOptionOverrides()) || m.getMethodId() ==
MethodDeclarations.putForExternalReadMethodLocal_id)
{
// 2. Replicate change to all *other* members (exclude self !)
- replicateCall(m, false, ctx.getOptionOverrides());
+ replicateCall(ctx, m, false, ctx.getOptionOverrides());
}
else
{
// REVISIT Needs to exclude itself and apply the local change manually.
// This is needed such that transient field is modified properly in-VM.
- replicateCall(m, true, ctx.getOptionOverrides());
+ replicateCall(ctx, m, true, ctx.getOptionOverrides());
}
}
return returnValue;
@@ -240,12 +239,12 @@
protected void runPreparePhase(MethodCall prepareMethod, GlobalTransaction gtx,
InvocationContext ctx) throws Throwable
{
boolean async = configuration.getCacheMode() ==
Configuration.CacheMode.REPL_ASYNC;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + cache.getLocalAddress() + "): running remote
prepare for global tx " + gtx + " with async mode=" + async);
}
// this method will return immediately if we're the only member (because
exclude_self=true)
- replicateCall(prepareMethod, !async, ctx.getOptionOverrides());
+ replicateCall(ctx, prepareMethod, !async, ctx.getOptionOverrides());
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -58,7 +57,7 @@
public TxInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@SuppressWarnings("unchecked")
@@ -82,7 +81,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("received my own message (discarding
it)");
+ if (trace) log.trace("received my own message (discarding it)");
result = null;
}
}
@@ -109,7 +108,7 @@
boolean scrubTxsOnExit = false;
try
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + cache.getLocalAddress() + ") call on method
[" + ctx.getMethodCall() + "]");
}
@@ -120,7 +119,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("received my own message (discarding
it)");
+ if (trace) log.trace("received my own message (discarding it)");
result = null;
}
}
@@ -287,7 +286,8 @@
boolean shouldRethtrow = optionOverride == null ||
!optionOverride.isFailSilently();
if (!shouldRethtrow)
{
- log.trace("There was a problem handling this request, but failSilently was
set, so suppressing exception", e);
+ if (trace)
+ log.trace("There was a problem handling this request, but failSilently
was set, so suppressing exception", e);
}
throw e;
}
@@ -372,7 +372,7 @@
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Resuming existing transaction " + ltx + ", global
TX=" + gtx);
}
@@ -391,7 +391,7 @@
entry.setTransaction(ltx);
log.debug("creating new tx entry");
txTable.put(gtx, entry);
- if (log.isTraceEnabled()) log.trace("TxTable contents: " +
txTable);
+ if (trace) log.trace("TxTable contents: " + txTable);
}
setTransactionalContext(ltx, gtx, ctx);
@@ -513,7 +513,7 @@
{
log.debug(" local transaction exists - registering global tx if not present
for " + Thread.currentThread());
}
- if (log.isTraceEnabled())
+ if (trace)
{
GlobalTransaction tempGtx = txTable.get(tx);
log.trace("Associated gtx in txTable is " + tempGtx);
@@ -575,7 +575,8 @@
replayModifications(modifications, ctx, false);
if (m.isOnePhaseCommitPrepareMehod())
{
- log.trace("Using one-phase prepare. Not propagating the prepare call
up the stack until called to do so by the sync handler.");
+ if (trace)
+ log.trace("Using one-phase prepare. Not propagating the prepare
call up the stack until called to do so by the sync handler.");
}
else
{
@@ -604,7 +605,7 @@
finally
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Are we running a 1-phase commit? " + commit);
}
@@ -788,7 +789,7 @@
//resume the old transaction if we suspended it
if (resumeCurrentTxOnCompletion)
{
- if (log.isTraceEnabled()) log.trace("Resuming suspended transaction
" + currentTx);
+ if (trace) log.trace("Resuming suspended transaction " +
currentTx);
txManager.suspend();
if (currentTx != null)
{
@@ -887,7 +888,7 @@
commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod,
gtx);
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(" running commit for " + gtx);
}
@@ -942,7 +943,7 @@
// JBCACHE-457
// MethodCall rollbackMethod = MethodCall(CacheImpl.rollbackMethod,
new Object[]{gtx, hasMods ? true : false});
MethodCall rollbackMethod =
MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(" running rollback for " + gtx);
}
@@ -993,7 +994,7 @@
else
{
// this is a REPL_ASYNC call - do 1-phase commit. break!
- log.trace("This is a REPL_ASYNC call (1 phase commit) - do nothing for
beforeCompletion()");
+ if (trace) log.trace("This is a REPL_ASYNC call (1 phase commit) - do
nothing for beforeCompletion()");
return null;
}
@@ -1040,14 +1041,14 @@
if (gtx.isRemote())
{
// should be no need to register a handler since this a remotely initiated
gtx
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("is a remotely initiated gtx so no need to register a tx
for it");
}
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Registering sync handler for tx " + tx + ", gtx
" + gtx);
}
@@ -1079,7 +1080,7 @@
{
OrderedSynchronizationHandler orderedHandler =
OrderedSynchronizationHandler.getInstance(tx);
- if (log.isTraceEnabled()) log.trace("registering for TX completion:
SynchronizationHandler(" + handler + ")");
+ if (trace) log.trace("registering for TX completion:
SynchronizationHandler(" + handler + ")");
orderedHandler.registerAtHead(handler);// needs to be invoked first on TX commit
@@ -1117,7 +1118,7 @@
*/
private Transaction createLocalTx() throws Exception
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Creating transaction for thread " +
Thread.currentThread());
}
@@ -1141,7 +1142,7 @@
txTable.put(localTx, gtx);
// attach this to the context
ctx.setTransaction(localTx);
- if (log.isTraceEnabled()) log.trace("Created new tx for gtx " + gtx);
+ if (trace) log.trace("Created new tx for gtx " + gtx);
return localTx;
}
@@ -1169,7 +1170,7 @@
public void beforeCompletion()
{
- if (log.isTraceEnabled()) log.trace("Running beforeCompletion on gtx "
+ gtx);
+ if (trace) log.trace("Running beforeCompletion on gtx " + gtx);
entry = txTable.get(gtx);
if (entry == null)
{
@@ -1220,7 +1221,7 @@
}
- if (log.isTraceEnabled()) log.trace("calling aftercompletion for "
+ gtx);
+ if (trace) log.trace("calling aftercompletion for " + gtx);
// set any transaction wide options as current for this thread.
if (entry != null)
{
@@ -1334,7 +1335,7 @@
setTransactionalContext(tx, gtx, ctx);
if (modifications.size() == 0)
{
- if (log.isTraceEnabled()) log.trace("No modifications in this tx.
Skipping beforeCompletion()");
+ if (trace) log.trace("No modifications in this tx. Skipping
beforeCompletion()");
return;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-01-03
13:29:35 UTC (rev 4967)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -3,12 +3,10 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.NodeLock;
import javax.transaction.Transaction;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
/**
@@ -22,10 +20,16 @@
{
Map<Thread, List<NodeLock>> lockTable = null;
- boolean trace = log.isTraceEnabled();
+// ThreadLocal<List<NodeLock>> lockTable;
+ public UnlockInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(@ComponentName("LockTable")Map<Thread,
List<NodeLock>> lockTable)
+// private void
injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>>
lockTable)
{
this.lockTable = lockTable;
}
@@ -52,7 +56,7 @@
else
{ // no TX
Thread currentThread = Thread.currentThread();
- List locks = lockTable.get(currentThread);
+ List<NodeLock> locks = lockTable.get(currentThread);
if (trace) log.trace("Attempting to release locks on current thread.
Lock table is " + lockTable);
if (locks != null && locks.size() > 0)
@@ -65,15 +69,13 @@
}
}
- private void releaseLocks(List locks, Thread currentThread)
+ private void releaseLocks(List<NodeLock> locks, Thread currentThread)
{
- IdentityLock lock;
- for (ListIterator it = locks.listIterator(locks.size()); it.hasPrevious();)
+ NodeLock[] locksArray = locks.toArray(new NodeLock[]{});
+ for (int i = locksArray.length - 1; i > -1; i--)
{
- lock = (IdentityLock) it.previous();
- if (trace)
- log.trace("releasing lock for " + lock.getFqn() + ": " +
lock);
- lock.release(currentThread);
+ if (trace) log.trace("releasing lock for " + locksArray[i].getFqn() +
": " + locksArray[i]);
+ locksArray[i].release(currentThread);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-03 13:29:35 UTC
(rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-03 19:17:09 UTC
(rev 4968)
@@ -1,5 +1,7 @@
package org.jboss.cache.lock;
+import org.jboss.cache.Fqn;
+
import java.util.Collection;
import java.util.Set;
@@ -9,12 +11,13 @@
*/
public interface NodeLock
{
-
public enum LockType
{
NONE, READ, WRITE
}
+ Fqn getFqn();
+
/**
* Returns a copy of the reader lock owner in List.
* Size is zero is not available. Note that this list
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -38,11 +38,6 @@
{
private static Log log = LogFactory.getLog(MethodDeclarations.class);
- static final Set<Integer> crudMethodIds = new HashSet<Integer>();
- static final Set<Integer> transactionLifecycleMethodIds = new
HashSet<Integer>();
- static final Set<Integer> buddyGroupOrganisationMethodIds = new
HashSet<Integer>();
- static final Set<Integer> blockUnblockMethodIds = new HashSet<Integer>();
- static final Set<Integer> putMethodIds = new HashSet<Integer>();
static final Set<Integer> methodsThatNeedToReturnValuesToRemoteCallers = new
HashSet<Integer>();
// maintain a list of method IDs that correspond to Methods in CacheImpl
@@ -356,42 +351,9 @@
{
methodIds.put(methods.get(id), id);
}
-
- putMethodIds.add(putDataMethodLocal_id);
- putMethodIds.add(putDataEraseMethodLocal_id);
- putMethodIds.add(putKeyValMethodLocal_id);
- putMethodIds.add(putDataEraseVersionedMethodLocal_id);
- putMethodIds.add(putDataVersionedMethodLocal_id);
- putMethodIds.add(putKeyValVersionedMethodLocal_id);
- putMethodIds.add(putForExternalReadMethodLocal_id);
- putMethodIds.add(putForExternalReadVersionedMethodLocal_id);
-
- crudMethodIds.addAll(putMethodIds);
- crudMethodIds.add(removeNodeMethodLocal_id);
- crudMethodIds.add(removeKeyMethodLocal_id);
- crudMethodIds.add(removeDataMethodLocal_id);
- crudMethodIds.add(dataGravitationCleanupMethod_id);
- crudMethodIds.add(moveMethodLocal_id);
- crudMethodIds.add(removeNodeVersionedMethodLocal_id);
- crudMethodIds.add(removeKeyVersionedMethodLocal_id);
- crudMethodIds.add(removeDataVersionedMethodLocal_id);
-
-
- transactionLifecycleMethodIds.add(commitMethod_id);
- transactionLifecycleMethodIds.add(rollbackMethod_id);
- transactionLifecycleMethodIds.add(prepareMethod_id);
- transactionLifecycleMethodIds.add(optimisticPrepareMethod_id);
-
- buddyGroupOrganisationMethodIds.add(remoteAnnounceBuddyPoolNameMethod_id);
- buddyGroupOrganisationMethodIds.add(remoteAssignToBuddyGroupMethod_id);
- buddyGroupOrganisationMethodIds.add(remoteRemoveFromBuddyGroupMethod_id);
-
- blockUnblockMethodIds.add(blockChannelMethodLocal_id);
- blockUnblockMethodIds.add(unblockChannelMethodLocal_id);
-
}
- protected static int lookupMethodId(Method method)
+ public static int lookupMethodId(Method method)
{
Integer methodIdInteger = methodIds.get(method);
int methodId = -1;
@@ -411,7 +373,7 @@
return methodId;
}
- protected static Method lookupMethod(int id)
+ public static Method lookupMethod(int id)
{
Method method = methods.get(id);
if (method == null)
@@ -430,22 +392,39 @@
*/
public static boolean isCrudMethod(int id)
{
- return crudMethodIds.contains(Integer.valueOf(id));
+ return isPutMethod(id) ||
+ id == removeNodeMethodLocal_id ||
+ id == removeKeyMethodLocal_id ||
+ id == removeDataMethodLocal_id ||
+ id == dataGravitationCleanupMethod_id ||
+ id == moveMethodLocal_id ||
+ id == removeNodeVersionedMethodLocal_id ||
+ id == removeKeyVersionedMethodLocal_id ||
+ id == removeDataVersionedMethodLocal_id;
}
public static boolean isTransactionLifecycleMethod(int id)
{
- return transactionLifecycleMethodIds.contains(id);
+ // transactional lifecycle methods consist of just commit, rollback, prepare and
optimistic prepare.
+ return id == commitMethod_id || id == optimisticPrepareMethod_id || id ==
prepareMethod_id || id == rollbackMethod_id;
}
public static boolean isBuddyGroupOrganisationMethod(int id)
{
- return buddyGroupOrganisationMethodIds.contains(id);
+ return id == remoteAssignToBuddyGroupMethod_id || id ==
remoteRemoveFromBuddyGroupMethod_id || id == remoteAnnounceBuddyPoolNameMethod_id;
}
public static boolean isPutMethod(int id)
{
- return putMethodIds.contains(id);
+ return
+ id == putDataMethodLocal_id ||
+ id == putDataEraseMethodLocal_id ||
+ id == putKeyValMethodLocal_id ||
+ id == putDataEraseVersionedMethodLocal_id ||
+ id == putDataVersionedMethodLocal_id ||
+ id == putKeyValVersionedMethodLocal_id ||
+ id == putForExternalReadMethodLocal_id ||
+ id == putForExternalReadVersionedMethodLocal_id;
}
public static boolean isGetMethod(int methodId)
@@ -456,7 +435,7 @@
public static boolean isBlockUnblockMethod(int id)
{
- return blockUnblockMethodIds.contains(id);
+ return id == blockChannelMethodLocal_id || id == unblockChannelMethodLocal_id;
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/FqnTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-01-03 13:29:35 UTC (rev
4967)
+++ core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-01-03 19:17:09 UTC (rev
4968)
@@ -21,6 +21,7 @@
* @author <a href="mailto:bela@jboss.org">Bela Ban</a> May 9,
2003
* @version $Revision$
*/
+@Test(groups = "functional")
public class FqnTest
{
private Cache<Object, Object> cache;
@@ -41,7 +42,6 @@
}
}
- @Test(groups = {"functional"})
public void testNull()
{
Fqn fqn = new Fqn();
@@ -51,7 +51,6 @@
assert hcode != -1;
}
- @Test(groups = {"functional"})
public void testOne()
{
Fqn<Integer> fqn = new Fqn<Integer>(22);
@@ -61,7 +60,6 @@
assert hcode != -1;
}
- @Test(groups = {"functional"})
public void testEmptyFqn()
{
Fqn f1 = new Fqn();
@@ -69,7 +67,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testFqn()
{
Fqn<String> fqn = Fqn.fromString("/a/b/c");
@@ -83,7 +80,6 @@
assert fqn.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testHereogeneousNames()
{
Fqn<Object> fqn = new Fqn<Object>("string", 38, true);
@@ -95,7 +91,6 @@
assert fqn.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testHashcode()
{
Fqn fqn1, fqn2;
@@ -111,7 +106,6 @@
assert map.get(fqn1).equals(34);
}
- @Test(groups = {"functional"})
public void testHashcode2()
{
Fqn<Integer> fqn = new Fqn<Integer>(-1);
@@ -121,7 +115,6 @@
assert hcode == -1;
}
- @Test(groups = {"functional"})
public void testEquals()
{
Fqn<String> fqn1 = new Fqn<String>("person/test");
@@ -145,7 +138,6 @@
}
- @Test(groups = {"functional"})
public void testEquals2()
{
Fqn<String> f1;
@@ -161,7 +153,6 @@
assert !f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals2WithMarshalling() throws Exception
{
Fqn<String> f1, f2;
@@ -170,7 +161,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals3()
{
Fqn<Object> f1;
@@ -190,7 +180,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals3WithMarshalling() throws Exception
{
Fqn<Object> f1, f2;
@@ -212,7 +201,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals4()
{
Fqn<String> fqn = Fqn.fromString("X");
@@ -231,7 +219,6 @@
assert fqn1.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testNullElements() throws CloneNotSupportedException
{
Fqn<Object> fqn0 = new Fqn<Object>((Object) null);
@@ -246,7 +233,6 @@
assert fqn1.equals(fqn1.clone());
}
- @Test(groups = {"functional"})
public void testIteration()
{
Fqn<String> fqn = Fqn.fromString("/a/b/c");
@@ -263,7 +249,6 @@
assert fqn.equals(tmp_fqn);
}
- @Test(groups = {"functional"})
public void testIsChildOf()
{
Fqn<String> child = Fqn.fromString("/a/b");
@@ -277,14 +262,12 @@
assert child.isChildOf(parent);
}
- @Test(groups = {"functional"})
public void testIsChildOf2()
{
Fqn<String> child = Fqn.fromString("/a/b/c/d");
assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
}
- @Test(groups = {"functional"})
public void testParentage()
{
Fqn<String> fqnRoot = new Fqn<String>();
@@ -308,7 +291,6 @@
}
- @Test(groups = {"functional"})
public void testRoot()
{
Fqn<String> fqn = new Fqn<String>();
@@ -318,7 +300,6 @@
assert !fqn.isRoot();
}
- @Test(groups = {"functional"})
public void testGetName()
{
Fqn<Integer> integerFqn = new Fqn<Integer>(1);
@@ -329,7 +310,6 @@
assert object.toString().equals(objectFqn.getLastElementAsString());
}
- @Test(groups = {"functional"})
public void testCloningString() throws CloneNotSupportedException
{
Fqn<String> f = Fqn.fromString("/a/b/c");
@@ -343,7 +323,6 @@
assert f.equals(f.clone());
}
- @Test(groups = {"functional"})
public void testRemovalNonString() throws Exception
{
Fqn<Object> f = new Fqn<Object>("test", 1);
@@ -372,7 +351,6 @@
// testing generics
- @Test(groups = {"functional"})
public void testGenerics()
{
Fqn<String> f = Fqn.fromString("/blah/blah");
@@ -387,7 +365,21 @@
assert f3.getParent().equals(f4);
}
- @Test(groups = {"functional"})
+ public void testSize()
+ {
+ Fqn f = new Fqn();
+ assert f.size() == 0;
+ assert f.isRoot();
+
+ f = Fqn.fromString("/");
+ assert f.size() == 0;
+ assert f.isRoot();
+
+ f = Fqn.fromString("/hello");
+ assert f.size() == 1;
+ assert !f.isRoot();
+ }
+
public void testGenerations()
{
Fqn<Integer> f = new Fqn<Integer>(1, 2, 3, 4, 5, 6, 7);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -8,11 +8,10 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
-
import org.testng.annotations.Test;
+
/**
* Checks CRUD methods
*
@@ -32,8 +31,6 @@
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putKeyValVersionedMethodLocal_id));
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putForExternalReadMethodLocal_id));
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putForExternalReadVersionedMethodLocal_id));
-
- assertEquals(8, MethodDeclarations.putMethodIds.size());
}
public void testTransactionLifecycleMethods()
@@ -42,8 +39,6 @@
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.rollbackMethod_id));
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.prepareMethod_id));
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.optimisticPrepareMethod_id));
-
- assertEquals(4, MethodDeclarations.transactionLifecycleMethodIds.size());
}
public void testCrudMethods()
@@ -65,8 +60,6 @@
assertTrue(MethodDeclarations.isCrudMethod(MethodDeclarations.putForExternalReadMethodLocal_id));
assertTrue(MethodDeclarations.isCrudMethod(MethodDeclarations.putForExternalReadVersionedMethodLocal_id));
- assertEquals(16, MethodDeclarations.crudMethodIds.size());
-
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getKeyValueMethodLocal_id));
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getNodeMethodLocal_id));
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getKeysMethodLocal_id));
@@ -78,7 +71,5 @@
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteAnnounceBuddyPoolNameMethod_id));
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteAssignToBuddyGroupMethod_id));
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteRemoveFromBuddyGroupMethod_id));
-
- assertEquals(3, MethodDeclarations.buddyGroupOrganisationMethodIds.size());
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-01-03
13:29:35 UTC (rev 4967)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-01-03
19:17:09 UTC (rev 4968)
@@ -1,14 +1,16 @@
package org.jboss.cache.profiling;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
@@ -34,62 +36,34 @@
/*
Test configuration options
*/
- protected static final long DURATION = 2 * 60000;
+ protected static final long DURATION = 2 * 60 * 1000;
protected static final int NUM_THREADS = 10;
protected static final int MAX_RANDOM_SLEEP_MILLIS = 100;
protected static final int MAX_DEPTH = 8;
protected static final int MAX_OVERALL_NODES = 100;
+ protected static final int WARMUP_LOOPS = 10000;
-
private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
private Random r = new Random();
- @BeforeTest
- public void initialiseFqns()
- {
- fqns.clear();
- for (int i = 0; i < MAX_OVERALL_NODES; i++)
- {
- Fqn fqn = createRandomFqn(r);
- while (fqns.contains(fqn)) fqn = createRandomFqn(r);
- if (i % 100 == 0) System.out.println("Generated " + i + "
fqns");
- fqns.add(fqn);
- }
- System.gc();
- System.out.println("Finished initialising. Starting test.");
- }
+ private Log log = LogFactory.getLog(ProfileTest.class);
- private Fqn createRandomFqn(Random r)
- {
- String s = "/";
- int depth = r.nextInt(MAX_DEPTH);
- for (int i = 0; i < depth; i++)
- {
- s += r.nextInt(Integer.MAX_VALUE) + "/";
- }
-
- return Fqn.fromString(s);
- }
-
public void testReplSync() throws Exception
{
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplAsync() throws Exception
{
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplSyncOptimistic() throws Exception
{
cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplAsyncOptimistic() throws Exception
@@ -97,8 +71,7 @@
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplSyncBR() throws Exception
@@ -133,15 +106,92 @@
testReplAsyncOptimistic();
}
+ private void runCompleteTest() throws Exception
+ {
+ init();
+ startup();
+ warmup();
+ doTest();
+ }
+
+ /**
+ * Thr following test phases can be profiled individually using triggers in
JProfiler.
+ */
+
+ protected void init()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting init() phase");
+ fqns.clear();
+ for (int i = 0; i < MAX_OVERALL_NODES; i++)
+ {
+ Fqn fqn = createRandomFqn(r);
+ while (fqns.contains(fqn)) fqn = createRandomFqn(r);
+ if (i % 10 == 0)
+ {
+ log.warn("Generated " + i + " fqns");
+ }
+ fqns.add(fqn);
+ }
+ System.gc();
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished init() phase. " + printDuration(duration));
+ }
+
+ private Fqn createRandomFqn(Random r)
+ {
+ String s = "/";
+ int depth = r.nextInt(MAX_DEPTH);
+ for (int i = 0; i < depth; i++)
+ {
+ s += r.nextInt(Integer.MAX_VALUE) + "/";
+ }
+
+ return Fqn.fromString(s);
+ }
+
+
+ private void startup()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting cache");
+ cache.start();
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Started cache. " + printDuration(duration));
+ }
+
+ private void warmup()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting warmup");
+ // creates all the Fqns since this can be expensive and we don't really want to
measure this (for now)
+ for (Fqn f : fqns)
+ {
+ // this will create the necessary nodes.
+ cache.put(f, Collections.emptyMap());
+ }
+
+ // loop through WARMUP_LOOPS gets and puts for JVM optimisation
+ for (int i = 0; i < WARMUP_LOOPS; i++)
+ {
+ Fqn f = fqns.get(r.nextInt(MAX_OVERALL_NODES));
+ cache.get(f, "");
+ cache.put(f, "k", "v");
+ cache.remove(f, "k");
+ }
+
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished warmup. " + printDuration(duration));
+ }
+
private void doTest() throws Exception
{
ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
long end = System.currentTimeMillis() + DURATION;
- int i = 0;
- long start = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting test");
while (System.currentTimeMillis() < end)
{
- i++;
exec.execute(new Runnable()
{
public void run()
@@ -153,12 +203,12 @@
});
TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
}
-
+ log.warn("Finished generating runnables; awaiting executor completion");
// wait for executors to complete!
exec.shutdown();
exec.awaitTermination(10000, TimeUnit.MILLISECONDS);
- double durationSecs = (System.currentTimeMillis() - start) / 1000;
- System.out.println("Completed Test! Achieved " + ((double) i /
durationSecs) + " TPS.");
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished test. " + printDuration(duration));
}
private String getRandomString()
@@ -172,4 +222,17 @@
}
return sb.toString();
}
+
+ private String printDuration(long duration)
+ {
+ if (duration > 2000)
+ {
+ double dSecs = ((double) duration / (double) 1000);
+ return "Duration: " + dSecs + " seconds";
+ }
+ else
+ {
+ return "Duration: " + duration + " millis";
+ }
+ }
}