01: // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
02:
03: /*
04: * SequencingEngineUtil.java
05: *
06: * SUN PROPRIETARY/CONFIDENTIAL.
07: * This software is the proprietary information of Sun Microsystems, Inc.
08: * Use is subject to license terms.
09: *
10: */
11: package com.sun.jbi.engine.sequencing.util;
12:
13: /**
14: * Sequencing binding util class.
15: *
16: * @author Sun Microsystems, Inc.
17: */
18: public class SequencingEngineUtil {
19: /**
20: * Tracking id.
21: */
22: private static long sTrackingId = 0;
23:
24: /**
25: * padding length.
26: */
27: private static final int PAD_LENGTH = 20;
28:
29: /**
30: * Method to generate tracking id.
31: *
32: * @return tracking id.
33: */
34: public static synchronized String getTrackingId() {
35: sTrackingId++;
36:
37: if (sTrackingId >= Long.MAX_VALUE) {
38: sTrackingId = 0;
39: }
40:
41: return padString(Long.toString(sTrackingId));
42: }
43:
44: /**
45: * Util method for padding with zeros.
46: *
47: * @param s string to be padded.
48: *
49: * @return padded string.
50: */
51: private static String padString(String s) {
52: StringBuffer sb = new StringBuffer(s);
53: int len = sb.length();
54:
55: for (int i = 0; i < (PAD_LENGTH - len); i++) {
56: sb.insert(0, '0');
57: }
58:
59: return sb.toString();
60: }
61: }
|