com.primix.vlib.ejb.impl
Class KeyAllocatorBean

java.lang.Object
  |
  +--com.primix.vlib.ejb.impl.KeyAllocatorBean
All Implemented Interfaces:
EnterpriseBean, java.io.Serializable, SessionBean

public class KeyAllocatorBean
extends java.lang.Object
implements SessionBean

Implementation of the KeyAllocator stateless session bean.

We're cheating a little; they KeyAllocator does have state, it just doesn't get persisted ever. Since the operation on it is atomic ("gimme a key") it doesn't need to have conversational state with its clients.

The KeyAllocator records in the database the "next key to allocate". When it needs a key, it allocates a block of keys (by advancing the next key by a some number).

If the KeyAllocator instance is purged from the pool, then some number of keys that it has allocated will be lost. Big deal.

Version:
$Id: KeyAllocatorBean.java,v 1.1 2001/06/14 15:21:23 hship Exp $
Author:
Howard Ship
See Also:
Serialized Form

Constructor Summary
KeyAllocatorBean()
           
 
Method Summary
protected  void allocateBlock(int count)
          Allocates a block of keys from the database.
 java.lang.Integer allocateKey()
          Allocates a single key, going to the database only if it has no keys in its internal cache.
 java.lang.Integer[] allocateKeys(int count)
          Allocates a block of keys, going to the database if there are insufficient keys in its internal cache.
 void ejbActivate()
          Does nothing, not invoked in stateless session beans.
 void ejbCreate()
          Activates the bean.
 void ejbPassivate()
          Does nothing, not invoked in stateless session beans.
 void ejbRemove()
          Does nothing.
protected  java.sql.Connection getConnection()
          Gets a database connection from the pool.
 void setSessionContext(SessionContext value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyAllocatorBean

public KeyAllocatorBean()
Method Detail

ejbCreate

public void ejbCreate()
Activates the bean. Gets the block size and DataSource from the environment.

ejbPassivate

public void ejbPassivate()
Does nothing, not invoked in stateless session beans.
Specified by:
ejbPassivate in interface SessionBean

setSessionContext

public void setSessionContext(SessionContext value)
Specified by:
setSessionContext in interface SessionBean

ejbActivate

public void ejbActivate()
Does nothing, not invoked in stateless session beans.
Specified by:
ejbActivate in interface SessionBean

ejbRemove

public void ejbRemove()
Does nothing. This is invoked when the bean moves from the method ready pool to the "does not exist" state. The EJB container will lost its reference to the bean, and the garbage collector will take it (including any keys it has cached from the database).
Specified by:
ejbRemove in interface SessionBean

allocateKey

public java.lang.Integer allocateKey()
Allocates a single key, going to the database only if it has no keys in its internal cache.

allocateKeys

public java.lang.Integer[] allocateKeys(int count)
Allocates a block of keys, going to the database if there are insufficient keys in its internal cache.

allocateBlock

protected void allocateBlock(int count)
Allocates a block of keys from the database. Allocates count keys, or the configured block size, whichever is greater.

It is assumed that this operation takes place within a transaction.


getConnection

protected java.sql.Connection getConnection()
Gets a database connection from the pool.
Throws:
EJBException - if a SQLException is thrown.