[jboss-cvs] JBossAS SVN: r87733 - in branches/Branch_5_x: cluster/src/main/org/jboss/ha/singleton and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 23 12:47:40 EDT 2009


Author: pferraro
Date: 2009-04-23 12:47:40 -0400 (Thu, 23 Apr 2009)
New Revision: 87733

Modified:
   branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java
   branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java
   branches/Branch_5_x/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
   branches/Branch_5_x/testsuite/build.xml
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java
Log:
[JBAS-6792] reimplement fix to avoid regressions with remote jmx notifications

Modified: branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java
===================================================================
--- branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/AbstractHAServiceMBeanSupport.java	2009-04-23 16:47:40 UTC (rev 87733)
@@ -349,7 +349,7 @@
       // to ensure that it can be safely transferred over the wire
       notification.setSource(this.getServiceName());
       
-      this.handleEvent(notification);
+      this.service.handleEvent(notification);
    }
 
    protected void sendNotificationToLocalListeners(Notification notification)
@@ -370,7 +370,7 @@
     */
    public void handleEvent(Notification notification) throws Exception
    {
-      this.service.handleEvent(notification);
+      this.notifyListeners(notification);
    }
 
    /**

Modified: branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java
===================================================================
--- branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java	2009-04-23 16:47:40 UTC (rev 87733)
@@ -25,6 +25,7 @@
 
 import org.jboss.ha.framework.interfaces.HAService;
 import org.jboss.ha.framework.server.HAServiceImpl;
+import org.jboss.ha.framework.server.HAServiceRpcHandler;
 
 /**
  * Management Bean for an HA-Service.
@@ -47,6 +48,7 @@
  */
 public class HAServiceMBeanSupport
    extends AbstractHAServiceMBeanSupport<HAService<Notification>>
+   implements HAServiceRpcHandler<Notification>
 {
    /**
     * @see org.jboss.ha.jmx.AbstractHAServiceMBeanSupport#createHAService()
@@ -54,7 +56,18 @@
    @Override
    protected HAService<Notification> createHAService()
    {
-      return new HAServiceImpl<Notification>(this, this);
+      return new HAServiceImpl<Notification>(this, this)
+      {
+         /**
+          * Expose HAServiceMBeanSupport subclass methods to rpc handler
+          * @see org.jboss.ha.framework.server.HAServiceImpl#getRpcHandler()
+          */
+         @Override
+         protected HAServiceRpcHandler<Notification> getRpcHandler()
+         {
+            return HAServiceMBeanSupport.this;
+         }
+      };
    }
 }
 

Modified: branches/Branch_5_x/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/Branch_5_x/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2009-04-23 16:47:40 UTC (rev 87733)
@@ -26,7 +26,9 @@
 import org.jboss.ha.framework.interfaces.HASingleton;
 import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
 import org.jboss.ha.framework.interfaces.HASingletonLifecycle;
+import org.jboss.ha.framework.server.HAServiceRpcHandler;
 import org.jboss.ha.framework.server.HASingletonImpl;
+import org.jboss.ha.framework.server.HASingletonRpcHandler;
 import org.jboss.ha.jmx.AbstractHAServiceMBeanSupport;
 
 
@@ -42,7 +44,7 @@
  */
 public class HASingletonSupport
    extends AbstractHAServiceMBeanSupport<HASingleton<Notification>>
-   implements HASingleton<Notification>
+   implements HASingleton<Notification>, HASingletonRpcHandler<Notification>
 {
    /**
     * @see org.jboss.ha.framework.interfaces.HASingletonMBean#isMasterNode()
@@ -125,6 +127,42 @@
    @Override
    protected HASingleton<Notification> createHAService()
    {
-      return new HASingletonImpl<Notification>(this, this, this);
+      return new HASingletonService();
    }
+
+   /**
+    * @see org.jboss.ha.framework.server.HASingletonRpcHandler#stopOldMaster()
+    */
+   public void stopOldMaster() throws Exception
+   {
+      ((HASingletonService) this.getHAService()).stopIfMaster();
+   }
+   
+   private class HASingletonService extends HASingletonImpl<Notification>
+   {
+      HASingletonService()
+      {
+         super(HASingletonSupport.this, HASingletonSupport.this, HASingletonSupport.this);
+      }
+      
+      /**
+       * Expose HASingletonSupport subclass methods to rpc handler
+       * @see org.jboss.ha.framework.server.HASingletonImpl#getRpcHandler()
+       */
+      @Override
+      protected HAServiceRpcHandler<Notification> getRpcHandler()
+      {
+         return HASingletonSupport.this;
+      }
+      
+      /**
+       * Expose to parent class
+       * @see org.jboss.ha.framework.server.HASingletonImpl#stopIfMaster()
+       */
+      @Override
+      protected void stopIfMaster()
+      {
+         super.stopIfMaster();
+      }
+   }
 }

Modified: branches/Branch_5_x/testsuite/build.xml
===================================================================
--- branches/Branch_5_x/testsuite/build.xml	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/testsuite/build.xml	2009-04-23 16:47:40 UTC (rev 87733)
@@ -926,8 +926,8 @@
       <exclude name="org/jboss/test/ejb3/servlet/unit/ServletUnitTestCase.class"/>
 
    	  <!-- JBAS-6792 fix temporarily reverted -->
