User: slaboure
  Date: 02/04/08 09:12:36

  Added:       src/main/org/jboss/ha/framework/test
                        ExplicitFailoverClientInterceptor.java
                        ExplicitFailoverServerInterceptor.java
  Log:
  New client and server side interceptors used to test clustering: ability to mimic 
that
  a node is dead by setting a property from the client test code.
  
  Revision  Changes    Path
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/test/ExplicitFailoverClientInterceptor.java
  
  Index: ExplicitFailoverClientInterceptor.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.ha.framework.test;
  
  import org.jboss.invocation.Invocation;
  
  /**
   * Used for testing clustering: allows to explicitely makes a call to node fail
   * This will mimic a dead server.
   *
   * @see org.jboss.ha.framework.test.ExplicitFailoverServerInterceptor
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>.
   * @version $Revision: 1.1 $
   *
   * <p><b>Revisions:</b>
   *
   * <p><b>8 avril 2002 Sacha Labourey:</b>
   * <ul>
   * <li> First implementation </li>
   * </ul>
   */
  
  public class ExplicitFailoverClientInterceptor extends org.jboss.proxy.Interceptor
  {
     
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     public ExplicitFailoverClientInterceptor ()
     {
     }
     
     // Public --------------------------------------------------------
     
     // Z implementation ----------------------------------------------
     
     // Interceptor overrides ---------------------------------------------------
     
     public Object invoke (Invocation mi) throws Throwable
     {
        Object failover = System.getProperty ("JBossCluster-DoFail");
        
        if (failover != null && 
            failover instanceof java.lang.String &&
            ((java.lang.String)failover).equalsIgnoreCase ("true"))
        {
           mi.setValue ("DO_FAIL_DURING_NEXT_CALL", Boolean.TRUE, Invocation.AS_IS);
           System.out.println("SYSTEM : We fail during next call!!!");
        }
        else
           mi.setValue ("DO_FAIL_DURING_NEXT_CALL", Boolean.FALSE, Invocation.AS_IS);
           
  
        return getNext().invoke(mi);
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/test/ExplicitFailoverServerInterceptor.java
  
  Index: ExplicitFailoverServerInterceptor.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.ha.framework.test;
  
  import org.jboss.invocation.Invocation;
  import org.jboss.ha.framework.interfaces.GenericClusteringException;
  
  /**
   * Used for testing clustering: allows to explicitely makes a call to node fail
   * This will mimic a dead server.
   *
   * @see org.jboss.ha.framework.test.ExplicitFailoverClientInterceptor
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>.
   * @version $Revision: 1.1 $
   *
   * <p><b>Revisions:</b>
   *
   * <p><b>8 avril 2002 Sacha Labourey:</b>
   * <ul>
   * <li> First implementation </li>
   * </ul>
   */
  
  public class ExplicitFailoverServerInterceptor extends 
org.jboss.ejb.plugins.AbstractInterceptor
  {
     
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     protected org.jboss.ejb.Container container;
  
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     public ExplicitFailoverServerInterceptor ()
     {
     }
     
     // Public --------------------------------------------------------
     
     public void setContainer(org.jboss.ejb.Container container)
     {
        this.container = container;
     }
        
     public org.jboss.ejb.Container getContainer()
     {
        return container;
     }
        
     // Z implementation ----------------------------------------------
     
     // AbstractInterceptor overrides 
---------------------------------------------------
     
     public Object invokeHome(Invocation mi)
        throws Exception
     {
        checkFailoverNeed (mi);
        
       return super.invokeHome (mi);
     }
     
     public Object invoke(Invocation mi)
        throws Exception
     {
        checkFailoverNeed (mi);
        
        return super.invoke (mi);
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     protected void checkFailoverNeed (Invocation mi) 
        throws GenericClusteringException 
     {
        Object data = mi.getValue ("DO_FAIL_DURING_NEXT_CALL");
        
        if (data != null &&
            data instanceof java.lang.Boolean &&
            ((java.lang.Boolean)data).equals (java.lang.Boolean.TRUE))
        {
           // we now determine if we have already failed
           //
           Object alreadyDone = mi.getValue ("FAILOVER_COUNTER");
           
           if (alreadyDone != null &&
               alreadyDone instanceof java.lang.Integer &&
               ((java.lang.Integer)alreadyDone).intValue () == 0)
           {
              // we do fail
              //
              this.log.debug ("WE FAILOVER IN SERVER INTERCEPTOR (explicit failover 
asked by client interceptor)!");
              throw new GenericClusteringException 
                 (GenericClusteringException.COMPLETED_NO, "Test failover from server 
interceptor");
           }
        }
     }
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to