[jboss-svn-commits] JBL Code SVN: r37505 - in labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore: arjuna/classes/com/arjuna/ats/arjuna/utils and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 4 13:10:09 EDT 2011


Author: mmusgrov
Date: 2011-10-04 13:10:08 -0400 (Tue, 04 Oct 2011)
New Revision: 37505

Modified:
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/tsmx/bin/com/arjuna/ats/tools/objectstorebrowser/stateviewers/viewers/UidInfo.java
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java
Log:
[JBTM-522] Backport ipv6 changes

Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2011-10-04 15:55:32 UTC (rev 37504)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2011-10-04 17:10:08 UTC (rev 37505)
@@ -36,6 +36,10 @@
 import com.arjuna.ats.arjuna.utils.Utility;
 
 import java.lang.Cloneable;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
 import java.io.Serializable;
 import java.io.PrintStream;
 
@@ -81,6 +85,14 @@
  *          [com.arjuna.ats.arjuna.common.Uid_9] - Invalid Uid object.
  * @message com.arjuna.ats.arjuna.common.Uid_10
  *          [com.arjuna.ats.arjuna.common.Uid_10] - Cannot unpack into nullUid!
+ * @message com.arjuna.ats.arjuna.common.Uid_11
+ *          [com.arjuna.ats.arjuna.common.Uid_11] - Cannot create Uid
+ * @message com.arjuna.ats.arjuna.common.Uid_12
+ *          [com.arjuna.ats.arjuna.common.Uid_12] - Exception thrown creating Uid from bytes
+ * @message com.arjuna.ats.arjuna.common.Uid_13
+ *          [com.arjuna.ats.arjuna.common.Uid_13] - Exception thrown getting bytes
+ * @message com.arjuna.ats.arjuna.common.Uid_14
+ *          [com.arjuna.ats.arjuna.common.Uid_14] - Error unpacking Uid
  */
 
 public class Uid implements Cloneable, Serializable
