1 51 52 package org.objectweb.jass.as; 53 54 import java.net.InetAddress ; 55 import java.net.UnknownHostException ; 56 57 import org.apache.log4j.Logger; 58 59 65 public class ActivityIdGenerator implements java.io.Serializable { 66 67 private static Logger log = Logger.getLogger(ActivityIdGenerator.class); 68 private static ActivityIdGenerator singleton = null; 69 70 72 private String baseGlobalId; 73 private long globalIdNumber = 0; 74 private ActivityIdImpl lastId = null; 75 76 78 81 private ActivityIdGenerator() { 82 83 try { 84 baseGlobalId = InetAddress.getLocalHost().getHostName() + "/"; 85 } catch (UnknownHostException e) { 86 baseGlobalId = "localhost/"; 87 } 88 } 89 90 92 96 public static ActivityIdGenerator getSingleton() { 97 98 if (singleton == null) 99 singleton = new ActivityIdGenerator(); 100 101 return singleton; 102 } 103 104 108 public ActivityIdImpl newActivityId() { 109 110 String id = baseGlobalId + Long.toString(getNextId()); 111 byte[] globalId = id.getBytes(); 112 ActivityIdImpl aid = new ActivityIdImpl(globalId); 113 log.debug("New Activity Id Created: " + aid.print()); 114 lastId = aid; 115 116 return aid; 117 } 118 119 123 public ActivityIdImpl getLastId() { 124 return lastId; 125 } 126 127 129 131 135 private synchronized long getNextId() { 136 137 return globalIdNumber++; 138 } 139 140 } 141 | Popular Tags |