Package com.sun.ejb.base.sfsb.util
Class SimpleKeyGenerator
java.lang.Object
com.sun.ejb.base.sfsb.util.SimpleKeyGenerator
- All Implemented Interfaces:
SFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>,org.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>
- Direct Known Subclasses:
ScrambledKeyGenerator
public class SimpleKeyGenerator
extends Object
implements SFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>, org.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>
A 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
- Author:
- Mahesh Kannan
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimpleKeyGenerator(byte[] ipAddress, int port) SimpleKeyGenerator(long uniquePrefix) -
Method Summary
Modifier and TypeMethodDescriptionbyteArrayToKey(byte[] array, int startIndex, int len) Return the sessionKey that represents the sessionKey.Create and return the sessionKey.byte[]Called from the Container before publishing an IOR.
-
Field Details
-
prefix
protected long prefix -
suffix
protected long suffix -
idCounter
protected int idCounter
-
-
Constructor Details
-
SimpleKeyGenerator
public SimpleKeyGenerator() -
SimpleKeyGenerator
public SimpleKeyGenerator(byte[] ipAddress, int port) -
SimpleKeyGenerator
public SimpleKeyGenerator(long uniquePrefix)
-
-
Method Details
-
createSessionKey
Create and return the sessionKey.- Specified by:
createSessionKeyin interfaceSFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>- Returns:
- the sessionKey object
-
keyToByteArray
Called from the Container before publishing an IOR. The method must convert the sessionKey into a byte[]- Specified by:
keyToByteArrayin interfaceorg.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>- Specified by:
keyToByteArrayin interfaceSFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>- Returns:
- A byte[] representation of the key. The byte[] could be created using serialization.
-
byteArrayToKey
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()- Specified by:
byteArrayToKeyin interfaceorg.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>- Specified by:
byteArrayToKeyin interfaceSFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>- Returns:
- the sessionKey object
-