FileDocCategorySizeDatePackage
AbstractPool.javaAPI DocJBoss 4.2.16869Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3

AbstractPool

public abstract class AbstractPool extends Object implements Pool
Comment
author
Bill Burke
version
$Revision: 61280 $

Fields Summary
private static final Logger
log
protected Class
beanClass
protected Class
contextClass
protected org.jboss.injection.Injector[]
injectors
protected Container
container
protected int
createCount
protected int
removeCount
Constructors Summary
public AbstractPool()


    
   

   
Methods Summary
protected BeanContextcreate()

      Object bean;
      BeanContext ctx;
      try
      {
         bean = container.construct();
         ctx = (BeanContext) contextClass.newInstance();
         ctx.setContainer(container);
         ctx.setInstance(bean);
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      if (ctx instanceof StatefulBeanContext)
      {
         StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
         sfctx.setId(new GUID());
         // Tell context how to handle replication
         Advisor advisor = (Advisor) container;
         CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
         if (config != null)
         {
            boolean replIsPass = true;
            try
            {
               // TODO determine why this fails on 4.2 branch if no
               // CacheConfig annotation is present
               replIsPass = config.replicationIsPassivation();
            }
            catch (Exception e)
            {
               log.debug("create(): Cannot determine replicationIsPassivation setting; defaulting to true " + 
                         e.getLocalizedMessage());
            }
            sfctx.setReplicationIsPassivation(replIsPass);
         }
         // this is for propagated extended PC's
         ctx = sfctx = sfctx.pushContainedIn();
      }
      try
      {
         if (injectors != null)
         {
            for (int i = 0; i < injectors.length; i++)
            {
               injectors[i].inject(ctx);
            }
         }

         ctx.initialiseInterceptorInstances();

      }
      finally
      {
         if (ctx instanceof StatefulBeanContext)
         {
            // this is for propagated extended PC's
            StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
            sfctx.popContainedIn();
         }
      }

      //TODO This needs to be reimplemented as replacement for create() on home interface
      container.invokeInit(bean);

      container.invokePostConstruct(ctx);
      
      ++createCount;
      
      return ctx;
   
protected BeanContextcreate(java.lang.Class[] initTypes, java.lang.Object[] initValues)

      Object bean;
      BeanContext ctx;
      try
      {
         bean = container.construct();
         ctx = (BeanContext) contextClass.newInstance();
         ctx.setContainer(container);
         ctx.setInstance(bean);
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      if (ctx instanceof StatefulBeanContext)
      {         
         StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
         sfctx.setId(new GUID());
         // Tell context how to handle replication
         Advisor advisor = (Advisor) container;
         CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
         if (config != null)
         {
            sfctx.setReplicationIsPassivation(config.replicationIsPassivation());
         }
         // this is for propagated extended PC's
         ctx = sfctx = sfctx.pushContainedIn();
      }
      try
      {
         if (injectors != null)
         {
            for (int i = 0; i < injectors.length; i++)
            {
               injectors[i].inject(ctx);
            }
         }

         ctx.initialiseInterceptorInstances();

      }
      finally
      {
         if (ctx instanceof StatefulBeanContext)
         {
            // this is for propagated extended PC's
            StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
            sfctx.popContainedIn();
         }
      }
      //TODO This needs to be reimplemented as replacement for create() on home interface
      container.invokeInit(bean, initTypes, initValues);

      container.invokePostConstruct(ctx);
      
      ++createCount;
      
      return ctx;
   
public voiddiscard(BeanContext ctx)

      remove(ctx);
   
public intgetCreateCount()

      return createCount;
   
public intgetRemoveCount()

      return removeCount;
   
public voidinitialize(Container container, java.lang.Class contextClass, java.lang.Class beanClass, int maxSize, long timeout)

      this.beanClass = beanClass;
      this.contextClass = contextClass;
      this.container = container;
   
public voidremove(BeanContext ctx)

      try
      {
         container.invokePreDestroy(ctx);
      }
      finally
      {
         ctx.remove();
         ++removeCount;
      }
   
public voidsetInjectors(org.jboss.injection.Injector[] injectors)

      this.injectors = injectors;