[jboss-svn-commits] JBL Code SVN: r37688 - in labs/jbosstm/branches/JBOSSTS_4_15_0_Final: ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore and 10 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 28 13:14:58 EDT 2011
Author: tomjenkinson
Date: 2011-10-28 13:14:58 -0400 (Fri, 28 Oct 2011)
New Revision: 37688
Added:
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/jta/
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/jta/TestXAResourceRecordWrapperImpl.java
Modified:
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/objectstore/StoreManager.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecordWrappingPlugin.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/TransactionImple.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/build.xml
labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/XAResourceRecordWrappingPluginImpl.java
Log:
JBTM-933 updated to allow the EIS name to be stored in a persistent hashmap
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/objectstore/StoreManager.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/objectstore/StoreManager.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/objectstore/StoreManager.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -153,4 +153,8 @@
public static ObjectStoreAPI getTxOJStore() {
return (ObjectStoreAPI) setupStore(null, StateType.OS_UNSHARED);
}
+
+ public static ObjectStoreAPI getEISNameStore() {
+ return (ObjectStoreAPI) setupStore(null, StateType.OS_UNSHARED);
+ }
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecordWrappingPlugin.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecordWrappingPlugin.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecordWrappingPlugin.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -20,8 +20,12 @@
*/
package com.arjuna.ats.internal.jta.resources.arjunacore;
+import java.io.IOException;
+
import javax.transaction.xa.XAResource;
+import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
+
/**
* Callback interface to allow customisable population of XAResourceRecord metadata.
*
@@ -31,5 +35,7 @@
{
public void transcribeWrapperData(XAResourceRecord record);
- public String getEISName(XAResource xaResource);
+ public Integer getEISName(XAResource xaResource) throws IOException, ObjectStoreException;
+
+ public String getEISName(Integer eisName);
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -52,6 +52,7 @@
import com.arjuna.ats.arjuna.coordinator.*;
import com.arjuna.ats.arjuna.common.*;
+import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
import javax.transaction.xa.*;
@@ -60,6 +61,7 @@
import javax.transaction.RollbackException;
import javax.transaction.Status;
+import java.io.IOException;
import java.lang.IllegalStateException;
import java.util.concurrent.ConcurrentHashMap;
@@ -1484,15 +1486,15 @@
return null;
}
- protected Xid createXid(boolean branch, XAModifier theModifier, XAResource xaResource)
+ protected Xid createXid(boolean branch, XAModifier theModifier, XAResource xaResource) throws IOException, ObjectStoreException
{
- String eisName = null;
+ int eisName = 0;
if(branch) {
if(_xaResourceRecordWrappingPlugin != null) {
eisName = _xaResourceRecordWrappingPlugin.getEISName(xaResource);
}
}
- Xid xid = new XidImple(_theTransaction, branch, eisName);
+ Xid xid = new XidImple(_theTransaction.get_uid(), branch, eisName);
if (theModifier != null)
{
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/TransactionImple.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/TransactionImple.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/subordinate/TransactionImple.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -33,6 +33,7 @@
import com.arjuna.ats.arjuna.coordinator.ActionStatus;
import com.arjuna.ats.arjuna.coordinator.TwoPhaseOutcome;
+import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
import com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction;
import com.arjuna.ats.jta.exceptions.InvalidTerminationStateException;
@@ -42,6 +43,7 @@
import com.arjuna.ats.jta.xa.XATxConverter;
import com.arjuna.ats.jta.xa.XidImple;
+import java.io.IOException;
import java.lang.IllegalStateException;
import javax.transaction.*;
@@ -362,7 +364,7 @@
}
@Override
- protected Xid createXid(boolean branch, XAModifier theModifier, XAResource xaResource)
+ protected Xid createXid(boolean branch, XAModifier theModifier, XAResource xaResource) throws IOException, ObjectStoreException
{
Xid xid = baseXid();
@@ -370,7 +372,7 @@
if (xid.getFormatId() != XATxConverter.FORMAT_ID)
return xid;
- String eisName = null;
+ Integer eisName = null;
if(branch) {
if(_xaResourceRecordWrappingPlugin != null) {
eisName = _xaResourceRecordWrappingPlugin.getEISName(xaResource);
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XATxConverter.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -38,7 +38,9 @@
import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.arjuna.coordinator.TxControl;
+import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecordWrappingPlugin;
import com.arjuna.ats.internal.jta.xa.XID;
+import com.arjuna.ats.jta.common.jtaPropertyManager;
/**
* @author Mark Little (mark.little at arjuna.com)
@@ -48,9 +50,15 @@
public class XATxConverter
{
+ private static XAResourceRecordWrappingPlugin xaResourceRecordWrappingPlugin;
public static final int FORMAT_ID = 131077; // different from JTS ones.
- static XID getXid (Uid uid, boolean branch, String eisName) throws IllegalStateException
+
+ static {
+ xaResourceRecordWrappingPlugin = jtaPropertyManager.getJTAEnvironmentBean().getXAResourceRecordWrappingPlugin();
+ }
+
+ static XID getXid (Uid uid, boolean branch, Integer eisName) throws IllegalStateException
{
if (branch)
return getXid(uid, new Uid(), FORMAT_ID, eisName);
@@ -69,7 +77,7 @@
return new XidImple(xid);
}
- private static XID getXid(Uid uid, Uid branch, int formatId, String eisNameString) throws IllegalStateException
+ private static XID getXid(Uid uid, Uid branch, int formatId, Integer eisName) throws IllegalStateException
{
if (uid == null) {
throw new IllegalStateException();
@@ -105,25 +113,13 @@
}
int spareBqualBytes = XID.MAXBQUALSIZE - (bqualUid.length + 4);
- byte[] eisName;
- try {
- // caution: we may truncate the byte[] to fit, so double byte encodings are best avoided.
- eisName = (eisNameString == null ? new byte[0] : eisNameString.getBytes("US-ASCII"));
- } catch(UnsupportedEncodingException e) {
- eisName = new byte[0];
- }
- int eisNameLengthToUse = eisName.length;
- if( eisName.length > spareBqualBytes) {
- eisNameLengthToUse = spareBqualBytes;
- }
- xid.bqual_length = bqualUid.length+4+eisNameLengthToUse;
+
+ xid.bqual_length = bqualUid.length+4+4;
// src, srcPos, dest, destPos, length
int offset = xid.gtrid_length;
System.arraycopy (bqualUid, 0, xid.data, offset, bqualUid.length);
- offset = offset + bqualUid.length;
- offset = offset + 4; // Reserve space for subordinate node name
- System.arraycopy (eisName, 0, xid.data, offset, eisNameLengthToUse);
+ setEisName(xid, eisName);
}
else
{
@@ -169,7 +165,10 @@
}
public static void setSubordinateNodeName(XID theXid, Integer xaNodeName) {
- int offset = theXid.gtrid_length + Uid.UID_SIZE;
+ if (theXid == null || theXid.formatID != FORMAT_ID) {
+ return;
+ }
+ int offset = theXid.gtrid_length + Uid.UID_SIZE + 4;
theXid.data[offset + 0] = (byte) (xaNodeName >>> 24);
theXid.data[offset + 1] = (byte) (xaNodeName >>> 16);
theXid.data[offset + 2] = (byte) (xaNodeName >>> 8);
@@ -184,7 +183,7 @@
// the node name follows the Uid with no separator, so the only
// way to tell where it starts is to figure out how long the Uid is.
- int offset = xid.gtrid_length + Uid.UID_SIZE;
+ int offset = xid.gtrid_length + Uid.UID_SIZE + 4;
return (xid.data[offset + 0] << 24)
+ ((xid.data[offset + 1] & 0xFF) << 16)
@@ -218,54 +217,34 @@
}
- public static void setEisName(XID xid, String eisName) {
- if (xid == null || xid.formatID != FORMAT_ID) {
+ public static void setEisName(XID theXid, Integer eisName) {
+ if (theXid == null || theXid.formatID != FORMAT_ID) {
return;
}
-
- int remainingNameLength = Xid.MAXBQUALSIZE - (Uid.UID_SIZE + 4);
-
-
-
- byte[] toWrite = new byte[0];
if (eisName == null) {
- toWrite = Arrays.copyOf(toWrite, remainingNameLength);
- xid.bqual_length = Uid.UID_SIZE + 4;
- } else {
- if (eisName.length() > remainingNameLength) {
- eisName = "eis name too long";
- }
- toWrite = Arrays.copyOf(eisName.getBytes(), remainingNameLength);
- xid.bqual_length = Uid.UID_SIZE + 4 + eisName.length();
+ eisName = 0;
}
-
- int eisNamePosition = xid.gtrid_length + Uid.UID_SIZE + 4;
- System.arraycopy(toWrite, 0, xid.data, eisNamePosition, remainingNameLength);
+ int offset = theXid.gtrid_length + Uid.UID_SIZE;
+ theXid.data[offset + 0] = (byte) (eisName >>> 24);
+ theXid.data[offset + 1] = (byte) (eisName >>> 16);
+ theXid.data[offset + 2] = (byte) (eisName >>> 8);
+ theXid.data[offset + 3] = (byte) (eisName >>> 0);
}
- public static String getEISName(XID xid)
+ public static Integer getEISName(XID xid)
{
if(xid == null || xid.formatID != FORMAT_ID) {
- return "unknown eis name";
+ return -1;
}
- Uid uid = getUid(xid);
- int uidLength = uid.getBytes().length;
- int nameLength = xid.bqual_length-(uidLength+4);
+ // the node name follows the Uid with no separator, so the only
+ // way to tell where it starts is to figure out how long the Uid is.
+ int offset = xid.gtrid_length + Uid.UID_SIZE;
- if(nameLength == 0) {
- return "unknown eis name";
- }
-
- byte[] eisName = new byte[nameLength];
- System.arraycopy(xid.data, xid.gtrid_length+uidLength+4, eisName, 0, eisName.length);
-
- try {
- return new String(eisName, "US-ASCII");
- } catch(UnsupportedEncodingException e) {
- // should never happen, we use a required charset.
- return "<failed to get eisName>";
- }
+ return (xid.data[offset + 0] << 24)
+ + ((xid.data[offset + 1] & 0xFF) << 16)
+ + ((xid.data[offset + 2] & 0xFF) << 8)
+ + (xid.data[offset + 3] & 0xFF);
}
public static String getXIDString(XID xid)
@@ -288,7 +267,11 @@
stringBuilder.append(", subordinatenodename=");
stringBuilder.append(getSubordinateNodeName(xid));
stringBuilder.append(", eis_name=");
- stringBuilder.append(getEISName(xid));
+ if (xaResourceRecordWrappingPlugin != null) {
+ stringBuilder.append(xaResourceRecordWrappingPlugin.getEISName(getEISName(xid)));
+ } else {
+ stringBuilder.append(getEISName(xid));
+ }
stringBuilder.append(" >");
return stringBuilder.toString();
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/classes/com/arjuna/ats/jta/xa/XidImple.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -73,11 +73,7 @@
this(c.get_uid(), false, null);
}
- public XidImple(AtomicAction c, boolean branch, String eisName) {
- this(c.get_uid(), branch, eisName);
- }
-
- public XidImple(Xid xid, boolean branch, String eisName) {
+ public XidImple(Xid xid, boolean branch, Integer eisName) {
this(xid);
if (branch) {
XATxConverter.setBranchUID(_theXid, new Uid());
@@ -92,7 +88,7 @@
this(id, false, null);
}
- public XidImple(Uid id, boolean branch, String eisName) {
+ public XidImple(Uid id, boolean branch, Integer eisName) {
try {
_theXid = XATxConverter.getXid(id, branch, eisName);
} catch (Exception e) {
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/ArjunaJTA/jta/tests/classes/com/arjuna/ats/jta/xa/XATxConverterTest.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -1,6 +1,7 @@
package com.arjuna.ats.jta.xa;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import javax.transaction.xa.Xid;
@@ -9,7 +10,6 @@
import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.arjuna.common.arjPropertyManager;
-import com.arjuna.ats.arjuna.coordinator.TxControl;
public class XATxConverterTest {
@@ -17,7 +17,7 @@
public void testXAConverter() throws CoreEnvironmentBeanException {
Uid uid = new Uid();
boolean branch = true;
- String eisName = "foo";
+ Integer eisName = 1;
arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier("1");
XidImple rootXid = new XidImple(uid, branch, eisName);
@@ -27,7 +27,7 @@
assertEquals(XATxConverter.getSubordinateNodeName(rootXid.getXID()), new Integer(0));
}
-// TxControl.setXANodeName(2);
+ // TxControl.setXANodeName(2);
XATxConverter.setSubordinateNodeName(rootXid.getXID(), 1);
XidImple subordinateXid = new XidImple(rootXid);
{
@@ -42,7 +42,7 @@
XidImple foreignXidImple = new XidImple(new MyForeignXID());
assertEquals(XATxConverter.getNodeName(foreignXidImple.getXID()), null);
- assertEquals(XATxConverter.getEISName(foreignXidImple.getXID()), "unknown eis name");
+ assertTrue(XATxConverter.getEISName(foreignXidImple.getXID()) == -1);
assertEquals(XATxConverter.getSubordinateNodeName(foreignXidImple.getXID()), new Integer(-1));
}
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/build.xml
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/build.xml 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/build.xml 2011-10-28 17:14:58 UTC (rev 37688)
@@ -82,6 +82,7 @@
<tests>
<fileset dir="tests/classes">
<include name="**/SimpleIsolatedServers.java"/>
+ <include name="**/TestXAResourceRecordWrapperImpl.java"/>
</fileset>
</tests>
</run.tests.macro>
Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/XAResourceRecordWrappingPluginImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/XAResourceRecordWrappingPluginImpl.java 2011-10-28 17:01:48 UTC (rev 37687)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/XAResourceRecordWrappingPluginImpl.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -20,38 +20,139 @@
*/
package com.arjuna.ats.internal.jbossatx.jta;
-import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord;
-import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecordWrappingPlugin;
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.transaction.xa.XAResource;
+
import org.jboss.tm.XAResourceWrapper;
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.TxControl;
+import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
+import com.arjuna.ats.arjuna.objectstore.ObjectStoreAPI;
+import com.arjuna.ats.arjuna.objectstore.StoreManager;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.internal.arjuna.common.UidHelper;
+import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord;
+import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecordWrappingPlugin;
+
/**
- * A plugin implementation for copying resource metadata from the JBoss AS specific
- * XAResourceWrapper class to an XAResourceRecord.
- *
+ * A plugin implementation for copying resource metadata from the JBoss AS
+ * specific XAResourceWrapper class to an XAResourceRecord.
+ *
* @author Jonathan Halliday (jonathan.halliday at redhat.com) 2011-07
*/
-public class XAResourceRecordWrappingPluginImpl implements XAResourceRecordWrappingPlugin
-{
- public void transcribeWrapperData(XAResourceRecord record) {
+public class XAResourceRecordWrappingPluginImpl implements XAResourceRecordWrappingPlugin {
+ private ConcurrentMap<Integer, String> keyToName = new ConcurrentHashMap<Integer, String>();
+ private ConcurrentMap<String, Integer> nameToKey = new ConcurrentHashMap<String, Integer>();
+ private AtomicInteger nextKey = new AtomicInteger(1);
+ private ObjectStoreAPI eisNameStore;
+ private String nodeIdentifier;
- XAResource xaResource = (XAResource)record.value();
+ public void transcribeWrapperData(XAResourceRecord record) {
- if(xaResource instanceof XAResourceWrapper) {
- XAResourceWrapper xaResourceWrapper = (XAResourceWrapper)xaResource;
- record.setProductName(xaResourceWrapper.getProductName());
- record.setProductVersion(xaResourceWrapper.getProductVersion());
- record.setJndiName(xaResourceWrapper.getJndiName());
- }
- }
+ XAResource xaResource = (XAResource) record.value();
- public String getEISName(XAResource xaResource) {
+ if (xaResource instanceof XAResourceWrapper) {
+ XAResourceWrapper xaResourceWrapper = (XAResourceWrapper) xaResource;
+ record.setProductName(xaResourceWrapper.getProductName());
+ record.setProductVersion(xaResourceWrapper.getProductVersion());
+ record.setJndiName(xaResourceWrapper.getJndiName());
+ }
+ }
- if(xaResource instanceof XAResourceWrapper) {
- return ((XAResourceWrapper) xaResource).getJndiName();
- } else {
- return null;
- }
- }
+ public Integer getEISName(XAResource xaResource) throws IOException, ObjectStoreException {
+ if (xaResource instanceof XAResourceWrapper) {
+ initialize();
+ String jndiName = ((XAResourceWrapper) xaResource).getJndiName();
+ Integer key = nameToKey.get(jndiName);
+ if (key == null) {
+ synchronized (this) {
+ // Recheck the resource, we do this so that we don't need to
+ // synchronize if this is a read
+ key = nameToKey.get(jndiName);
+ if (key == null) {
+ key = nextKey.getAndIncrement();
+ keyToName.put(key, jndiName);
+ nameToKey.put(jndiName, key);
+
+ OutputObjectState oos = new OutputObjectState();
+ oos.packString(nodeIdentifier);
+ oos.packInt(key);
+ oos.packString(jndiName);
+ eisNameStore.write_committed(new Uid(), "EISNAME", oos);
+ eisNameStore.sync();
+ }
+ }
+ }
+ return key;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public String getEISName(Integer eisKey) {
+ try {
+ initialize();
+ } catch (IOException ioe) {
+ return "unloadable EIS key file: " + eisKey;
+ } catch (ObjectStoreException e) {
+ return "unloadable EIS key file: " + eisKey;
+ }
+ if (eisKey == 0) {
+ return "unknown eis name";
+ } else if (eisKey == -1) {
+ return "foreign XID";
+ } else {
+ String eisName = keyToName.get(eisKey);
+ if (eisName == null) {
+ return "forgot eis name for: " + eisKey;
+ } else {
+ return eisName;
+ }
+ }
+ }
+
+ private void initialize() throws ObjectStoreException, IOException {
+ if (this.nodeIdentifier == null) {
+ synchronized (this) {
+ // If we are here, check again that the node idenfier is still
+ // null in case of race condition
+ if (this.nodeIdentifier == null) {
+
+ this.nodeIdentifier = TxControl.getXANodeName();
+ this.eisNameStore = StoreManager.getEISNameStore();
+ InputObjectState states = new InputObjectState();
+ int keyMax = 0;
+ boolean allObjUids = eisNameStore.allObjUids("EISNAME", states);
+ while (states.notempty()) {
+ Uid uid = UidHelper.unpackFrom(states);
+ if (uid.equals(Uid.nullUid())) {
+ break;
+ } else {
+ InputObjectState oState = eisNameStore.read_committed(uid, "EISNAME");
+ String nodeName = oState.unpackString();
+ if (nodeName.equals(nodeIdentifier)) {
+ Integer key = oState.unpackInt();
+ String jndiName = oState.unpackString();
+ keyToName.put(key, jndiName);
+ nameToKey.put(jndiName, key);
+ if (key > keyMax) {
+ keyMax = key;
+ }
+ } else {
+ // logger warn that we are using a new node
+ }
+ }
+ }
+ nextKey.set(keyMax + 1);
+ }
+ }
+ }
+ }
}
Added: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/jta/TestXAResourceRecordWrapperImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/jta/TestXAResourceRecordWrapperImpl.java (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/internal/jbossatx/jta/TestXAResourceRecordWrapperImpl.java 2011-10-28 17:14:58 UTC (rev 37688)
@@ -0,0 +1,148 @@
+package com.arjuna.ats.internal.jbossatx.jta;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.IOException;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.tm.XAResourceWrapper;
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.coordinator.TxControl;
+import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
+
+public class TestXAResourceRecordWrapperImpl {
+
+ @Test
+ public void testReadAndWriteEISNameSameKey() throws IOException, ObjectStoreException {
+ String xaNodeName = TxControl.getXANodeName();
+ TxControl.setXANodeName("1");
+ XAResourceRecordWrappingPluginImpl xaResourceRecordWrappingPluginImpl = new XAResourceRecordWrappingPluginImpl();
+ MyWrapper myWrapper = new MyWrapper("Simple");
+ Integer eisNameKey = xaResourceRecordWrappingPluginImpl.getEISName(myWrapper);
+
+ MyWrapper otherMyWrapper = new MyWrapper("Simple");
+ Integer shouldBeSameEisNameKey = xaResourceRecordWrappingPluginImpl.getEISName(otherMyWrapper);
+
+ System.out.println(eisNameKey + " == " + shouldBeSameEisNameKey + "?");
+ assertEquals(eisNameKey, shouldBeSameEisNameKey);
+ assertEquals("Simple", xaResourceRecordWrappingPluginImpl.getEISName(eisNameKey));
+ assertEquals("Simple", xaResourceRecordWrappingPluginImpl.getEISName(shouldBeSameEisNameKey));
+ TxControl.setXANodeName(xaNodeName);
+ }
+
+ @Test
+ public void testReadAndWriteEISNameDifferentKey() throws IOException, ObjectStoreException {
+ String xaNodeName = TxControl.getXANodeName();
+ TxControl.setXANodeName("1");
+ XAResourceRecordWrappingPluginImpl xaResourceRecordWrappingPluginImpl = new XAResourceRecordWrappingPluginImpl();
+ MyWrapper myWrapper = new MyWrapper("Simple1");
+ Integer eisNameKey = xaResourceRecordWrappingPluginImpl.getEISName(myWrapper);
+
+ MyWrapper otherMyWrapper = new MyWrapper("Simple2");
+ Integer shouldBeSameEisNameKey = xaResourceRecordWrappingPluginImpl.getEISName(otherMyWrapper);
+
+ System.out.println(eisNameKey + " == " + shouldBeSameEisNameKey + "?");
+ assertFalse(eisNameKey.equals(shouldBeSameEisNameKey));
+ assertEquals("Simple1", xaResourceRecordWrappingPluginImpl.getEISName(eisNameKey));
+ assertEquals("Simple2", xaResourceRecordWrappingPluginImpl.getEISName(shouldBeSameEisNameKey));
+ TxControl.setXANodeName(xaNodeName);
+ }
+
+ private class MyWrapper implements XAResourceWrapper {
+
+ private String jndiName;
+
+ public MyWrapper(String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+ @Override
+ public String getJndiName() {
+ return jndiName;
+ }
+
+ @Override
+ public void commit(Xid arg0, boolean arg1) throws XAException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void end(Xid arg0, int arg1) throws XAException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void forget(Xid arg0) throws XAException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getTransactionTimeout() throws XAException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean isSameRM(XAResource arg0) throws XAException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int prepare(Xid arg0) throws XAException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public Xid[] recover(int arg0) throws XAException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void rollback(Xid arg0) throws XAException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean setTransactionTimeout(int arg0) throws XAException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void start(Xid arg0, int arg1) throws XAException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public XAResource getResource() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getProductName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getProductVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+}
More information about the jboss-svn-commits
mailing list