User: oberg   
  Date: 00/05/19 00:11:53

  Modified:    src/main/org/jboss/ejb/plugins
                        NoPassivationEntityInstanceCache.java
                        StatefulSessionFilePersistenceManager.java
                        TxInterceptor.java
  Log:
  Prefixed deployment classes with Jaws and jBoss
  Added server-side JMX RMI Adaptor
  Added shorthand JMX commands for deploy and stop of server
  Added read-only functionality to JAWS
  
  Revision  Changes    Path
  1.2       +1 -3      
jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java
  
  Index: NoPassivationEntityInstanceCache.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NoPassivationEntityInstanceCache.java     2000/04/22 14:30:12     1.1
  +++ NoPassivationEntityInstanceCache.java     2000/05/19 07:11:53     1.2
  @@ -13,7 +13,6 @@
   import java.util.Stack;
   import java.util.Collections;
   
  -import javax.ejb.SessionBean;
   import javax.transaction.SystemException;
   
   import org.jboss.ejb.Container;
  @@ -31,7 +30,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class NoPassivationEntityInstanceCache
      implements InstanceCache
  @@ -70,7 +69,6 @@
      public void start()
         throws Exception
      {
  -      isReentrant = ((Entity)con.getMetaData()).getReentrant().equals("True");
      }
      
      public void stop()
  
  
  
  1.2       +41 -54    
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java
  
  Index: StatefulSessionFilePersistenceManager.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatefulSessionFilePersistenceManager.java        2000/04/22 14:30:12     1.1
  +++ StatefulSessionFilePersistenceManager.java        2000/05/19 07:11:53     1.2
  @@ -18,6 +18,7 @@
   import java.io.IOException;
   import java.lang.reflect.Method;
   import java.lang.reflect.Field;
  +import java.lang.reflect.Modifier;
   import java.lang.reflect.InvocationTargetException;
   import java.rmi.RemoteException;
   import java.rmi.NoSuchObjectException;
  @@ -53,7 +54,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class StatefulSessionFilePersistenceManager
      implements StatefulSessionPersistenceManager
  @@ -89,9 +90,19 @@
         ejbRemove = SessionBean.class.getMethod("ejbRemove", new Class[0]);
         
         String ejbName = con.getMetaData().getEjbName();
  -      dir = new 
File(getClass().getResource("/db/sessions/db.properties").getFile()).getParentFile();
  +      dir = new 
