[jboss-svn-commits] JBL Code SVN: r32446 - in labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats: internal/arjuna/utils and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 6 09:08:09 EDT 2010
Author: jhalliday
Date: 2010-04-06 09:08:08 -0400 (Tue, 06 Apr 2010)
New Revision: 32446
Modified:
labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java
labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/utils/SocketProcessId.java
Log:
Backport host and process id lock contention fixes to CP branch. JBTM-635
Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java 2010-04-06 12:41:56 UTC (rev 32445)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/utils/Utility.java 2010-04-06 13:08:08 UTC (rev 32446)
@@ -168,8 +168,15 @@
* separated for general availability.
* @since JTS 2.1.
*/
+ public static int hostInetAddr() throws UnknownHostException {
+ if(myAddr == 0) {
+ calculateHostInetAddr();
+ }
- public static synchronized int hostInetAddr () throws UnknownHostException
+ return myAddr;
+ }
+
+ private static synchronized void calculateHostInetAddr () throws UnknownHostException
{
/*
* Calculate only once.
@@ -193,8 +200,6 @@
myAddr = (myAddr << 8) | l;
}
}
-
- return myAddr;
}
/**
@@ -303,15 +308,22 @@
* @return a Uid representing this process.
* @since JTS 2.1.
*/
-
- public static final synchronized Uid getProcessUid ()
+ public static Uid getProcessUid ()
{
- if (processUid == null)
- processUid = new Uid();
+ if (processUid == null) {
+ initProcessUid();
+ }
return processUid;
}
+ private static synchronized void initProcessUid() {
+ // not done from a static initializer because Uid ctor calls back into this class.
+ if(processUid == null) {
+ processUid = new Uid();
+ }
+ }
+
public static final boolean isWindows ()
{
String os = arjPropertyManager.propertyManager.getProperty("os.name");
@@ -332,38 +344,38 @@
* [com.arjuna.ats.arjuna.utils.Utility_1] -
* Utility.getDefaultProcess - failed with
*/
- public static final Process getDefaultProcess ()
+ private static synchronized void initDefaultProcess ()
{
- try
+ if(processHandle == null)
{
- Class c = Thread.currentThread().getContextClassLoader().loadClass(
- arjPropertyManager.getPropertyManager().getProperty(Environment.PROCESS_IMPLEMENTATION, defaultProcessId));
+ try {
+ Class c = Thread.currentThread().getContextClassLoader().loadClass(
+ arjPropertyManager.getPropertyManager().getProperty(Environment.PROCESS_IMPLEMENTATION, defaultProcessId));
- return (Process) c.newInstance();
+ processHandle = (Process) c.newInstance();
+ }
+ catch (Exception e)
+ {
+ tsLogger.arjLoggerI18N.warn("Utility_1", e);
+ }
}
- catch (Exception e)
- {
- tsLogger.arjLoggerI18N.warn("Utility_1", e);
-
- return null;
- }
}
private static final Process getProcess ()
{
if (processHandle == null)
{
- processHandle = getDefaultProcess();
+ initDefaultProcess();
}
return processHandle;
}
- private static int myAddr = 0;
+ private static volatile int myAddr = 0;
private static Uid processUid = null;
- private static Process processHandle = null;
+ private static volatile Process processHandle = null;
private static final String hexStart = "0x";
Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/utils/SocketProcessId.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/utils/SocketProcessId.java 2010-04-06 12:41:56 UTC (rev 32445)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/utils/SocketProcessId.java 2010-04-06 13:08:08 UTC (rev 32446)
@@ -53,58 +53,51 @@
public class SocketProcessId implements com.arjuna.ats.arjuna.utils.Process
{
-
/**
- * @return the process id. This had better be unique between processes
- * on the same machine. If not we're in trouble!
- *
- * @message com.arjuna.ats.internal.arjuna.utils.SocketProcessId_1 [com.arjuna.ats.internal.arjuna.utils.SocketProcessId_1]- Invalid port specified
* @message com.arjuna.ats.internal.arjuna.utils.SocketProcessId_2 [com.arjuna.ats.internal.arjuna.utils.SocketProcessId_2] - SocketProcessId.getpid could not get unique port.
- * @message com.arjuna.ats.internal.arjuna.utils.SocketProcessId_3 [com.arjuna.ats.internal.arjuna.utils.SocketProcessId_3]- Invalid value for SocketProcessIdMaxPorts specified {0}
*/
-
- public int getpid ()
+ public SocketProcessId()
{
- synchronized (SocketProcessId._lock)
- {
- if (_thePort == 0)
- {
- if (_theSocket == null)
- {
Integer port = Utility.lookupBoundedIntegerProperty(arjPropertyManager.propertyManager, Environment.SOCKET_PROCESS_ID_PORT, _defaultPort,
"com.arjuna.ats.internal.arjuna.utils.SocketProcessId_1",
0, Utility.MAX_PORT);
Integer maxPorts = Utility.lookupBoundedIntegerProperty(arjPropertyManager.propertyManager, Environment.SOCKET_PROCESS_ID_MAX_PORTS, 1,
"com.arjuna.ats.internal.arjuna.utils.SocketProcessId_3",
0, Utility.MAX_PORT);
- int maxPort;
- if (maxPorts <= 1)
- {
- maxPort = port;
- }
- else if (Utility.MAX_PORT - maxPorts < port)
- {
- maxPort = Utility.MAX_PORT;
- }
- else
- {
- maxPort = port + maxPorts;
- }
+ int maxPort;
+
+ if (maxPorts <= 1)
+ {
+ maxPort = port;
+ }
+ else if (Utility.MAX_PORT - maxPorts < port)
+ {
+ maxPort = Utility.MAX_PORT;
+ }
+ else
+ {
+ maxPort = port + maxPorts;
+ }
- do {
- _theSocket = createSocket(port);
- } while (_theSocket == null && ++port < maxPort);
+ do {
+ _theSocket = createSocket(port);
+ } while (_theSocket == null && ++port < maxPort);
- _thePort = ((_theSocket == null) ? -1 : _theSocket.getLocalPort());
- }
- }
- }
+ _thePort = ((_theSocket == null) ? -1 : _theSocket.getLocalPort());
- if (_thePort == -1)
- throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.internal.arjuna.utils.SocketProcessId_2"));
+ if (_thePort == -1) {
+ throw new FatalError(tsLogger.log_mesg.getString("com.arjuna.ats.internal.arjuna.utils.SocketProcessId_2"));
+ }
+ }
- return _thePort;
+ /**
+ * @return the process id. This had better be unique between processes
+ * on the same machine. If not we're in trouble!
+ */
+ public int getpid ()
+ {
+ return _thePort;
}
private static ServerSocket createSocket(int port)
@@ -119,22 +112,11 @@
}
}
- public static ServerSocket getSocket ()
- {
- synchronized (SocketProcessId._lock)
- {
- return _theSocket;
- }
- }
+ private final int _thePort;
+ private ServerSocket _theSocket;
- private static int _thePort = 0;
- private static ServerSocket _theSocket = null;
- private static final Object _lock = new Object();
-
/**
* Default port is any free port.
*/
-
private static final int _defaultPort = 0 ;
-
}
More information about the jboss-svn-commits
mailing list