com.sun.ejb.base.sfsb.util
Class SimpleKeyGenerator

java.lang.Object
  extended by 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
protected static class SimpleKeyGenerator.SimpleSessionKey
           
 
Field Summary
protected  int idCounter
           
protected  long prefix
           
protected  long suffix
           
 
Constructor Summary
SimpleKeyGenerator()
           
SimpleKeyGenerator(byte[] ipAddress, int port)
           
SimpleKeyGenerator(long uniquePrefix)
           
 
Method Summary
 SimpleKeyGenerator.SimpleSessionKey byteArrayToKey(byte[] array, int startIndex, int len)
          Return the sessionKey that represents the sessionKey.
 SimpleKeyGenerator.SimpleSessionKey createSessionKey()
          Create and return the sessionKey.
 byte[] keyToByteArray(SimpleKeyGenerator.SimpleSessionKey key)
          Called from the Container before publishing an IOR.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefix

protected long prefix

suffix

protected long suffix

idCounter

protected int idCounter
Constructor Detail

SimpleKeyGenerator

public SimpleKeyGenerator()

SimpleKeyGenerator

public SimpleKeyGenerator(byte[] ipAddress,
                          int port)

SimpleKeyGenerator

public SimpleKeyGenerator(long uniquePrefix)
Method Detail

createSessionKey

public SimpleKeyGenerator.SimpleSessionKey createSessionKey()
Create and return the sessionKey.

Specified by:
createSessionKey in interface SFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>
Returns:
the sessionKey object

keyToByteArray

public byte[] keyToByteArray(SimpleKeyGenerator.SimpleSessionKey key)
Called from the Container before publishing an IOR. The method must convert the sessionKey into a byte[]

Specified by:
keyToByteArray in interface SFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>
Specified by:
keyToByteArray in interface org.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>
Returns:
A byte[] representation of the key. The byte[] could be created using serialization.

byteArrayToKey

public SimpleKeyGenerator.SimpleSessionKey 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()

Specified by:
byteArrayToKey in interface SFSBUUIDUtil<SimpleKeyGenerator.SimpleSessionKey>
Specified by:
byteArrayToKey in interface org.glassfish.ha.store.util.KeyTransformer<SimpleKeyGenerator.SimpleSessionKey>
Returns:
the sessionKey object


Copyright © 2012 GlassFish Community. All Rights Reserved.