[jboss-cvs] JBossAS SVN: r77963 - trunk/cluster/src/main/org/jboss/invocation/unified/interfaces.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 4 07:27:09 EDT 2008
Author: galder.zamarreno at jboss.com
Date: 2008-09-04 07:27:09 -0400 (Thu, 04 Sep 2008)
New Revision: 77963
Modified:
trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
Log:
[JBAS-5923] Weak hash map is now a synchronized map in order to avoid k,v pairs dissapearing under load. Removed any synchronization on tpc except if putIfAbsent type of operations done.
Modified: trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java 2008-09-04 11:26:08 UTC (rev 77962)
+++ trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java 2008-09-04 11:27:09 UTC (rev 77963)
@@ -30,7 +30,9 @@
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.WeakHashMap;
import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
@@ -65,7 +67,7 @@
private FamilyClusterInfo familyClusterInfo = null;
- public static final WeakHashMap txFailoverAuthorizations = new WeakHashMap();
+ public static final Map txFailoverAuthorizations = Collections.synchronizedMap(new WeakHashMap());
/** Trace level logging flag only set when the proxy is created or read from JNDI */
private static boolean trace = false;
@@ -102,13 +104,16 @@
Object tpc = getTransactionPropagationContext();
if(tpc != null)
{
+ if (trace)
+ {
+ log.trace("Checking tx failover authorisation map with tpc " + tpc);
+ }
+
+ /* Synchronise on tpc because we're updating the map if it doesn't
+ * contain tpc upon failover (putIfAbsent type of operation). This is
+ * still needed even if the collection is synchronized. */
synchronized(tpc)
{
- if (trace)
- {
- log.trace("Checking tx failover authorisation map with tpc " + tpc);
- }
-
/* If the map contains the tpc, then we can't allow a failover */
boolean failoverAuthorised = ! txFailoverAuthorizations.containsKey(tpc);
@@ -123,7 +128,7 @@
invocation.getTransientPayload().put("TX_STICKY_TARGET", null);
}
- return failoverAuthorised;
+ return failoverAuthorised;
}
}
@@ -135,22 +140,19 @@
Object tpc = getTransactionPropagationContext();
if(tpc != null)
{
- synchronized(tpc)
+ if (trace)
{
- if (trace)
- {
- log.trace("After reaching the server, transaction propagation context (tpc) is " + tpc);
- }
-
- Object stickyTarget = invocation.getTransientValue("TX_STICKY_TARGET");
-
- if (trace && stickyTarget != null)
- {
- log.trace("Remember transaction bound target[" + stickyTarget + "] for tpc " + tpc);
- }
-
- txFailoverAuthorizations.put(tpc, stickyTarget);
+ log.trace("After reaching the server, transaction propagation context (tpc) is " + tpc);
}
+
+ Object stickyTarget = invocation.getTransientValue("TX_STICKY_TARGET");
+
+ if (trace && stickyTarget != null)
+ {
+ log.trace("Remember transaction bound target[" + stickyTarget + "] for tpc " + tpc);
+ }
+
+ txFailoverAuthorizations.put(tpc, stickyTarget);
}
}
@@ -541,6 +543,10 @@
protected Object getTransactionPropagationContext()
{
TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
+ if (trace)
+ {
+ log.trace("Using tpc factory " + tpcFactory);
+ }
return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext();
}
@@ -557,32 +563,30 @@
{
if (tpc != null)
{
- synchronized (tpc)
+ if (trace)
{
- if (trace)
- {
- log.trace("In the proxy, transaction propagation context (tpc) is " + tpc);
- }
+ log.trace("In the proxy, transaction propagation context (tpc) is " + tpc);
+ log.trace("Contains key returns " + txFailoverAuthorizations.containsKey(tpc));
+ }
- Object stickyTarget = txFailoverAuthorizations.get(tpc);
-
- if (stickyTarget != null)
+ Object stickyTarget = txFailoverAuthorizations.get(tpc);
+
+ if (stickyTarget != null)
+ {
+ if (familyClusterInfo.getTargets().contains(stickyTarget))
{
- if (familyClusterInfo.getTargets().contains(stickyTarget))
+ if (trace)
{
- if (trace)
- {
- log.trace("Put transaction bound target into transient payload: " + stickyTarget);
- }
-
- invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
+ log.trace("Put transaction bound target into transient payload: " + stickyTarget);
}
- else
- {
- throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES,
- "Transaction sticky target is no longer available, so invocation needs to be halted");
- }
+
+ invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
}
+ else
+ {
+ throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES,
+ "Transaction sticky target is no longer available, so invocation needs to be halted");
+ }
}
}
}
More information about the jboss-cvs-commits
mailing list