axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/test/components TestUUID.java
Date Wed, 02 Jul 2003 11:45:56 GMT
dims        2003/07/02 04:45:56

  Modified:    java/src/org/apache/axis/transport/mail MailSender.java
               java/src/org/apache/axis/ime/internal
                        MessageExchangeImpl.java
               java/src/org/apache/axis/components/uuid SimpleUUIDGen.java
                        UUIDGen.java UUIDGenFactory.java
               java/test/components TestUUID.java
  Log:
  - Cleanup UUIDGen, remove unnecessary code
  - Make it faster by not creating a new SecureRandom all the time
  - Make it pluggable just like compiler and socket factories
  
  Revision  Changes    Path
  1.3       +1 -1      xml-axis/java/src/org/apache/axis/transport/mail/MailSender.java
  
  Index: MailSender.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/mail/MailSender.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MailSender.java	22 Apr 2003 19:35:55 -0000	1.2
  +++ MailSender.java	2 Jul 2003 11:45:50 -0000	1.3
  @@ -88,7 +88,7 @@
   public class MailSender extends BasicHandler {
   
       protected static Log log = LogFactory.getLog(MailSender.class.getName());
  -    private UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(null);
  +    private UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
   
       Properties prop = new Properties();
       Session session = Session.getDefaultInstance(prop, null);
  
  
  
  1.18      +1 -1      xml-axis/java/src/org/apache/axis/ime/internal/MessageExchangeImpl.java
  
  Index: MessageExchangeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/ime/internal/MessageExchangeImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- MessageExchangeImpl.java	22 Apr 2003 19:35:10 -0000	1.17
  +++ MessageExchangeImpl.java	2 Jul 2003 11:45:56 -0000	1.18
  @@ -116,7 +116,7 @@
                           MessageExchangeConstants.MESSAGE_CORRELATOR_PROPERTY);
           if (correlator == null) {
               correlator = new SimpleMessageExchangeCorrelator(
  -                    UUIDGenFactory.getUUIDGen(null).nextUUID());
  +                    UUIDGenFactory.getUUIDGen().nextUUID());
               context.setProperty(
                       MessageExchangeConstants.MESSAGE_CORRELATOR_PROPERTY,
                       correlator);
  
  
  
  1.5       +23 -28    xml-axis/java/src/org/apache/axis/components/uuid/SimpleUUIDGen.java
  
  Index: SimpleUUIDGen.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/uuid/SimpleUUIDGen.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleUUIDGen.java	27 Jun 2003 06:53:05 -0000	1.4
  +++ SimpleUUIDGen.java	2 Jul 2003 11:45:56 -0000	1.5
  @@ -80,7 +80,29 @@
       private static final int clock_sequence = (new Random()).nextInt(16384);
       private static final byte ZERO = (byte) 48; // "0"
       private static final byte ONE  = (byte) 49; // "1"
  +    private static Random secureRandom = null;
   
  +    static {
  +        // problem: the node should be the IEEE 802 ethernet address, but can not
  +        // be retrieved in Java yet.
  +        // see bug ID 4173528
  +        // workaround (also suggested in bug ID 4173528)
  +        // If a system wants to generate UUIDs but has no IEE 802 compliant
  +        // network card or other source of IEEE 802 addresses, then this section
  +        // describes how to generate one.
  +        // The ideal solution is to obtain a 47 bit cryptographic quality random
  +        // number, and use it as the low 47 bits of the node ID, with the most
  +        // significant bit of the first octet of the node ID set to 1. This bit
  +        // is the unicast/multicast bit, which will never be set in IEEE 802
  +        // addresses obtained from network cards; hence, there can never be a
  +        // conflict between UUIDs generated by machines with and without network
  +        // cards.
  +        try {
  +            secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
  +        } catch (Exception e) {
  +            secureRandom = new Random();
  +        }
  +    }
   
       /**
        * utility method which returns a bitString with left zero padding
  @@ -89,7 +111,7 @@
        *
        * @return a left zero padded string of at least <tt>len</tt> chars
        * @param bitString a String to pad
  -     * @param the length under which bitString needs padding
  +     * @param len the length under which bitString needs padding
        */
       private static final String leftZeroPadString(String bitString, int len) {
           if (bitString.length() < len) {
  @@ -181,27 +203,6 @@
           String clockSeqLow = Long.toHexString((new BigInteger(new String(reverseArray(clock_seq_low)),
2)).longValue());
           clockSeqLow = leftZeroPadString(clockSeqLow, 2);
   
  -        // problem: the node should be the IEEE 802 ethernet address, but can not
  -        // be retrieved in Java yet.
  -        // see bug ID 4173528
  -        // workaround (also suggested in bug ID 4173528)
  -        // If a system wants to generate UUIDs but has no IEE 802 compliant
  -        // network card or other source of IEEE 802 addresses, then this section
  -        // describes how to generate one.
  -        // The ideal solution is to obtain a 47 bit cryptographic quality random
  -        // number, and use it as the low 47 bits of the node ID, with the most
  -        // significant bit of the first octet of the node ID set to 1. This bit
  -        // is the unicast/multicast bit, which will never be set in IEEE 802
  -        // addresses obtained from network cards; hence, there can never be a
  -        // conflict between UUIDs generated by machines with and without network
  -        // cards.
  -        Random secureRandom = null;
  -        try {
  -            secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
  -        } catch (Exception e) {
  -            secureRandom = new Random();
  -        }
  -
           long nodeValue = secureRandom.nextLong();
           nodeValue = Math.abs(nodeValue);
           while (nodeValue > 140737488355328L) {
  @@ -239,11 +240,5 @@
               result[i] = bits[result.length - 1 - i];
   
           return result;
  -    }
  -
  -    public void destroy() {
  -    }
  -
  -    public void init() {
       }
   }
  
  
  
  1.3       +0 -4      xml-axis/java/src/org/apache/axis/components/uuid/UUIDGen.java
  
  Index: UUIDGen.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/uuid/UUIDGen.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UUIDGen.java	22 Apr 2003 19:34:13 -0000	1.2
  +++ UUIDGen.java	2 Jul 2003 11:45:56 -0000	1.3
  @@ -75,9 +75,5 @@
    * @since   JDK1.2.2
    */
   public interface UUIDGen {
  -    public void init();
  -
  -    public void destroy();
  -
       public String nextUUID();
   }
  
  
  
  1.4       +12 -35    xml-axis/java/src/org/apache/axis/components/uuid/UUIDGenFactory.java
  
  Index: UUIDGenFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/uuid/UUIDGenFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UUIDGenFactory.java	22 Apr 2003 19:34:13 -0000	1.3
  +++ UUIDGenFactory.java	2 Jul 2003 11:45:56 -0000	1.4
  @@ -59,10 +59,12 @@
    *  (http://sourceforge.net/projects/juddi/)
    * 
    */
  -
   package org.apache.axis.components.uuid;
   
   import org.apache.axis.i18n.Messages;
  +import org.apache.axis.components.logger.LogFactory;
  +import org.apache.axis.AxisProperties;
  +import org.apache.commons.logging.Log;
   
   /**
    * A Universally Unique Identifier (UUID) is a 128 bit number generated
  @@ -76,44 +78,19 @@
    * @since   JDK1.2.2
    */
   public abstract class UUIDGenFactory {
  -    private static final String defaultUUIDGenClassName = "org.apache.axis.components.uuid.SimpleUUIDGen";
  -
  -    /**
  -     * getInstance
  -     *
  -     * Returns the singleton instance of UUIDGen
  -     */
  -    public static UUIDGen getUUIDGen(String uuidgenClassName) {
  -        UUIDGen uuidgen = null;
  -
  -        if ((uuidgenClassName == null) || (uuidgenClassName.length() == 0)) {
  -            // use the default UUIDGen implementation
  -            uuidgenClassName = defaultUUIDGenClassName;
  -        }
  +    protected static Log log = LogFactory.getLog(UUIDGenFactory.class.getName());
   
  -        Class uuidgenClass = null;
  -        try {
  -            // instruct the class loader to load the UUIDGen implementation
  -            uuidgenClass = java.lang.Class.forName(uuidgenClassName);
  -        } catch (ClassNotFoundException e) {
  -            throw new RuntimeException(Messages.getMessage("uuidGenFactoryCNFE00", uuidgenClassName));
  -        }
  -
  -        try {
  -            // try to instantiate the UUIDGen subclass
  -            uuidgen = (UUIDGen) uuidgenClass.newInstance();
  -        } catch (java.lang.Exception e) {
  -            throw new RuntimeException(Messages.getMessage("uuidGenFactoryException02",
uuidgenClass.getName(), e.getMessage()));
  -        }
  -
  -        return uuidgen;
  +    static {
  +        AxisProperties.setClassOverrideProperty(Compiler.class, "axis.UUIDGenerator");
  +        AxisProperties.setClassDefault(UUIDGen.class, "org.apache.axis.components.uuid.SimpleUUIDGen");
       }
   
       /**
  -     * Release any aquired external resources and stop any background threads.
  +     * Returns an instance of UUIDGen
        */
  -    public static void destroyUUIDGen(UUIDGen uuidgen) {
  -        if (uuidgen != null)
  -            uuidgen.destroy();
  +    public static UUIDGen getUUIDGen() {
  +        UUIDGen uuidgen = (UUIDGen) AxisProperties.newInstance(UUIDGen.class);
  +        log.debug("axis.UUIDGenerator:" + uuidgen.getClass().getName());
  +        return uuidgen;
       }
   }
  
  
  
  1.3       +1 -3      xml-axis/java/test/components/TestUUID.java
  
  Index: TestUUID.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/components/TestUUID.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestUUID.java	22 Apr 2003 19:36:33 -0000	1.2
  +++ TestUUID.java	2 Jul 2003 11:45:56 -0000	1.3
  @@ -83,7 +83,7 @@
           long endTime = 0;
           UUIDGen uuidgen = null;
   
  -        uuidgen = UUIDGenFactory.getUUIDGen(null);
  +        uuidgen = UUIDGenFactory.getUUIDGen();
           startTime = System.currentTimeMillis();
           for (int i = 1; i <= 10; ++i) {
               String u = uuidgen.nextUUID();
  @@ -91,7 +91,5 @@
           }
           endTime = System.currentTimeMillis();
           System.out.println("UUIDGen took " + (endTime - startTime) + " milliseconds");
  -
  -        UUIDGenFactory.destroyUUIDGen(uuidgen);
       }
   }
  
  
  

Mime
View raw message