File(getClass().getResource("db.properties").getFile()).getParentFile();
         dir = new File(dir, ejbName);
  +             
  +             System.out.println("Storing sessions for "+ejbName+" in:"+dir);
         dir.mkdirs();
  +             
  +             // Clear dir of old files
  +             File[] sessions = dir.listFiles();
  +             for (int i = 0; i < sessions.length; i++)
  +             {
  +                     sessions[i].delete();
  +             }
  +             System.out.println(sessions.length + " old sessions removed");
      }
      
      public void start()
  @@ -118,11 +129,6 @@
            // Call ejbCreate
            createMethod.invoke(ctx.getInstance(), args);
            
  -/*         // Check exist
  -         if (getFile(id).exists())
  -            throw new DuplicateKeyException("Already exists:"+id);
  -*/
  -
            // Set id
            ctx.setId(nextId());
            
  @@ -147,9 +153,18 @@
      public void activateSession(StatefulSessionEnterpriseContext ctx)
         throws RemoteException
      {
  -      // Call bean
  -      try
  -      {
  +             try
  +             {
  +                     // Load state
  +                     ObjectInputStream in = new SessionObjectInputStream(ctx, new 
FileInputStream(new File(dir, ctx.getId()+".ser")));
  +                     
  +                     Field[] fields = ctx.getInstance().getClass().getFields();
  +                     
  +                     for (int i = 0; i < fields.length; i++)
  +                             if (!Modifier.isTransient(fields[i].getModifiers()))
  +                                     fields[i].set(ctx.getInstance(), 
in.readObject());
  +                     
  +           // Call bean
            ejbActivate.invoke(ctx.getInstance(), new Object[0]);
         } catch (Exception e)
         {
  @@ -160,14 +175,25 @@
      public void passivateSession(StatefulSessionEnterpriseContext ctx)
         throws RemoteException
      {
  -      // Call bean
         try
         {
  +           // Call bean
            ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
  -      } catch (Exception e)
  -      {
  -         throw new ServerException("Passivation failed", e);
  -      }
  +             
  +                // Store state
  +                ObjectOutputStream out = new SessionObjectOutputStream(new 
FileOutputStream(new File(dir, ctx.getId()+".ser")));
  +                     
  +                     Field[] fields = ctx.getInstance().getClass().getFields();
  +                     
  +                     for (int i = 0; i < fields.length; i++)
  +                             if (!Modifier.isTransient(fields[i].getModifiers()))
  +                                     
out.writeObject(fields[i].get(ctx.getInstance()));
  +                     
  +                     out.close();    
  +        } catch (Exception e)
  +        {
  +           throw new ServerException("Passivation failed", e);
  +        }
      }
         
      public void removeSession(StatefulSessionEnterpriseContext ctx)
  @@ -196,43 +222,4 @@
      // Private -------------------------------------------------------
      
      // Inner classes -------------------------------------------------
  -   static class CMPObjectOutputStream
  -      extends ObjectOutputStream
  -   {
  -      public CMPObjectOutputStream(OutputStream out)
  -         throws IOException
  -      {
  -         super(out);
  -         enableReplaceObject(true);
  -      }
  -      
  -      protected Object replaceObject(Object obj)
  -         throws IOException
  -      {
  -         if (obj instanceof EJBObject)
  -            return ((EJBObject)obj).getHandle();
  -            
  -         return obj;
  -      }
  -   }
  -   
  -   static class CMPObjectInputStream
  -      extends ObjectInputStream
  -   {
  -      public CMPObjectInputStream(InputStream in)
  -         throws IOException
  -      {
  -         super(in);
  -         enableResolveObject(true);
  -      }
  -      
  -      protected Object resolveObject(Object obj)
  -         throws IOException
  -      {
  -         if (obj instanceof Handle)
  -            return ((Handle)obj).getEJBObject();
  -            
  -         return obj;
  -      }
  -   }
   }
  
  
  
  1.4       +77 -2     jboss/src/main/org/jboss/ejb/plugins/TxInterceptor.java
  
  Index: TxInterceptor.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TxInterceptor.java        2000/05/12 11:44:05     1.3
  +++ TxInterceptor.java        2000/05/19 07:11:53     1.4
  @@ -16,6 +16,7 @@
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   import javax.transaction.RollbackException;
  +import javax.transaction.TransactionRequiredException;
   import javax.transaction.SystemException;
   
   import javax.ejb.EJBException;
  @@ -28,7 +29,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.3 $
  + *   @version $Revision: 1.4 $
    */
   public class TxInterceptor
      extends AbstractInterceptor
  @@ -43,6 +44,7 @@
       
      // Attributes ----------------------------------------------------
      private TransactionManager tm;
  +     private HashMap methodTx = new HashMap();
      
      // Static --------------------------------------------------------
   
  @@ -51,6 +53,17 @@
      // Public --------------------------------------------------------
   
      // Interceptor implementation --------------------------------------
  +     public void init()
  +             throws Exception
  +     {
  +             // Store TM reference locally
  +             tm = getContainer().getTransactionManager();
  +     
  +             // Find out method->tx-type mappings from meta-info
  +//           EnterpriseBean eb = getContainer.getMetaData();
  +//           eb.getBeanContext()
  +     }
  +     
      public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
         throws Exception
      {
  @@ -76,7 +89,7 @@
         {
            case TX_NOT_SUPPORTED:
            {
  -//            System.out.println("TX_NOT_SUPPORTED");
  +            Logger.debug("TX_NOT_SUPPORTED");
               if (current.getStatus() != Status.STATUS_NO_TRANSACTION)
               {
                  // Suspend tx
  @@ -155,18 +168,80 @@
            
            case TX_SUPPORTS:
            {
  +              Logger.debug("TX_SUPPORTS");
  +              Transaction tx = current;
  +              
  +                             // This mode doesn't really do anything
  +                             // If tx started -> do nothing
  +                             // If tx not started -> do nothing
  +                             
  +              // Continue invocation
  +            return getNext().invoke(id, method, args, ctx);
            }
            
            case TX_REQUIRES_NEW:
            {
  +              Logger.debug("TX_REQUIRES_NEW");
  +              
  +            // Always begin new tx
  +            Logger.debug("Begin tx");
  +            getContainer().getTransactionManager().begin();
  +              
  +              // Continue invocation
  +              try
  +              {
  +                 return getNext().invoke(id, method, args, ctx);
  +              } catch (RemoteException e)
  +              {
  +                             getContainer().getTransactionManager().rollback();
  +                 throw e;
  +              } catch (RuntimeException e)
  +              {
  +                     getContainer().getTransactionManager().rollback();
  +                 throw new ServerException("Exception occurred", e);
  +              } catch (Error e)
  +              {
  +                     getContainer().getTransactionManager().rollback();
  +                 throw new ServerException("Exception occurred:"+e.getMessage());
  +              } finally
  +              {
  +                 if (tm.getStatus() == Status.STATUS_MARKED_ROLLBACK)
  +                 {
  +                    tm.rollback();
  +                 }
  +                 else
  +                 {
  +                             // Commit tx
  +                             // This will happen if
  +                             // a) everything goes well
  +                             // b) app. exception was thrown
  +                    tm.commit();
  +                 }
  +              }
            }
            
            case TX_MANDATORY:
            {
  +              Logger.debug("TX_MANDATORY");
  +              if (current.getStatus() == Status.STATUS_NO_TRANSACTION)
  +              {
  +                                     throw new TransactionRequiredException();
  +              } else
  +              {
  +                 return getNext().invoke(id, method, args, ctx);
  +              }
            }
            
            case TX_NEVER:
            {
  +              Logger.debug("TX_NEVER");
  +              if (current.getStatus() == Status.STATUS_ACTIVE)
  +              {
  +                     throw new RemoteException("Transaction not allowed");
  +              } else
  +              {
  +                 return getNext().invoke(id, method, args, ctx);
  +              }
            }
         }
         
  
  
  

Reply via email to