@@ -93,16 +105,19 @@
 
 	public Uid ()
 	{
-		hostAddr = -1;
+		hostAddr = null;
 		process = 0;
 		sec = 0;
 		other = 0;
 		_hashValue = -1;
-		_valid = true;
+		_valid = false;
+		_stringForm = null;
+		_byteForm = null;
 
 		try
 		{
 			hostAddr = Utility.hostInetAddr(); /* calculated only once */
+			_ipv6 = Utility.isIPv6();
 			process = Utility.getpid();
 
 			if (Uid.initTime == 0)
@@ -111,6 +126,10 @@
 			sec = Uid.initTime;
 
 			other = Uid.getValue();
+
+			_valid = true;
+
+			generateHash();
 		}
 		catch (UnknownHostException e)
 		{
@@ -129,6 +148,51 @@
 		copy(copyFrom);
 	}
 
+    public Uid (byte[] byteForm)
+    {
+		init(byteForm);
+    }
+
+    private void init(byte[] byteForm)
+    {
+        if (byteForm == null)
+            throw new IllegalArgumentException();
+
+        hostAddr = new long[2];
+        _hashValue = -1;
+        _stringForm = null;
+        _byteForm = null;
+
+        try
+        {
+            ByteArrayInputStream ba = new ByteArrayInputStream(byteForm);
+            DataInputStream ds = new DataInputStream(ba);
+
+			_ipv6 = Utility.isIPv6();
+
+			if (_ipv6) {
+            	hostAddr[0] = ds.readLong();
+            	hostAddr[1] = ds.readLong();
+			} else {
+            	hostAddr[0] = ds.readInt();
+			}
+
+            process = ds.readInt();
+            sec = ds.readInt();
+            other = ds.readInt();
+
+            _valid = true;
+        }
+        catch (final Throwable ex) {
+            _valid = false;
+
+			throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_12" +
+				ex.getMessage() ));
+        }
+
+        generateHash();
+    }
+
 	/**
 	 * Create Uid from string representation. If the string does not represent a
 	 * valid Uid then the instance will be set to nullUid.
@@ -146,14 +210,19 @@
 
 	public Uid (String uidString, boolean errsOk)
 	{
+        if (uidString == null)
+            throw new IllegalArgumentException();
+
 		char theBreakChar = Uid.getBreakChar(uidString);
 
-		hostAddr = -1;
+		hostAddr = new long[2];
 		process = 0;
 		sec = 0;
 		other = 0;
 		_hashValue = -1;
 		_valid = false;
+		_stringForm = null;
+		_byteForm = null;
 
 		if (uidString.length() > 0)
 		{
@@ -163,11 +232,13 @@
 
 			try
 			{
+				_ipv6 = Utility.isIPv6();
+
 				while (uidString.charAt(endIndex) != theBreakChar)
 					endIndex++;
 
 				s = uidString.substring(startIndex, endIndex);
-				hostAddr = (int) Utility.hexStringToLong(s);
+				hostAddr[0] = _ipv6 ? Utility.hexStringToLong(s) : Utility.hexStringToInt(s);
 
 				startIndex = endIndex + 1;
 				endIndex++;
@@ -176,7 +247,10 @@
 					endIndex++;
 
 				s = uidString.substring(startIndex, endIndex);
-				process = (int) Utility.hexStringToLong(s);
+				if (_ipv6)
+					hostAddr[1] = Utility.hexStringToLong(s);
+				else
+					process = (int) Utility.hexStringToLong(s);
 
 				startIndex = endIndex + 1;
 				endIndex++;
@@ -185,12 +259,26 @@
 					endIndex++;
 
 				s = uidString.substring(startIndex, endIndex);
+
+				if (_ipv6) {
+					process = (int) Utility.hexStringToLong(s);
+					startIndex = endIndex + 1;
+					endIndex++;
+
+					while (uidString.charAt(endIndex) != theBreakChar)
+						endIndex++;
+
+					s = uidString.substring(startIndex, endIndex);
+				}
+
 				sec = (int) Utility.hexStringToLong(s);
 
 				s = uidString.substring(endIndex + 1, uidString.length());
 				other = (int) Utility.hexStringToLong(s);
 
 				_valid = true;
+
+				generateHash();
 			}
 			catch (NumberFormatException e)
 			{
@@ -207,12 +295,37 @@
 			}
 			catch (StringIndexOutOfBoundsException e)
 			{
+				if (!errsOk)
+				{
+					if (tsLogger.arjLoggerI18N.isWarnEnabled())
+					{
+						tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.common.Uid_3", new Object[]
+						{ uidString });
+					}
+				}
+
 				_valid = false;
 			}
+            catch (final Throwable ex)
+			{
+				if (!errsOk)
+				{
+					if (tsLogger.arjLoggerI18N.isWarnEnabled())
+					{
+						tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.common.Uid_3", new Object[]
+						{ uidString });
+					}
+				}
+
+
+                _valid = false;
+            }
+
 		}
 		else
 		{
 			this.copy(Uid.nullUid());
+			_ipv6 = false;
 		}
 
 		if (!_valid)
@@ -222,6 +335,8 @@
 				try
 				{
 					this.copy(Uid.nullUid());
+
+					_valid = false;
 				}
 				catch (Exception e)
 				{
@@ -250,6 +365,32 @@
 		}
 	}
 
+    public Uid(long[] addr, int processId, int time, int incr)
+    {
+        try
+        {
+            hostAddr = new long[2];
+            hostAddr[0] = addr[0];
+            hostAddr[1] = addr[1];
+			_ipv6 = true;
+
+            process = processId;
+            sec = time;
+            other = incr;
+
+            _valid = true;
+
+            generateHash();
+        }
+        catch (Throwable ex)
+        {
+            _valid = false;
+
+			throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_11" +
+				ex.getMessage()));
+        }
+    }
+
 	/**
 	 * Override Object.hashCode. We always return a positive value.
 	 */
