1 36 package org.columba.ristretto.message; 37 38 import java.net.InetAddress ; 39 import java.net.UnknownHostException ; 40 41 47 public class MessageIDGenerator { 48 51 public MessageIDGenerator() { 52 } 53 54 61 public static String generate() { 62 String hostname = null; 63 64 try { 65 hostname = InetAddress.getLocalHost().getHostName(); 66 } catch (UnknownHostException e) { 67 hostname = ""; 68 } 69 70 long currentTime = System.currentTimeMillis(); 71 long randomNumber = Double.doubleToLongBits(Math.random()); 72 73 StringBuffer result = new StringBuffer (); 74 75 result.append("<"); 76 result.append(Long.toString(Math.abs(currentTime), 36)); 77 result.append("."); 78 result.append(Long.toString(Math.abs(randomNumber), 36)); 79 result.append("@"); 80 81 if (hostname.length() == 0) { 82 result.append(hostname); 83 } else { 84 result.append("a"); 85 randomNumber = (Double.doubleToLongBits(Math.random()) & 0xFFFFFFFFL); 86 result.append(Long.toString(Math.abs(randomNumber), 36)); 87 } 88 89 result.append(">"); 90 91 return result.toString(); 92 } 93 94 } | Popular Tags |