1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.idgenerator;
18
19
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 /***
25 * Simple implementation of the IdGeneratorService.
26 *
27 * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
28 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
29 * @version $Id: JetspeedIdGenerator.java 516448 2007-03-09 16:25:47Z ate $
30 */
31 public class JetspeedIdGenerator implements IdGenerator
32 {
33 private final static Log log = LogFactory.getLog(JetspeedIdGenerator.class);
34
35
36 private final static long DEFAULT_CONFIG_COUNTER_START = 0x10000;
37 private final static String DEFAULT_CONFIG_PEID_PREFIX = "P-";
38 private final static String DEFAULT_CONFIG_PEID_SUFFIX = "";
39
40
41 private String peidPrefix = null;
42 private String peidSuffix = null;
43 protected long idCounter;
44
45 public JetspeedIdGenerator()
46 {
47 this.idCounter = DEFAULT_CONFIG_COUNTER_START;
48 this.peidPrefix = DEFAULT_CONFIG_PEID_PREFIX;
49 this.peidSuffix = DEFAULT_CONFIG_PEID_SUFFIX;
50 }
51
52 public JetspeedIdGenerator(long counterStart)
53 {
54 this.idCounter = counterStart;
55 this.peidPrefix = DEFAULT_CONFIG_PEID_PREFIX;
56 this.peidSuffix = DEFAULT_CONFIG_PEID_SUFFIX;
57 }
58
59 public JetspeedIdGenerator(long counterStart, String prefix, String suffix)
60 {
61 this.idCounter = counterStart;
62 this.peidPrefix = prefix;
63 this.peidSuffix = suffix;
64 }
65
66 public void start()
67 {
68 log.info( "Start JetspeedIdGenerator");
69 }
70
71 public void stop()
72 {
73 log.info( "Shutdown for JetspeedIdGenerator called. idCounter = "
74 + idCounter + " (" + Long.toHexString(idCounter) + ")" );
75 }
76
77 /***
78 * Generate a Unique PEID
79 * @return Unique PEID
80 */
81 public String getNextPeid()
82 {
83 long newid;
84
85 synchronized(JetspeedIdGenerator.class)
86 {
87 newid = idCounter++;
88 }
89
90 return peidPrefix + Long.toHexString(System.currentTimeMillis()) + "-"
91 + Long.toHexString(newid) + peidSuffix;
92 }
93
94 }