Package org.jboss.ejb3.stateful

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


   @Override
   public StatefulBeanContext get(final Object id, boolean markInUse) throws EJBException
   {
      this.trace("get(%s, %s)", id, markInUse);
      StatefulBeanContext bean = this.getFromCache(id);
     
      if (bean == null)
      {
         throw new NoSuchEJBException(String.format("Could not find stateful bean: %s", id));
      }
      else if (markInUse && bean.isRemoved())
      {
         throw new NoSuchEJBException(String.format("Could not find stateful bean: %s (bean was marked as removed)", id));
      }
     
      bean.postReplicate();
     
      if (markInUse)
      {
         synchronized (bean)
         {
View Full Code Here


      if (event.isPre()) return;
      // Needed in case this cache is shared
      if ((event.getValue() == null) || !(event.getValue() instanceof StatefulBeanContext)) return;
     
      this.trace("activated(%s)", event.getKey());
      StatefulBeanContext bean = event.getValue();
     
      this.passivatedCount.decrementAndGet();
      this.resetTotalSize.set(true);
     
      if (localActivity.get() == Boolean.TRUE)
      {
         SwitchContext switchContext = switcher.getSwitchContext();
         ClassLoader classLoader = this.classLoaderRef.get();
        
         try
         {
            if (classLoader != null)
            {
               switchContext.setClassLoader(classLoader);
            }
  
            bean.activateAfterReplication();
         }
         finally
         {
            if (classLoader != null)
            {
View Full Code Here

      if ((event.getValue() == null) || !(event.getValue() instanceof StatefulBeanContext)) return;
     
      Object key = event.getKey();
      this.trace("passivated(%s)", key);
     
      StatefulBeanContext bean = event.getValue();
     
      SwitchContext switchContext = switcher.getSwitchContext();
      ClassLoader classLoader = this.classLoaderRef.get();
     
      Boolean active = localActivity.get();
      localActivity.set(Boolean.TRUE);
     
      try
      {
         if (!bean.getCanPassivate())
         {
            // Abort the eviction
            throw new RuntimeException(String.format("Cannot passivate bean %s -- it or one if its children is currently in use", key));
         }
        
         this.passivatedCount.incrementAndGet();
         this.resetTotalSize.set(true);
        
         if (classLoader != null)
         {
            switchContext.setClassLoader(classLoader);
         }
        
         bean.passivateAfterReplication();
      }
      finally
      {
         localActivity.set(active);
        
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

      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;
      Fqn id = getFqn(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(new Fqn(key.toString()), 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

      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 = (StatefulBeanContext) cacheMap.get(key);
      }
      if (entry == null)
      {
         entry = (StatefulBeanContext) pm.activateSession(key);
         if (entry == null)
         {
            throw new NoSuchEJBException("Could not find stateful bean: " + key);
         }
         --passivatedCount;
        
         // We cache the entry even if we will throw an exception below
         // as we may still need it for its children and XPC references
         if (log.isTraceEnabled())
         {
            log.trace("Caching activated context " + entry.getId() + " of type " + entry.getClass());
         }
        
         synchronized (cacheMap)
         {
            cacheMap.put(key, entry);
         }
      }
     
      // Now we know entry isn't null
      if (markInUse)
      {
         if (entry.isRemoved())
         {
            throw new NoSuchEJBException("Could not find stateful bean: " + key +
                                         " (bean was marked as removed");
         }     
     
         entry.setInUse(true);
         entry.lastUsed = System.currentTimeMillis();
      }
     
      return entry;
   }
View Full Code Here

TOP

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

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.