Package org.jboss.ejb3.pool

Examples of org.jboss.ejb3.pool.Pool


   public Object invoke(Invocation invocation) throws Throwable
   {
      EJBContainerInvocation<StatelessContainer, StatelessBeanContext> ejb = (EJBContainerInvocation<StatelessContainer, StatelessBeanContext>) invocation;
      EJBContainer container = getEJBContainer(invocation);
      Pool pool = container.getPool();
      BeanContext<?> ctx = pool.get();
      assert ctx != null : "pool returned null instance";
      //ejb.setTargetObject(ctx.getInstance());
      ejb.setBeanContext(ctx);
      container.pushContext(ctx);

      boolean discard = false;

      try
      {
         return ejb.invokeNext();
      }
      catch (Exception ex)
      {
         discard = (ex instanceof EJBException) ||
                 ((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation));
         throw ex;
      }
      catch (final Throwable t)
      {
         discard = true;
         throw t;
      }
      finally
      {
         container.popContext();
         //ejb.setTargetObject(null);
         ejb.setBeanContext(null);
         if (discard) pool.discard(ctx);
         else pool.release(ctx);
      }
   }
View Full Code Here


         }
      });
     
      entree.await(5, SECONDS);
     
      Pool pool = container.getPool();
      assertEquals(1, pool.getCreateCount());
      assertEquals("the pool should have grown", 1, pool.getMaxSize());
      int inUse = pool.getMaxSize() - pool.getAvailableCount();
      assertEquals("the instance should be in use", 1, inUse);
     
      exit.await(5, SECONDS);
     
      future.get(5, SECONDS);
View Full Code Here

   }
  
   @Test
   public void testMaxSize()
   {
      Pool pool = container.getPool();
      int actual = pool.getMaxSize();
      assertEquals("a ThreadLocalPool starts empty and grows", 0, actual);
   }
View Full Code Here

         }
      });
     
      entree.await(5, SECONDS);
     
      Pool pool = container.getPool();
      assertEquals(2, pool.getCreateCount());
      assertEquals("the pool should have grown", 2, pool.getMaxSize());
      int inUse = pool.getMaxSize() - pool.getAvailableCount();
      assertEquals("two instances should be in use", 2, inUse);
     
      exit.await(5, SECONDS);
     
      future.get(5, SECONDS);
     
      assertEquals("the pool should have shrunk", 1, pool.getMaxSize());
      assertEquals("the pool should have 1 available instance", 1, pool.getAvailableCount());
     
      service.shutdown();
   }
View Full Code Here

      futures[0] = service.submit(task);
      futures[1] = service.submit(task);
     
      entree.await(5, SECONDS);
     
      Pool pool = container.getPool();
      assertEquals(2, pool.getCreateCount());
      assertEquals("the pool should have grown", 2, pool.getMaxSize());
      int inUse = pool.getMaxSize() - pool.getAvailableCount();
      assertEquals("the instance should be in use", 2, inUse);
     
      exit.await(5, SECONDS);
     
      futures[0].get(5, SECONDS);
View Full Code Here

   public Object invoke(Invocation invocation) throws Throwable
   {
      EJBContainerInvocation<StatelessContainer, StatelessBeanContext> ejb = (EJBContainerInvocation<StatelessContainer, StatelessBeanContext>) invocation;
      EJBContainer container = getEJBContainer(invocation);
      Pool pool = container.getPool();
      BeanContext<?> ctx = pool.get();
      assert ctx != null : "pool returned null instance";
      //ejb.setTargetObject(ctx.getInstance());
      ejb.setBeanContext(ctx);
      container.pushContext(ctx);

      boolean discard = false;

      try
      {
         return ejb.invokeNext();
      }
      catch (Exception ex)
      {
         discard = (ex instanceof EJBException) ||
                 ((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation));
         throw ex;
      }
      finally
      {
         container.popContext();
         //ejb.setTargetObject(null);
         ejb.setBeanContext(null);
         if (discard) pool.discard(ctx);
         else pool.release(ctx);
      }
   }
View Full Code Here

/*    */
/*    */   public Object invoke(Invocation invocation) throws Throwable
/*    */   {
/* 52 */     EJBContainerInvocation ejb = (EJBContainerInvocation)invocation;
/* 53 */     EJBContainer container = ejb.getAdvisor();
/* 54 */     Pool pool = container.getPool();
/* 55 */     BeanContext ctx = pool.get();
/* 56 */     ejb.setTargetObject(ctx.getInstance());
/* 57 */     ejb.setBeanContext(ctx);
/* 58 */     container.pushContext(ctx);
/*    */
/* 60 */     boolean discard = false;
/*    */     try
/*    */     {
/* 64 */       localObject1 = ejb.invokeNext();
/*    */     }
/*    */     catch (Exception ex)
/*    */     {
/*    */       Object localObject1;
/* 68 */       discard = ((ex instanceof EJBException)) || ((((ex instanceof RuntimeException)) || ((ex instanceof RemoteException))) && (!StatefulInstanceInterceptor.isApplicationException(ex.getClass(), container)));
/*    */
/* 70 */       throw ex;
/*    */     }
/*    */     finally
/*    */     {
/* 74 */       container.popContext();
/* 75 */       ejb.setTargetObject(null);
/* 76 */       ejb.setBeanContext(null);
/* 77 */       if (discard) pool.discard(ctx); else
/* 78 */         pool.release(ctx);
/*    */     }
/*    */   }
View Full Code Here

   }
  
   @Test
   public void test1()
   {
      Pool pool = new StrictMaxPool();
      int maxSize = 10;
      long timeout = 100;
      pool.initialize(container, maxSize, timeout);
     
      BeanContext<?> ctx = pool.get();
      pool.remove(ctx);
     
      assertEquals(0, pool.getCurrentSize());
   }
View Full Code Here

   }
  
   @Test
   public void test2()
   {
      Pool pool = new StrictMaxPool();
      int maxSize = 10;
      long timeout = 100;
      pool.initialize(container, maxSize, timeout);
     
      for(int i = 0; i < maxSize; i++)
         pool.get();
     
      assertEquals(maxSize, pool.getCurrentSize());
     
      try
      {
         pool.get();
         fail("should have thrown an EJBException");
      }
      catch(EJBException e)
      {
         // good
View Full Code Here

   }
  
   @Test
   public void test3()
   {
      Pool pool = new StrictMaxPool();
      int maxSize = 10;
      long timeout = 100;
      pool.initialize(container, maxSize, timeout);
     
      BeanContext<?> ctxs[] = new BeanContext[maxSize];
      for(int i = 0; i < maxSize; i++)
         ctxs[i] = pool.get();
     
      pool.remove(ctxs[0]);
     
      assertEquals(maxSize - 1, pool.getCurrentSize());
      assertEquals(1, pool.getAvailableCount());
     
      try
      {
         pool.get();
      }
      catch(EJBException e)
      {
         fail(e.getMessage());
      }
View Full Code Here

TOP

Related Classes of org.jboss.ejb3.pool.Pool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.