Package org.jboss.ejb3.cache.legacy

Examples of org.jboss.ejb3.cache.legacy.StatefulBeanContext


      }
      // 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.markForPassivation();
                 
                  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.markForPassivation();
                              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

      if (debug)
      {
         log.debug("Reading session state from: " + file);
      }

      StatefulBeanContext bean = null;
      try
      {
         FileInputStream fis = FISAction.open(file);
         // todo need to rewrite SessionObjectInputStream to support EJB3 classes
         ObjectInputStream in;

         in = new JBossObjectInputStream(new BufferedInputStream(fis));
         try
         {
            bean = (StatefulBeanContext) in.readObject();
         }
         finally
         {
            fis.close();
            in.close();
         }
      }
      catch (EJBException e)
      {
         throw e;
      }
      catch (Exception e)
      {
         throw new EJBException("Could not activate; failed to " +
                                "restore state", e);
      }

      removePassivated(id);

      bean.postActivate();
      return bean;
   }
View Full Code Here

            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

   {
      // Find the ultimate parent context for the tree of SFSBs the target
      // bean is part of.  This "tree" could just be the bean itself, or
      // a multi-layer tree of nested SFSBs.
      StatefulContainerInvocation ejbInv = (StatefulContainerInvocation) invocation;
      StatefulBeanContext ctx = (StatefulBeanContext) ejbInv.getBeanContext();
      StatefulBeanContext root = ctx.getUltimateContainedIn();
     
      // Find out if the ultimate parent is clustered
      boolean clustered = false;
      StatefulContainer container = (StatefulContainer) root.getContainer();
      ClusteredStatefulCache clusteredCache = null;
      if (container.getCache() instanceof ClusteredStatefulCache)
      {
         clustered = true;
         clusteredCache = (ClusteredStatefulCache) container.getCache();
      }
     
      // Track nested calls to this tree so we know when the outer call
      // returns -- that's when we replicate
      if (clustered)        
         pushCallStack(root);
     
      boolean stackUnwound = false;
      Object rtn = null;
      try
      {
         rtn = invocation.invokeNext();
      }
      finally
      {
         stackUnwound = (clustered && isCallStackUnwound(root));
      }


      // We only replicate if the ultimate parent is clustered
      // TODO should we fail somehow during bean creation otherwise??
      boolean mustReplicate = clustered;
     
      // If the bean implements Optimized, we call isModified() even
      // if we know we won't replicate, as the bean might be expecting
      // us to call the method
      Object obj = invocation.getTargetObject();
      if (obj instanceof Optimized)
      {
         if (((Optimized) obj).isModified() == false)
         {
            mustReplicate = false;
         }
      }
     
      if (mustReplicate)
      {
         // Mark the bean for replication. If the call stack is not
         // unwound yet this will tell the outer caller the tree is
         // dirty even if the outer bean's isModified() returns false
         root.setMarkedForReplication(true);
      }
     
      if (stackUnwound && root.isMarkedForReplication())
      {
         clusteredCache.replicate(root);
      }
     
      if (ctx != root && ctx.isMarkedForReplication())
View Full Code Here

      // must match JNDI name in jboss-client.xml or display-name in application-client.xml
      String name = new Date().toString();
      String applicationClientName = "ee5client_test";
      String args[] = { name };
     
      ClientLauncher launcher = new ClientLauncher();
      Properties env = getENCProps(applicationClientName);
      launcher.launch(mainClassName, applicationClientName, args, env);
     
      Class<?> clientClass = ClientLauncher.getTheMainClass();
      Class<?> empty[] = {};
      {
         Method getResult = clientClass.getDeclaredMethod("getResult", empty);
View Full Code Here

   {
      String mainClassName = SimpleResourceClient.class.getName();
      String applicationClientName = "ee5client-simpleresource-client"; // must match JNDI name in jboss-client.xml or display-name in application-client.xml
      String args[] = { };

      ClientLauncher launcher = new ClientLauncher();
      launcher.launch(mainClassName, applicationClientName, args);
   }
View Full Code Here

   {
      String mainClassName = SimpleResourceClient.class.getName();
      String applicationClientName = "ee5client-simpleresource-client"; // must match JNDI name in jboss-client.xml or display-name in application-client.xml
      String args[] = { };
     
      ClientLauncher launcher = new ClientLauncher();
      launcher.launch(mainClassName, applicationClientName, args);
   }
View Full Code Here

TOP

Related Classes of org.jboss.ejb3.cache.legacy.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.