Source Code Cross Referenced for UUID.java in  » Web-Server » Jigsaw » org » w3c » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Jigsaw » org.w3c.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // UUID.java
002:        // $Id: UUID.java,v 1.2 2000/10/18 14:52:49 bmahe Exp $
003:        // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:        package org.w3c.util;
006:
007:        import java.net.InetAddress;
008:        import java.net.UnknownHostException;
009:
010:        import org.w3c.tools.crypt.Md5;
011:
012:        /**
013:         * A UUID (from java.rmi.server.UID)
014:         * @version $Revision: 1.2 $
015:         * @author  Benoît Mahé (bmahe@w3.org)
016:         */
017:        public final class UUID {
018:
019:            /**
020:             * @serial Integer that helps create a unique UID.
021:             */
022:            private int unique;
023:
024:            /**
025:             * @serial Long used to record the time.  The <code>time</code>
026:             * will be used to create a unique UID.
027:             */
028:            private long time;
029:
030:            /**
031:             * InetAddress to make the UID globally unique
032:             */
033:            private static String address;
034:
035:            /**
036:             * a random number
037:             */
038:            private static int hostUnique;
039:
040:            /**
041:             * Used for synchronization
042:             */
043:            private static Object mutex;
044:
045:            private static long lastTime;
046:            private static long DELAY;
047:
048:            private static String generateNoNetworkID() {
049:                Thread current = Thread.currentThread();
050:                String nid = current.activeCount()
051:                        + System.getProperty("os.version")
052:                        + System.getProperty("user.name")
053:                        + System.getProperty("java.version");
054:                System.out.println(nid);
055:                Md5 md5 = new Md5(nid);
056:                md5.processString();
057:                return md5.getStringDigest();
058:            }
059:
060:            static {
061:                hostUnique = (new Object()).hashCode();
062:                mutex = new Object();
063:                lastTime = System.currentTimeMillis();
064:                DELAY = 10; // in milliseconds
065:                try {
066:                    String s = InetAddress.getLocalHost().getHostAddress();
067:                    Md5 md5 = new Md5(s);
068:                    md5.processString();
069:                    address = md5.getStringDigest();
070:                } catch (UnknownHostException ex) {
071:                    address = generateNoNetworkID();
072:                }
073:            }
074:
075:            public UUID() {
076:                synchronized (mutex) {
077:                    boolean done = false;
078:                    while (!done) {
079:                        time = System.currentTimeMillis();
080:                        if (time < lastTime + DELAY) {
081:                            // pause for a second to wait for time to change
082:                            try {
083:                                Thread.currentThread().sleep(DELAY);
084:                            } catch (java.lang.InterruptedException e) {
085:                            } // ignore exception
086:                            continue;
087:                        } else {
088:                            lastTime = time;
089:                            done = true;
090:                        }
091:                    }
092:                    unique = hostUnique;
093:                }
094:            }
095:
096:            public String toString() {
097:                return Integer.toString(unique, 16) + "-"
098:                        + Long.toString(time, 16) + "-" + address;
099:            }
100:
101:            public boolean equals(Object obj) {
102:                if ((obj != null) && (obj instanceof  UUID)) {
103:                    UUID uuid = (UUID) obj;
104:                    return (unique == uuid.unique && time == uuid.time && address
105:                            .equals(uuid.address));
106:                } else {
107:                    return false;
108:                }
109:            }
110:
111:            public static void main(String args[]) {
112:                System.out.println(new UUID());
113:                System.out.println(new UUID());
114:                System.out.println(new UUID());
115:                System.out.println(new UUID());
116:            }
117:
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.