@@ -260,9 +401,6 @@
 
 	public int hashCode ()
 	{
-		if (_hashValue == -1)
-			generateHash();
-
 		return _hashValue;
 	}
 
@@ -273,12 +411,7 @@
 	public synchronized void pack (OutputBuffer packInto) throws IOException
 	{
 		if (_valid)
-		{
-			packInto.packInt(hostAddr);
-			packInto.packInt(process);
-			packInto.packInt(sec);
-			packInto.packInt(other);
-		}
+			packInto.packBytes(getBytes());
 		else
 			throw new IOException(
 					tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_9"));
@@ -294,23 +427,11 @@
 			throw new IOException(
 					tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_10"));
 
-		_valid = true; // should not be able to pack an invalid Uid.
-
-		try
-		{
-			hostAddr = unpackFrom.unpackInt();
-			process = unpackFrom.unpackInt();
-			sec = unpackFrom.unpackInt();
-			other = unpackFrom.unpackInt();
-
-			_hashValue = -1;
+		if (_valid) {
+			init(unpackFrom.unpackBytes());
+		} else {
+			throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_14"));
 		}
-		catch (IOException e)
-		{
-			_valid = false;
-
-			throw e;
-		}
 	}
 
 	/**
@@ -324,10 +445,20 @@
 
 	public String stringForm ()
 	{
-		return Utility.intToHexString(hostAddr) + Uid.breakChar
-				+ Utility.intToHexString(process) + Uid.breakChar
-				+ Utility.intToHexString(sec) + Uid.breakChar
-				+ Utility.intToHexString(other);
+		if (_stringForm == null)
+            if (_ipv6)
+                _stringForm = Utility.longToHexString(hostAddr[0]) + Uid.breakChar
+                    + Utility.longToHexString(hostAddr[1]) + Uid.breakChar
+                    + Utility.intToHexString(process) + Uid.breakChar
+                    + Utility.intToHexString(sec) + Uid.breakChar
+                    + Utility.intToHexString(other);
+            else
+                _stringForm = Utility.intToHexString((int) hostAddr[0]) + Uid.breakChar
+                    + Utility.intToHexString(process) + Uid.breakChar
+                    + Utility.intToHexString(sec) + Uid.breakChar
+                    + Utility.intToHexString(other);
+
+        return _stringForm;
 	}
 
 	/**
@@ -337,12 +468,61 @@
 
 	public String fileStringForm ()
 	{
-		return Utility.intToHexString(hostAddr) + Uid.fileBreakChar
-				+ Utility.intToHexString(process) + Uid.fileBreakChar
-				+ Utility.intToHexString(sec) + Uid.fileBreakChar
-				+ Utility.intToHexString(other);
+        if (_ipv6)
+            return Utility.longToHexString(hostAddr[0]) + Uid.fileBreakChar
+                + Utility.longToHexString(hostAddr[1]) + Uid.fileBreakChar
+                + Utility.intToHexString(process) + Uid.fileBreakChar
+                + Utility.intToHexString(sec) + Uid.fileBreakChar
+                + Utility.intToHexString(other);
+        else
+            return Utility.intToHexString((int) hostAddr[0]) + Uid.fileBreakChar
+                + Utility.intToHexString(process) + Uid.fileBreakChar
+                + Utility.intToHexString(sec) + Uid.fileBreakChar
+                + Utility.intToHexString(other);
 	}
 
+    /**
+	 * Get the byte representation of the Uid. Useful for packing and creating other
+	 * representations of transaction ids.
+	 * 
+	 * @return the byte array. Cached once created.
+	 */
+
+    public byte[] getBytes ()
+    {
+        /*
+		 * We should only really be doing this once, so overhead should
+		 * be negligible.
+		 */
+
+        if (_byteForm == null)
+        {
+            ByteArrayOutputStream ba = new ByteArrayOutputStream(UID_SIZE);
+            DataOutputStream ds = new DataOutputStream(ba);
+
+            try
+            {
+				if (Utility.isIPv6()) {
+                	ds.writeLong(hostAddr[0]);
+                	ds.writeLong(hostAddr[1]);
+				} else {
+					ds.writeInt((int) hostAddr[0]);
+				}
+
+                ds.writeInt(process);
+                ds.writeInt(sec);
+                ds.writeInt(other);
+                _byteForm = ba.toByteArray();
+            }
+            catch (final Throwable ex) {
+				throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.arjuna.common.Uid_13" +
+					ex.getMessage() ));
+            }
+        }
+
+        return _byteForm;
+    }
+
 	/**
 	 * Same as stringForm()
 	 */
@@ -352,6 +532,14 @@
 		return stringForm();
 	}
 