-      <exclude name="org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.class"/>
-      <exclude name="org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.class"/>
+      <!--exclude name="org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.class"/>
+      <exclude name="org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.class"/-->
    </patternset>
 
    <patternset id="aop-with-classloader.excludes">

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HAServiceUnitTestCase.java	2009-04-23 16:47:40 UTC (rev 87733)
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import javax.management.MBeanServerConnection;
+import javax.management.Notification;
 import javax.management.ObjectName;
 
 import junit.framework.Test;
@@ -47,21 +48,50 @@
       return JBossClusteredTestCase.getDeploySetup(HAServiceUnitTestCase.class, "ha-service.sar");
    }
 
-   public void testTrueEcho() throws Exception
+   public void testEcho() throws Exception
    {
+      Boolean result = this.testMethod("echo", new Object[] { false }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
+      assertFalse(result.booleanValue());
+      
+      result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
+      assertTrue(result.booleanValue());
+   }
+
+   public void testHandleEvent() throws Exception
+   {
+      Void result = this.testMethod("handleEvent", new Object[] { new Notification("test", "source", 1) }, new Class[] { Notification.class }, Void.class);
+      
+      assertNull(result);
+   }
+   
+   private <T> T testMethod(String method, Object[] parameters, Class<?>[] types, Class<T> resultType) throws Exception
+   {
       MBeanServerConnection[] adaptors = this.getAdaptors();
-      ObjectName on = new ObjectName("jboss.ha:service=EchoHAService");
-      Object[] args = new Object[] {"echo", new Object[] {true}, new Class[] {boolean.class}};
-      String[] signature = new String[] {String.class.getName(), Object[].class.getName(), Class[].class.getName()};
-      List<?> responses = (List<?>) adaptors[0].invoke(on, "callMethodOnPartition", args, signature);
-      log.debug("Response list: " + responses);
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHAService");
+      Object[] args = new Object[] { method, parameters, types };
+      String[] signature = new String[] { String.class.getName(), Object[].class.getName(), Class[].class.getName() };
+      List<?> responses = (List<?>) adaptors[0].invoke(name, "callMethodOnPartition", args, signature);
+      
+      this.log.debug("Response list: " + responses);
+      
       assertEquals(1, responses.size());
       
-      if (responses.get(0) instanceof Exception)
+      Object response = responses.get(0);
+      
+      if (response instanceof Exception)
       {
-         throw (Exception) responses.get(0);
+         throw (Exception) response;
       }
-      
-      assertTrue(((Boolean) responses.get(0)).booleanValue());
+
+      return resultType.cast(response);
    }
+   
+   public void testSendNotification() throws Exception
+   {
+      MBeanServerConnection[] adaptors = this.getAdaptors();
+      ObjectName name = new ObjectName("jboss.ha:service=EchoHAService");
+      adaptors[0].invoke(name, "sendNotification", new Object[] { new Notification("test", "source", 1) }, new String[] { Notification.class.getName() });
+   }
 }

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java	2009-04-23 16:11:01 UTC (rev 87732)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonUnitTestCase.java	2009-04-23 16:47:40 UTC (rev 87733)
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import javax.management.MBeanServerConnection;
+import javax.management.Notification;
 import javax.management.ObjectName;
 
 import junit.framework.Test;
@@ -49,8 +50,12 @@
 
    public void testEcho() throws Exception
    {
-      Boolean result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      Boolean result = this.testMethod("echo", new Object[] { false }, new Class[] { Boolean.TYPE }, Boolean.class);
       
+      assertFalse(result.booleanValue());
+      
+      result = this.testMethod("echo", new Object[] { true }, new Class[] { Boolean.TYPE }, Boolean.class);
+      
       assertTrue(result.booleanValue());
    }
 
@@ -60,24 +65,40 @@
       
       assertNull(result);
    }
+
+   public void testHandleEvent() throws Exception
+   {
+      Void result = this.testMethod("handleEvent", new Object[] { new Notification("test", "source", 1) }, new Class[] { Notification.class }, Void.class);
+      
+      assertNull(result);
+   }
    
    private <T> T testMethod(String method, Object[] parameters, Class<?>[] types, Class<T> resultType) throws Exception
    {
       MBeanServerConnection[] adaptors = this.getAdaptors();
-      ObjectName on = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
       Object[] args = new Object[] { method, parameters, types };
       String[] signature = new String[] { String.class.getName(), Object[].class.getName(), Class[].class.getName() };
-      List<?> responses = (List<?>) adaptors[0].invoke(on, "callMethodOnPartition", args, signature);
+      List<?> responses = (List<?>) adaptors[0].invoke(name, "callMethodOnPartition", args, signature);
       
-      log.debug("Response list: " + responses);
+      this.log.debug("Response list: " + responses);
       
       assertEquals(1, responses.size());
       
-      if (responses.get(0) instanceof Exception)
+      Object response = responses.get(0);
+      
+      if (response instanceof Exception)
       {
-         throw (Exception) responses.get(0);
+         throw (Exception) response;
       }
 
-      return resultType.cast(responses.get(0));
+      return resultType.cast(response);
    }
+      
+   public void testSendNotification() throws Exception
+   {
+      MBeanServerConnection[] adaptors = this.getAdaptors();
+      ObjectName name = ObjectName.getInstance("jboss.ha:service=EchoHASingleton");
+      adaptors[0].invoke(name, "sendNotification", new Object[] { new Notification("test", "source", 1) }, new String[] { Notification.class.getName() });
+   }
 }




More information about the jboss-cvs-commits mailing list