Examples of StatefulBeanContext


Examples of org.jboss.ejb3.stateful.StatefulBeanContext

            FileInputStream fis = FISAction.open(file);
  
            in = new JBossObjectInputStream(new BufferedInputStream(fis));
            try
            {
               StatefulBeanContext bean = (StatefulBeanContext) in.readObject();
               beans.add(bean);
            }
            finally
            {
               fis.close();
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

    */
   @Test
   public void testRemovalAfterPassivation() throws Exception
   {
      // create a session
      StatefulBeanContext sfsbContext = cache.create();
      Object sessionId = sfsbContext.getId();
      logger.info("Created StatefulBeanContext with session id " + sessionId);
      // mark it as *not in use* so that it can be passivated
      sfsbContext.setInUse(false);
      // wait for 3 (or more seconds for passivation to happen)
      // The SimpleSFSB is configured for a idleTimeout of 3 seconds (so that it will be
      // passivated after 3 seconds of inactivity)
      logger.info("Sleeping for 6 seconds to allow passivation thread to passivate the bean context with id "
            + sessionId);
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

      inject(ctx, ctx.getInstance());
   }

   public void inject(BeanContext beanContext, Object instance)
   {
      StatefulBeanContext ctx = (StatefulBeanContext)beanContext;
      EntityManager pc = ctx.getExtendedPersistenceContext(factory.getKernelName());
      if (pc == null)
      {
         pc = factory.createEntityManager();
         ctx.addExtendedPersistenceContext(factory.getKernelName(), pc);
      }
   }
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
   }
  
   protected EntityManager getEntityManager()
   {
      StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
    
      EntityManager em;
      if (beanContext != null)
      {
         List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

   public Object invoke(Invocation invocation) throws Throwable
   {
      log.debug("++++ LongLivedSessionPropagationInterceptor");
      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
      StatefulBeanContext ctx = (StatefulBeanContext) ejb.getBeanContext();

      Map<String, EntityManager> extendedPCs = ctx.getExtendedPersistenceContexts();
      if (extendedPCs == null || extendedPCs.size() == 0)
      {
         return invocation.invokeNext();
      }
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

      return create(null, null);
   }

   public StatefulBeanContext create(Class<?>[] initTypes, Object[] initValues)
   {
      StatefulBeanContext ctx = null;
      try
      {
         ctx = container.create(initTypes, initValues);
         if (log.isTraceEnabled())
         {
            log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
         }
         synchronized (cacheMap)
         {
            cacheMap.put(ctx.getId(), ctx);
            ctx.setInUse(true);
            ctx.lastUsed = System.currentTimeMillis();
         }
         ++createCount;
      }
      catch (EJBException e)
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

      return get(key, true);
   }
  
   public StatefulBeanContext get(Object key, boolean markInUse) throws EJBException
   {
      StatefulBeanContext entry = null;
      synchronized (cacheMap)
      {
         entry = cacheMap.get(key);
      }
      if(entry == null)
      {
         // TODO: optimize
         synchronized (cacheMap)
         {
            entry = cacheMap.get(key);
            if(entry == null)
            {
               Iterator<StatefulBeanContext> i = passivationQueue.iterator();
               while(i.hasNext())
               {
                  StatefulBeanContext ctx = i.next();
                  if(ctx.getId().equals(key))
                  {
                     boolean passivationCanceled = passivationQueue.remove(ctx);
                     if(passivationCanceled)
                     {
                        entry = ctx;
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

   {
      if(log.isTraceEnabled())
      {
         log.trace("Removing context " + key);
      }
      StatefulBeanContext ctx = null;
      synchronized (cacheMap)
      {
         ctx = cacheMap.get(key);
      }
      if(ctx == null)
         throw new NoSuchEJBException("Could not find Stateful bean: " + key);
      if (!ctx.isRemoved())
         container.destroy(ctx);
     
      ++removeCount;
     
      if (ctx.getCanRemoveFromCache())
      {
         synchronized (cacheMap)
         {
            cacheMap.remove(key);
         }
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

      public boolean removeEldestEntry(Entry<Object, StatefulBeanContext> entry)
      {
         boolean removeIt = size() > maxSize;
         if (removeIt)
         {
            StatefulBeanContext centry = (StatefulBeanContext) entry.getValue();
            synchronized (centry)
            {
               if (centry.getCanPassivate())
               {
                  passivate(centry);
                  // its ok to evict because bean will be passivated.
               }
               else
               {
                  centry.markedForPassivation = true;
                 
                  if (!centry.isInUse())
                  {
                     // Can't passivate but not in use means a child bean is
                     // in use.
                     // It's not ok to evict because bean will not be passivated
                     removeIt = false;
View Full Code Here

Examples of org.jboss.ejb3.stateful.StatefulBeanContext

                  
                  Iterator<Entry<Object, StatefulBeanContext>> it = cacheMap.entrySet().iterator();
                  while (it.hasNext())
                  {
                     Entry<Object, StatefulBeanContext> entry = it.next();
                     StatefulBeanContext centry = entry.getValue();
                     if (now - centry.lastUsed >= removalTimeout * 1000)
                     {
                        synchronized (centry)
                        {                                                                   
                           it.remove();
                        }
                     }
                  }                 
               }
              
               List<StatefulBeanContext> beans = pm.getPassivatedBeans()
               Iterator<StatefulBeanContext> it = beans.iterator();
               while (it.hasNext())
               {      
                  StatefulBeanContext centry = it.next();
                  if (now - centry.lastUsed >= removalTimeout * 1000)
                  {
                     get(centry.getId(), false);
                     remove(centry.getId());
                  }
               }
              
               // Invoke post-removal callback
               this.postRemoval();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.