+    // return the process id value in hex form.
+    // The internal format is Uids mostly should not be exposed, but some
+    // recovery/expiry code need this.
+    public String getHexPid ()
+    {
+        return Utility.intToHexString(process);
+    }
+
 	/**
 	 * Create a copy of this instance.
 	 */
@@ -365,7 +553,7 @@
 	 * Copy the specified Uid over this instance.
 	 */
 
-	public synchronized void copy (Uid toCopy)
+	private void copy (Uid toCopy)
 	{
 		if (toCopy == this)
 			return;
@@ -402,7 +590,12 @@
 		if (u == this)
 			return true;
 
-		return ((other == u.other) && (sec == u.sec) && (process == u.process) && (hostAddr == u.hostAddr));
+        if (_ipv6)
+            return ((other == u.other) && (sec == u.sec) && (process == u.process)
+                && (hostAddr[0] == u.hostAddr[0]) && (hostAddr[1] == u.hostAddr[1]));
+		else
+            return ((other == u.other) && (sec == u.sec) && (process == u.process)
+                && ((int) hostAddr[0] == (int) u.hostAddr[0]));
 	}
 
 	public boolean notEquals (Uid u)
@@ -413,7 +606,12 @@
 		if (u == this)
 			return false;
 
-		return ((other != u.other) || (sec != u.sec) || (process != u.process) || (hostAddr != u.hostAddr));
+        if (_ipv6)
+		    return ((other != u.other) || (sec != u.sec) || (process != u.process)
+                || (hostAddr[0] != u.hostAddr[0]) || (hostAddr[1] != u.hostAddr[1]));
+        else
+		    return ((other != u.other) || (sec != u.sec) || (process != u.process)
+                || ((int) hostAddr[0] != (int) u.hostAddr[0]));
 	}
 
 	public boolean lessThan (Uid u)
@@ -433,23 +631,26 @@
 		if (LAST_RESOURCE_UID.equals(u))
 			return true ;
 		
-		if (hostAddr < u.hostAddr)
+		if ((hostAddr[0] < u.hostAddr[0])
+			&& (!_ipv6 || hostAddr[1] < u.hostAddr[1]))
 			return true;
 		else
-			if (hostAddr == u.hostAddr)
+		{
+			if ((hostAddr[0] == u.hostAddr[0])
+				&& (!_ipv6 || hostAddr[1] == u.hostAddr[1]))
 			{
 				if (process < u.process)
 					return true;
-				else
-					if (process == u.process)
-					{
-						if (sec < u.sec)
+				else if (process == u.process)
+				{
+					if (sec < u.sec)
+						return true;
+					else
+						if ((sec == u.sec) && (other < u.other))
 							return true;
-						else
-							if ((sec == u.sec) && (other < u.other))
-								return true;
-					}
+				}
 			}
+		}
 		return false;
 	}
 
@@ -470,23 +671,25 @@
 		if (LAST_RESOURCE_UID.equals(u))
 			return false ;
 
-		if (hostAddr > u.hostAddr)
+		if ((hostAddr[0] > u.hostAddr[0]) && (!_ipv6 || hostAddr[1] > u.hostAddr[1]))
 			return true;
 		else
