org.apache.openejb.core.mdb
Class MdbInstanceFactory

java.lang.Object
  extended by org.apache.openejb.core.mdb.MdbInstanceFactory

public class MdbInstanceFactory
extends Object

A MdbInstanceFactory creates instances of message driven beans for a single instance. This class differs from other instance managers in OpenEJB as it doesn't do pooling and it creates instances for only a single EJB deployment.

The MdbContainer assumes that the resouce adapter is pooling message endpoints so a second level of pooling in the container would be inefficient. This is true of all known resouce adapters in opensource (ActiveMQ), so if this is a poor assumption for your resource adapter, contact the OpenEJB developers.

This class can optionally limit the number of bean instances and therefore the message endpoints available to the resource adapter.


Constructor Summary
MdbInstanceFactory(CoreDeploymentInfo deploymentInfo, TransactionManager transactionManager, SecurityService securityService, int instanceLimit)
          Creates a MdbInstanceFactory for a single specific deployment.
 
Method Summary
 Object createInstance(boolean ignoreInstanceCount)
          Creates a new mdb instance preforming all necessary lifecycle callbacks
 void freeInstance(Instance instance, boolean ignoredInstanceCount)
          Frees an instance no longer needed by the resource adapter.
 int getInstanceCount()
          Gets the current number of created instances.
 int getInstanceLimit()
          Gets the maximal number of instances that can exist at any time.
 Object recreateInstance(Object bean)
          Recreates a bean instance that has thrown a system exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MdbInstanceFactory

public MdbInstanceFactory(CoreDeploymentInfo deploymentInfo,
                          TransactionManager transactionManager,
                          SecurityService securityService,
                          int instanceLimit)
Creates a MdbInstanceFactory for a single specific deployment.

Parameters:
deploymentInfo - the deployment for which instances will be created
transactionManager - the transaction manager for this container system
securityService - the transaction manager for this container system
instanceLimit - the maximal number of instances or <= 0 if unlimited
Method Detail

getInstanceLimit

public int getInstanceLimit()
Gets the maximal number of instances that can exist at any time.

Returns:
the maximum number of instances or <= 0 if unlimitied

getInstanceCount

public int getInstanceCount()
Gets the current number of created instances.

Returns:
the current number of instances created

createInstance

public Object createInstance(boolean ignoreInstanceCount)
                      throws javax.resource.spi.UnavailableException
Creates a new mdb instance preforming all necessary lifecycle callbacks

Parameters:
ignoreInstanceCount -
Returns:
a new message driven bean instance
Throws:
javax.resource.spi.UnavailableException - if the instance limit has been exceeded or if an exception occurs while creating the bean instance

freeInstance

public void freeInstance(Instance instance,
                         boolean ignoredInstanceCount)
Frees an instance no longer needed by the resource adapter. This method makes all the necessary lifecycle callbacks and decrements the instance count. This method should not be used to disposed of beans that have thrown a system exception. Instead the discardInstance method should be called.

Parameters:
instance - the bean instance to free
ignoredInstanceCount -

recreateInstance

public Object recreateInstance(Object bean)
                        throws javax.resource.spi.UnavailableException
Recreates a bean instance that has thrown a system exception. As required by the EJB specification, lifecycle callbacks are not invoked. To normally free a bean instance call the freeInstance method.

Parameters:
bean - the bean instance to discard
Returns:
the new replacement bean instance
Throws:
javax.resource.spi.UnavailableException


Copyright © 1999-2011 The Apache OpenEJB development community. All Rights Reserved.