Package org.jboss.ejb3.stateful

Examples of org.jboss.ejb3.stateful.StatefulBeanContext$CustomSessionSynchronization


      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


      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

      }
      // don't directly use the cacheMap to get the
      // object from the key. Instead, use the get() method
      // which will even activate any sessions which have been
      // passivated (see https://jira.jboss.org/jira/browse/EJBTHREE-2030)
      StatefulBeanContext ctx = this.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

      public boolean removeEldestEntry(Map.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

                  
                  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)
                     {
                        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)
                  {
                     get(centry.getId(), false);
                     remove(centry.getId());
                  }
               }
              
               // Invoke post-removal callback
               this.postRemoval();
View Full Code Here

                  Iterator<Entry<Object, StatefulBeanContext>> it = cacheMap.entrySet().iterator();
                  long now = System.currentTimeMillis();
                  while (it.hasNext())
                  {
                     Entry<Object, StatefulBeanContext> entry = it.next();
                     StatefulBeanContext centry = entry.getValue();
                     if (now - centry.lastUsed >= sessionTimeout * 1000)
                     {
                        synchronized (centry)
                        {                    
                           if (centry.getCanPassivate())
                           {
                              if (!centry.getCanRemoveFromCache())
                              {
                                 passivationQueue.add(centry);
                              }
                              else if (trace)
                              {
                                 log.trace("Removing " + entry.getKey() + " from cache");
                              }
                           }
                           else
                           {
                              centry.markedForPassivation = true;                             
                              assert centry.isInUse() : centry + " is not in use, and thus will never be passivated";
                           }
                           // its ok to evict because it will be passivated
                           // or we determined above that we can remove it
                           it.remove();
                        }
                     }
                     else if (trace)
                     {
                        log.trace("Not passivating; id=" + centry.getId() +
                              " only inactive " + Math.max(0, now - centry.lastUsed) + " ms");
                     }
                  }                 
               }
              
               prePassivationCompleted();
              
               StatefulBeanContext ctx;
               while ((ctx = passivationQueue.poll()) != null)
               { 
                  passivate(ctx);
               }
              
View Full Code Here

    }

    @Test
    public void testSmallCacheCreates() throws Exception {
        // Fill the cache.
        final StatefulBeanContext bean1 = cache.create();
        cache.release(bean1);
        final Future<StatefulBeanContext> futureBean2 = service.submit(new Callable<StatefulBeanContext>() {
            @Override
            public StatefulBeanContext call() throws Exception {
                final StatefulBeanContext ctx = cache.create();
                cache.release(ctx);
                return ctx;
            }
        });
        // Force bean1 in the first cacheMap sync.
        final Future<StatefulBeanContext> futureBean1 = service.submit(new Callable<StatefulBeanContext>() {
            @Override
            public StatefulBeanContext call() throws Exception {
                return cache.get(bean1.getId());
            }
        });
        // Setup another create run to lock the cacheMap after bean1 proceeds.
        final Future<StatefulBeanContext> futureBean3 = service.submit(new Callable<StatefulBeanContext>() {
            @Override
            public StatefulBeanContext call() throws Exception {
                final StatefulBeanContext ctx = cache.create();
                cache.release(ctx);
                return ctx;
            }
        });
        // Go bean 2! This will make either bean1 or bean3 move forward as well.
View Full Code Here

      this.acquireSessionOwnership(id, false);
      boolean remove = false;
     
      try
      {
         StatefulBeanContext bean = this.invoker.invoke(this.cache, operation);
  
         if (bean == null)
         {
            throw new NoSuchEJBException("Could not find bean: " + id);
         }
        
         if (!bean.isRemoved())
         {
            this.container.destroy(bean);
         }
         else
         {
            this.trace("remove(%s): was already removed from pool", id);
         }
  
         if (bean.getCanRemoveFromCache())
         {
            operation = new Operation<StatefulBeanContext>()
            {
               @Override
               public StatefulBeanContext invoke(Cache<Object, StatefulBeanContext> cache)
View Full Code Here

   }

   @Override
   public StatefulBeanContext create(Class<?>[] initTypes, Object[] initValues)
   {
      StatefulBeanContext bean = this.create();
      this.trace("Caching context %s of type %s", bean.getId(), bean.getClass().getName());
     
      this.acquireSessionOwnership(bean.getId(), true);
     
      try
      {
         this.putInCache(bean);
        
View Full Code Here

    * with additional logic to ensure that the generated bean will cache locally.
    * @see {@link org.jboss.ejb3.stateful.StatefulContainer#create(Class[], Object[])}
    */
   private StatefulBeanContext create()
   {
      StatefulBeanContext bean = (StatefulBeanContext) this.container.createBeanContext();
     
      DistributionManager manager = this.cache.getAdvancedCache().getDistributionManager();
     
      if (manager != null)
      {
         // If using distribution mode, ensure that bean will cache locally
         while (!manager.isLocal(bean.getId()))
         {
            bean = new InfinispanStatefulBeanContext(this.container, bean.getInstance());
         }
      }

      // Tell context how to handle replication
      CacheConfig config = this.container.getAnnotation(CacheConfig.class);
      if (config != null)
      {
         bean.setReplicationIsPassivation(config.replicationIsPassivation());
      }

      // this is for propagated extended PC's
      bean = bean.pushContainedIn();

      this.container.pushContext(bean);
      try
      {
         this.container.injectBeanContext(bean);
      }
      finally
      {
         this.container.popContext();
         // this is for propagated extended PC's
         bean.popContainedIn();
      }

      this.container.invokePostConstruct(bean);

      return bean;
View Full Code Here

TOP

Related Classes of org.jboss.ejb3.stateful.StatefulBeanContext$CustomSessionSynchronization

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.