SimpleKeyGeneratorpublic class SimpleKeyGenerator extends Object implements com.sun.ejb.spi.sfsb.SFSBUUIDUtilA utility class that generates stateful session keys using two longs
The session id generated by this class is guarenteed to be unique as
long as the system clock is never reset to a previous value
The hashCode of the SessionKey generated by SimpleKeyGenerator
also allows uniform distribution of keys when hashed in a HashMap |
Fields Summary |
---|
private int | idCounter | private long | time | private long | prefix |
Constructors Summary |
---|
public SimpleKeyGenerator()
//Inital isCounter value
this.idCounter = 0;
//Set the default time value
this.time = System.currentTimeMillis();
//Default value for prefix
this.prefix = 0;
|
Methods Summary |
---|
public java.lang.Object | byteArrayToKey(byte[] array, int startIndex, int len)Return the sessionKey that represents the sessionKey.
This has to be super efficient as the container calls this
method on every invocation. Two objects obtained from identical
byte[] must satisfy both o1.equals(o2) and
o1.hashCode() == o2.hashCode()
long myTime = Utility.bytesToLong(array, startIndex);
long myId = Utility.bytesToLong(array, startIndex+8);
return new SimpleSessionKey(myTime, myId);
| public java.lang.Object | createSessionKey()Create and return the sessionKey.
int id = 0;
synchronized (this) {
id = ++idCounter;
if (id < 0) {
//idCounter wrapped around!!
id = idCounter = 0;
time = System.currentTimeMillis();
}
}
return new SimpleSessionKey(time, prefix + id);
| public byte[] | keyToByteArray(java.lang.Object sessionKey)Called from the Container before publishing an IOR.
The method must convert the sessionKey into a byte[]
SimpleSessionKey key = (SimpleSessionKey) sessionKey;
byte[] array = new byte[16];
Utility.longToBytes(key.time, array, 0);
Utility.longToBytes(key.id, array, 8);
return array;
| public void | setPrefix(int val)
this.prefix = val;
|
|