Package org.jboss.ejb3.stateful

Examples of org.jboss.ejb3.stateful.StatefulBeanContext


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


      return get(key, true);
   }

   public StatefulBeanContext get(Object key, boolean markInUse) throws EJBException
   {
      StatefulBeanContext entry = null;
      Fqn id = getFqn(key, false);
      Boolean active = localActivity.get();
      try
      {
         localActivity.set(Boolean.TRUE);
         // If need be, gravitate
         InvocationContext ictx = cache.getInvocationContext();
         ictx.setOptionOverrides(getGravitateOption());
         entry = (StatefulBeanContext) cache.get(id, "bean");
      }
      catch (CacheException e)
      {
         RuntimeException re = convertToRuntimeException(e);
         throw re;
      }
      finally
      {
         localActivity.set(active);
      }

      if (entry == null)
      {
         throw new NoSuchEJBException("Could not find stateful bean: " + key);
      }
      else if (markInUse && entry.isRemoved())
      {
         throw new NoSuchEJBException("Could not find stateful bean: " + key +
                                      " (bean was marked as removed)");
      }

      entry.postReplicate();

      if (markInUse)
      {
         entry.setInUse(true);

         // Mark the Fqn telling the eviction thread not to passivate it yet.
         // Note the Fqn we use is relative to the region!
         region.markNodeCurrentlyInUse(new Fqn(key.toString()), MarkInUseWaitTime);
         entry.lastUsed = System.currentTimeMillis();
View Full Code Here

         {
            log.trace("remove: cache id " +id.toString());
         }
         InvocationContext ictx = cache.getInvocationContext();
         ictx.setOptionOverrides(getGravitateOption());
         StatefulBeanContext ctx = (StatefulBeanContext) cache.get(id, "bean");

         if (ctx != null)
         {
            if (!ctx.isRemoved())
               pool.remove(ctx);

            if (ctx.getCanRemoveFromCache())
            {
               // Do a cluster-wide removal of the ctx
               cache.removeNode(id);
            }
            else
View Full Code Here

                  
                  Iterator it = cacheMap.entrySet().iterator();
                  while (it.hasNext())
                  {
                     Map.Entry entry = (Map.Entry) it.next();
                     StatefulBeanContext centry = (StatefulBeanContext) 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());
                  }              
               }
            }
            catch (Exception ex)
            {
View Full Code Here

                  Iterator it = cacheMap.entrySet().iterator();
                  long now = System.currentTimeMillis();
                  while (it.hasNext())
                  {
                     Map.Entry entry = (Map.Entry) it.next();
                     StatefulBeanContext centry = (StatefulBeanContext) entry.getValue();
                     if (now - centry.lastUsed >= sessionTimeout * 1000)
                     {
                        synchronized (centry)
                        {                    
                           if (centry.getCanPassivate())
                           {
                              if (!centry.getCanRemoveFromCache())
                              {
                                 passivate(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");
                     }
                  }
               }
            }
View Full Code Here

      return create(null, null);
   }

   public StatefulBeanContext create(Class[] initTypes, Object[] initValues)
   {
      StatefulBeanContext ctx = null;
      try
      {
         ctx = ejbContainer.create(initTypes, initValues);
         if (log.isTraceEnabled())
         {
            log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
         }
         putInCache(ctx);
         ctx.setInUse(true);
         ctx.lastUsed = System.currentTimeMillis();
         ++createCount;
         totalSize = -1;
         if (beans != null)
         {
            beans.put(ctx.getId(), new Long(ctx.lastUsed));
         }
      }
      catch (EJBException e)
      {
         throw e;
View Full Code Here

      return get(key, true);
   }

   public StatefulBeanContext get(Object key, boolean markInUse) throws EJBException
   {
      StatefulBeanContext entry = null;
      String keyString = key.toString();
      Fqn id = getFqn(keyString, key, false);
      Boolean active = localActivity.get();
      try
      {
         localActivity.set(Boolean.TRUE);
         // If need be, gravitate
         cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
         entry = (StatefulBeanContext) cache.get(id, "bean");
      }
      catch (CacheException e)
      {
         RuntimeException re = convertToRuntimeException(e);
         throw re;
      }
      finally
      {
         localActivity.set(active);
      }

      if (entry == null)
      {
         throw new NoSuchEJBException("Could not find stateful bean: " + key);
      }
      else if (markInUse && entry.isRemoved())
      {
         throw new NoSuchEJBException("Could not find stateful bean: " + key +
                                      " (bean was marked as removed)");
      }

      entry.postReplicate();

      if (markInUse)
      {
         entry.setInUse(true);

         // Mark the Fqn telling the eviction thread not to passivate it yet.
         // Note the Fqn we use is relative to the region!
         region.markNodeCurrentlyInUse(getFqn(keyString, key, true), MarkInUseWaitTime);
         entry.lastUsed = System.currentTimeMillis();
View Full Code Here

         if(log.isTraceEnabled())
         {
            log.trace("remove: cache id " +id.toString());
         }
         cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
         StatefulBeanContext ctx = (StatefulBeanContext) cache.get(id, "bean");
        
         if(ctx == null)
            throw new NoSuchEJBException("Could not find Stateful bean: " + key);
        
         if (!ctx.isRemoved())
         {
            ejbContainer.destroy(ctx);
         }
         else if (log.isTraceEnabled())
         {
            log.trace("remove: " +id.toString() + " already removed from pool");
         }

         if (ctx.getCanRemoveFromCache())
         {
            // Do a cluster-wide removal of the ctx
            cache.removeNode(id);
         }
         else
View Full Code Here

            // But we do want to record that the bean's now in memory
            --passivatedCount;
            return;
         }

         StatefulBeanContext bean = (StatefulBeanContext) nodeData.get("bean");

         if(bean == null)
         {
            throw new IllegalStateException("nodeLoaded(): null bean instance.");
         }

         --passivatedCount;
         totalSize = -1;
      
         if(log.isTraceEnabled())
         {
            log.trace("nodeLoaded(): send postActivate event to bean at fqn: " +fqn);
         }

         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         try
         {
            ClassLoader cl = classloader.get();
            if (cl != null)
            {
               Thread.currentThread().setContextClassLoader(cl);
            }

            bean.activateAfterReplication();
         }
         finally
         {
            Thread.currentThread().setContextClassLoader(oldCl);
         }
View Full Code Here

         if(!event.isPre()) return;
         Fqn fqn = event.getFqn();
         if(fqn.size() != FQN_SIZE) return;
         if(!fqn.isChildOrEquals(cacheNode)) return;

         StatefulBeanContext bean = null;
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         Boolean active = localActivity.get();
         try
         {
            localActivity.set(Boolean.TRUE);
            bean = (StatefulBeanContext) event.getData().get("bean");
            if (bean != null)
            {
               ClassLoader cl = classloader.get();
               if (cl != null)
               {
                  Thread.currentThread().setContextClassLoader(cl);
               }

               if (!bean.getCanPassivate())
               {
                  // Abort the eviction
                  throw new ContextInUseException("Cannot passivate bean " + fqn +
                        " -- it or one if its children is currently in use");
               }

               if(log.isTraceEnabled())
               {
                  log.trace("nodePassivated(): send prePassivate event to bean at fqn: " +fqn);
               }

               bean.passivateAfterReplication();
               ++passivatedCount;
               totalSize = -1;
            }
         }
         catch (NoSuchEJBException e)
         {
            // TODO is this still necessary? Don't think we
            // should have orphaned proxies any more
            if (bean instanceof ProxiedStatefulBeanContext)
            {
               // This is probably an orphaned proxy; double check and remove it
               try
               {
                  bean.getContainedIn();
                  // If that didn't fail, it's not an orphan
                  throw e;
               }
               catch (NoSuchEJBException n)
               {
View Full Code Here

TOP

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

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.