com.arjuna.ats.arjuna.utils
Class Utility

java.lang.Object
  extended by com.arjuna.ats.arjuna.utils.Utility

public class Utility
extends java.lang.Object

Various useful functions that we wrap in a single class. Some of these functions are needed simply for backwards compatibility with older versions of Java.

Since:
JTS 1.0.
Version:
$Id: Utility.java 2342 2006-03-30 13:06:17Z $
Author:
Mark Little (mark@arjuna.com)

Field Summary
static int BACKLOG
          The maximum queue length for incoming connection indications (a request to connect)
static int MAX_PORT
          Maximum value for a socket port
 
Constructor Summary
Utility()
           
 
Method Summary
static Process getDefaultProcess()
           
static int getpid()
           
static Uid getProcessUid()
           
static int hexStringToInt(java.lang.String s)
          Convert a hex String to an integer.
static long hexStringToLong(java.lang.String s)
          Convert a hex String to a long.
static int hostInetAddr()
           
static java.net.InetAddress hostNameToInetAddress(java.lang.String host, java.lang.String messageKey)
          Convert a host name into an InetAddress object
static java.lang.String intToHexString(int number)
          Convert integer to hex String.
static boolean isWindows()
           
static java.lang.String longToHexString(long number)
          Convert a long to a hex String.
static java.lang.Integer lookupBoundedIntegerProperty(com.arjuna.common.util.propertyservice.PropertyManager pm, java.lang.String intProperty, java.lang.Integer defValue, java.lang.String warnMsgKey, int minValue, int maxValue)
          Lookup and valid a port number.
static void setProcess(Process p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKLOG

public static final int BACKLOG
The maximum queue length for incoming connection indications (a request to connect)

See Also:
Constant Field Values

MAX_PORT

public static final int MAX_PORT
Maximum value for a socket port

See Also:
Constant Field Values
Constructor Detail

Utility

public Utility()
Method Detail

intToHexString

public static java.lang.String intToHexString(int number)
                                       throws java.lang.NumberFormatException
Convert integer to hex String.

Throws:
java.lang.NumberFormatException

hexStringToInt

public static int hexStringToInt(java.lang.String s)
                          throws java.lang.NumberFormatException
Convert a hex String to an integer. Be careful of -1. Java IO is really bad!

Throws:
java.lang.NumberFormatException

longToHexString

public static java.lang.String longToHexString(long number)
                                        throws java.lang.NumberFormatException
Convert a long to a hex String.

Throws:
java.lang.NumberFormatException

hexStringToLong

public static long hexStringToLong(java.lang.String s)
                            throws java.lang.NumberFormatException
Convert a hex String to a long.

Throws:
java.lang.NumberFormatException

hostInetAddr

public static int hostInetAddr()
                        throws java.net.UnknownHostException
Returns:
an integer representing the ip 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 separated for general availability.
Throws:
java.net.UnknownHostException
Since:
JTS 2.1.

hostNameToInetAddress

public static java.net.InetAddress hostNameToInetAddress(java.lang.String host,
                                                         java.lang.String messageKey)
                                                  throws java.net.UnknownHostException
Convert a host name into an InetAddress object

Parameters:
host - if empty or null then the loopback address is used
messageKey - message key to a report warning if host is unknown
Returns:
an InetAddress structure corresponding the desired host name
Throws:
java.net.UnknownHostException - if the hostname cannot be found

lookupBoundedIntegerProperty

public static java.lang.Integer lookupBoundedIntegerProperty(com.arjuna.common.util.propertyservice.PropertyManager pm,
                                                             java.lang.String intProperty,
                                                             java.lang.Integer defValue,
                                                             java.lang.String warnMsgKey,
                                                             int minValue,
                                                             int maxValue)
Lookup and valid a port number.

Parameters:
intProperty - property name of an integer valued property
defValue - a value to return if intProperty is invalid. If a null value is used and intProperty is invalid then
warnMsgKey - message key to report a warning if property values is invalid
minValue - minimum value for the integer propertry
maxValue - maximum value for the integer propertry
Returns:
the integer value of property or the default value if the property does not represent an integer
See Also:
is thrown

getpid

public static final int getpid()
Returns:
the process id. This had better be unique between processes on the same machine. If not we're in trouble!
Since:
JTS 2.1.

getProcessUid

public static final Uid getProcessUid()
Returns:
a Uid representing this process.
Since:
JTS 2.1.

isWindows

public static final boolean isWindows()

setProcess

public static final void setProcess(Process p)

getDefaultProcess

public static final Process getDefaultProcess()