Methods Summary |
---|
public static synchronized java.lang.Long | generateSession()Generate and return a new session identifier.
return new Long(getRandom().nextLong());
|
public static synchronized java.lang.String | generateSessionId()Generate and return a new session identifier.
// Generate a byte array containing a session identifier
byte bytes[] = new byte[SESSION_ID_BYTES];
getRandom().nextBytes(bytes);
// Render the result as a String of hexadecimal digits
StringBuffer result = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
byte b2 = (byte) (bytes[i] & 0x0f);
if (b1 < 10) {
result.append((char) ('0" + b1));
} else {
result.append((char) ('A" + (b1 - 10)));
}
if (b2 < 10) {
result.append((char) ('0" + b2));
} else {
result.append((char) ('A" + (b2 - 10)));
}
}
return (result.toString());
|
private static synchronized java.util.Random | getRandom()Return the random number generator instance we should use for
generating session identifiers. If there is no such generator
currently defined, construct and seed a new one.
if (random == null) {
try {
Class clazz = Class.forName(randomClass);
random = (Random) clazz.newInstance();
} catch (Exception e) {
random = new java.util.Random();
}
}
return (random);
|