-			if (hostAddr == u.hostAddr)
+		{
+			if ((hostAddr[0] == u.hostAddr[0])
+					&& (!_ipv6 || hostAddr[1] == u.hostAddr[1]))
 			{
 				if (process > u.process)
 					return true;
-				else
-					if (process == u.process)
-					{
-						if (sec > u.sec)
-							return true;
-						else
-							if ((sec == u.sec) && (other > u.other))
-								return true;
-					}
+				else if (process == u.process)
+				{
+					if (sec > u.sec)
+						return true;
+					else if ((sec == u.sec) && (other > u.other))
+						return true;
+				}
 			}
+		}
+
 		return false;
 	}
 
@@ -494,13 +697,13 @@
 	 * Is the Uid valid?
 	 */
 
-	public synchronized final boolean valid ()
+	public final boolean valid ()
 	{
 		return _valid;
 	}
 
 	/**
-	 * Return a null Uid (0:0:0:0)
+	 * Return a null Uid (0:0:0:0:0)
 	 */
 
 	public static final Uid nullUid ()
@@ -509,7 +712,7 @@
 	}
 
 	/**
-	 * Return a last resource Uid (0:0:0:1)
+	 * Return a last resource Uid (0:0:0:0:1)
 	 */
 	public static final Uid lastResourceUid ()
 	{
@@ -517,7 +720,7 @@
 	}
 
 	/**
-	 * Return the maximum Uid (7fffffff:7fffffff:7fffffff:7fffffff)
+	 * Return the maximum Uid (7fffffff:7fffffff:7fffffff:7fffffff:7fffffff)
 	 */
 	public static final Uid maxUid ()
 	{
@@ -525,7 +728,8 @@
 	}
 	
 	/**
-	 * Return the minimum Uid (-80000000:-80000000:-80000000:-80000000)
+	 * Return the minimum Uid
+	 * (-80000000:-80000000:-80000000:-80000000:-80000000)
 	 */
 	public static final Uid minUid ()
 	{
@@ -544,7 +748,13 @@
 	{
 		if (_valid)
 		{
-			out.writeInt(hostAddr);
+			if (_ipv6) {
+				out.writeLong(hostAddr[0]);
+				out.writeLong(hostAddr[1]);
+			} else {
+				out.writeInt((int) hostAddr[0]);
+			}
+
 			out.writeInt(process);
 			out.writeInt(sec);
 			out.writeInt(other);
@@ -563,16 +773,24 @@
 	private void readObject (java.io.ObjectInputStream in) throws IOException,
 			ClassNotFoundException
 	{
-		_valid = true; // should not be able to pack an invalid Uid.
-
 		try
 		{
-			hostAddr = in.readInt();
+			hostAddr = new long[2];
+
+			if (_ipv6) {
+				hostAddr[0] = in.readLong();
+				hostAddr[1] = in.readLong();
+			} else {
+				hostAddr[0] = in.readInt();
+			}
+
 			process = in.readInt();
 			sec = in.readInt();
 			other = in.readInt();
-			_hashValue = -1; // Set hashvalue to -1 to force a regeneration
-								// of the hashcode
+
+			_valid = true; // should not be able to pack an invalid Uid.
+
+			generateHash();
 		}
 		catch (IOException e)
 		{
@@ -582,18 +800,22 @@
 		}
 	}
 
-    private static final int MAX_SEQ_VALUE = 0x40000000; // 2^30, which is a bit conservative.
+    private static final int MAX_SEQ_VALUE = 0x40000000; // 2^30, which is a bit
+                                                         // conservative.
 
 	private static int getValue ()
 	{
         int value = 0;
-        do {
+        do
+		{
             value = uidsCreated.getAndIncrement();
-            if(value == MAX_SEQ_VALUE) {
+            if(value == MAX_SEQ_VALUE)
+            {
                 uidsCreated.set(0);
                 initTime = (int) (System.currentTimeMillis() / 1000);
             }
-        } while(value >= MAX_SEQ_VALUE);
+        }
+		while(value >= MAX_SEQ_VALUE);
 
         return value;
 	}
@@ -603,38 +825,16 @@
 	 * adverse effect.
 	 */
 
-	private final synchronized void generateHash ()
+	private final void generateHash ()
 	{
 		if (_valid)
 		{
-			if (true)
-				_hashValue = hostAddr ^ process ^ sec ^ other;
+			if (_ipv6)
+				_hashValue = (int) hostAddr[0] ^ (int) hostAddr[1] ^ process
+                    ^ sec ^ other;
 			else
-			{
-				int g = 0;
-				String p = toString();
-				int len = p.length();
-				int index = 0;
+				_hashValue = (int) hostAddr[0] ^ process ^ sec ^ other;
 
-				if (len > 0)
-				{
-					while (len-- > 0)
-					{
-						_hashValue = (_hashValue << 4)
-								+ (int) (p.charAt(index));
-						g = _hashValue & 0xf0000000;
-
-						if (g > 0)
-						{
-							_hashValue = _hashValue ^ (g >> 24);
-							_hashValue = _hashValue ^ g;
-						}
-
-						index++;
-					}
-				}
-			}
-
 			/*
 			 * Integers are signed in Java, so we have to be careful and only
 			 * return a signed value.
@@ -668,7 +868,9 @@
 
 	// use ints rather than longs for interoperability with C++ version
 
-	private volatile int hostAddr;
+	private volatile long[] hostAddr;	// representation of ipv6 address (and
+										// ipv4)
+	private volatile boolean _ipv6;
 
 	private volatile int process;
 
@@ -679,6 +881,10 @@
 	private volatile int _hashValue;
 
 	private volatile boolean _valid;
+
+	private volatile String _stringForm;
+
+	private volatile byte[] _byteForm;
 	
 	private static final AtomicInteger uidsCreated = new AtomicInteger();
 
@@ -688,11 +894,13 @@
 
 	private static final char fileBreakChar = '_';
 
-	private static final Uid NIL_UID = new Uid("0:0:0:0") ;
+	private static final Uid NIL_UID = new Uid("0:0:0:0:0") ;
 
-	private static final Uid LAST_RESOURCE_UID = new Uid("0:0:0:1") ;
+	private static final Uid LAST_RESOURCE_UID = new Uid("0:0:0:0:1") ;
 	
-	private static final Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff") ;
+	private static final Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff:7fffffff") ;
 	
-	private static final Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000") ;
+	private static final Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000:-80000000") ;
+
+	private static final int UID_SIZE = 2*8 + 3*4; // in bytes
 }

Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java	2011-10-04 15:55:32 UTC (rev 37504)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java	2011-10-04 17:10:08 UTC (rev 37505)
@@ -36,6 +36,7 @@
 import com.arjuna.ats.arjuna.common.*;
 import com.arjuna.common.util.propertyservice.PropertyManager;
 
+import java.net.Inet6Address;
 import java.net.InetAddress;
 
 import java.net.UnknownHostException;
@@ -119,7 +120,7 @@
     }
 
     /**
-     * Convert a hex String to a long.
+     * Convert a hex String to a long
      */
 
     public static long hexStringToLong (String s) throws NumberFormatException
@@ -162,46 +163,116 @@
     }
 
     /**
-     * @return an integer representing the ip address of the local machine.
+     * @return Long(s) representing the ip v6 address of the local machine.
      *         Essentially the bytes of the InetAddress are shuffled into the
-     *         integer. This was once part of the Uid class but has been
+     *         long(s). This was once part of the Uid class but has been
      *         separated for general availability.
      * @since JTS 2.1.
      */
-    public static int hostInetAddr() throws UnknownHostException {
-        if(myAddr == 0) {
+    public static long[] hostInetAddr() throws UnknownHostException {
+        if(myAddr == null) {
             calculateHostInetAddr();
         }
 
         return myAddr;
     }
 
+	/*
+     * @message com.arjuna.ats.arjuna.utils.Utility_2
+     *          [com.arjuna.ats.arjuna.utils.Utility_2] -
+     *          Utility.calculateHostInetAddr - failed with
+     */
     private static synchronized void calculateHostInetAddr () throws UnknownHostException
     {
         /*
          * Calculate only once.
          */
 
-        if (myAddr == 0)
+        if (myAddr == null)
         {
-            InetAddress addr = InetAddress.getLocalHost();
-            byte[] b = addr.getAddress();
+            myAddr = new long[2];
 
-            for (int i = 0; i < b.length; i++)
+            myAddr[0] = 0;
+            myAddr[1] = 0;
+
+            byte[] b = null;
+            InetAddress addr;
+
+            try
             {
+                addr = InetAddress.getLocalHost();
+            }
+            catch (final UnknownHostException uhe) {
+                tsLogger.arjLoggerI18N.warn("Utility_2", uhe);
+
+                addr = InetAddress.getByName(null);
+            }
+
+            if (addr instanceof Inet6Address)
+            {
+                // 16 bytes to work with.
+
+                b = addr.getAddress();
+				ipv6 = true;
+            }
+            else
+            {
                 /*
-                 * Convert signed byte into unsigned.
+                 * Convert ipv4 to ipv6
+                 * 
+                 * We only have 4 bytes here.
+                 * 
+                 * ::FFFF:129.144.52.38
                  */
+                byte[] v4Address = addr.getAddress();
 
+                if (v4Address.length > 4)
+                    throw new UnknownHostException();
+
+                b = new byte[16];
+
+                // high order byte in [0]
+                for (int i = 0; i < 10; i++)
+                    b[i] = 0;
+
+                b[10] = b[11] = (byte) 255;
+
+                System.arraycopy(v4Address, 0, b, 12, v4Address.length);
+            }
+
+            for (int i = 0; i < 8; i++)
+            {
+                /*
+            * Convert signed byte into unsigned.
+            */
                 int l = 0x7f & b[i];
 
                 l += (0x80 & b[i]);
 
-                myAddr = (myAddr << 8) | l;
+                myAddr[0] = (myAddr[0] << 8) | l;
             }
+
+            for (int i = 8; i < 16; i++)
+            {
+                /*
+                 * Convert signed byte into unsigned.
+                 */
+                int l = 0x7f & b[i];
+
+                l += (0x80 & b[i]);
+
+                myAddr[1] = (myAddr[1] << 8) | l;
+            }
         }
     }
 
+	public static boolean isIPv6() throws UnknownHostException
+	{
+		calculateHostInetAddr();
+
+		return ipv6;
+	}
+
     /**
      * Convert a host name into an InetAddress object
      * 
@@ -371,8 +442,10 @@
         return processHandle;
     }
 
-    private static volatile int myAddr = 0;
+    private static volatile long[] myAddr = null;
 
+    private static volatile boolean ipv6 = false;
+
     private static Uid processUid = null;
 
     private static volatile Process processHandle = null;

Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/tsmx/bin/com/arjuna/ats/tools/objectstorebrowser/stateviewers/viewers/UidInfo.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/tsmx/bin/com/arjuna/ats/tools/objectstorebrowser/stateviewers/viewers/UidInfo.java	2011-10-04 15:55:32 UTC (rev 37504)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/tsmx/bin/com/arjuna/ats/tools/objectstorebrowser/stateviewers/viewers/UidInfo.java	2011-10-04 17:10:08 UTC (rev 37505)
@@ -33,6 +33,7 @@
 
 /**
  * Base class for representing common state relevant to Uid's and Xid's
+ * TODO Does this still work with IPv6
  */
 public class UidInfo
 {

Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java	2011-10-04 15:55:32 UTC (rev 37504)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP_JBTM-522/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java	2011-10-04 17:10:08 UTC (rev 37505)
@@ -119,7 +119,7 @@
 		 */
 
 		applicPid = currentPid;
-		applicUid.copy(temp);
+		applicUid = new Uid();
 	    }
 
 	    ah.add(applicUid);



More information about the jboss-svn-commits mailing list