[jboss-cvs] JBossAS SVN: r73593 - in projects/cluster/ha-client/trunk: src/main/java/org/jboss/aspects/remoting and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 22 14:33:29 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-05-22 14:33:29 -0400 (Thu, 22 May 2008)
New Revision: 73593

Added:
   projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusteredPojiProxy.java
   projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusteredPojiProxyUnitTestCase.java
Modified:
   projects/cluster/ha-client/trunk/pom.xml
   projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterConstants.java
Log:
[JBCLUSTER-200] Add a Clustered PojiProxy

Modified: projects/cluster/ha-client/trunk/pom.xml
===================================================================
--- projects/cluster/ha-client/trunk/pom.xml	2008-05-22 14:38:21 UTC (rev 73592)
+++ projects/cluster/ha-client/trunk/pom.xml	2008-05-22 18:33:29 UTC (rev 73593)
@@ -8,7 +8,7 @@
   <groupId>org.jboss.cluster</groupId>
   <artifactId>jboss-ha-client</artifactId>
   <packaging>jar</packaging>
-  <version>1.1.0.Beta2</version>
+  <version>1.1.0-SNAPSHOT</version>
   <name>JBoss Cluster HA Client Classes</name>
   <url>http://www.jboss.org</url>
   <description>A set of client-side classes commonly used by applications that want HA</description>

Modified: projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterConstants.java
===================================================================
--- projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterConstants.java	2008-05-22 14:38:21 UTC (rev 73592)
+++ projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusterConstants.java	2008-05-22 18:33:29 UTC (rev 73593)
@@ -1,31 +1,33 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.aspects.remoting;
 
 /**
+ * Set of constants used in remoting clustered objects (mostly
+ * as metadata keys in an Invocation).
+ * 
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision: 37406 $
  */
-
 public interface ClusterConstants
 {
    public static final String CLUSTERED_REMOTING = "CLUSTERED_REMOTING";
@@ -34,6 +36,7 @@
    public static final String CLUSTER_FAMILY_WRAPPER = "CLUSTER_FAMILY_WRAPPER";
    public static final String CLUSTER_FAMILY = "CLUSTER_FAMILY";
    public static final String CLUSTER_FAMILIES = "CLUSTER_FAMILIES";
+   public static final String PARTITION_NAME = "PARTITION_NAME";
    public static final String HA_TARGET = "HA_TARGET";
    public static final String CLUSTER_VIEW_ID = "CLUSTER_VIEW_ID";
 }

Added: projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusteredPojiProxy.java
===================================================================
--- projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusteredPojiProxy.java	                        (rev 0)
+++ projects/cluster/ha-client/trunk/src/main/java/org/jboss/aspects/remoting/ClusteredPojiProxy.java	2008-05-22 18:33:29 UTC (rev 73593)
@@ -0,0 +1,81 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.aspects.remoting;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.aop.util.PayloadKey;
+import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * InvocationHandler that generates an aop {@link MethodInvocation} and 
+ * populates its metadata with a target URI as well as various pieces of
+ * clustering metadata.
+ *
+ * @author Brian Stansberry, based on work by Bill Burke
+ */
+public class ClusteredPojiProxy implements java.io.Serializable, InvocationHandler
+{
+   private static final long serialVersionUID = 8054816523858555978L;
+
+   private Object oid;
+   private InvokerLocator uri;
+   private Interceptor[] interceptors;
+   private FamilyWrapper family;
+   private LoadBalancePolicy lbPolicy;
+   private String partitionName;
+   private Object originTarget;
+
+   public ClusteredPojiProxy(Object oid, InvokerLocator uri, Interceptor[] interceptors,
+                             FamilyWrapper family, LoadBalancePolicy lb, 
+                             String partitionName, Object originTarget)
+   {
+      this.oid = oid;
+      this.uri = uri;
+      this.interceptors = interceptors;
+      this.family = family;
+      this.lbPolicy = lb;
+      this.partitionName = partitionName;
+      this.originTarget = originTarget;
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      long hash = MethodHashing.calculateHash(method);
+      MethodInvocation sri = new MethodInvocation(interceptors, hash, method, method, null);
+      sri.setArguments(args);
+      sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.CLUSTER_FAMILY_WRAPPER, family, PayloadKey.TRANSIENT);
+      sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY, lbPolicy, PayloadKey.TRANSIENT);
+      sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.PARTITION_NAME, partitionName, PayloadKey.TRANSIENT);
+      if (originTarget != null)
+         sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.HA_TARGET, originTarget, PayloadKey.TRANSIENT);
+      sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, oid, PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
+      sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
+      return sri.invokeNext();
+   }
+}

Added: projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusteredPojiProxyUnitTestCase.java
===================================================================
--- projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusteredPojiProxyUnitTestCase.java	                        (rev 0)
+++ projects/cluster/ha-client/trunk/src/test/java/org/jboss/test/aspects/remoting/ClusteredPojiProxyUnitTestCase.java	2008-05-22 18:33:29 UTC (rev 73593)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.aspects.remoting;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.aop.util.PayloadKey;
+import org.jboss.aspects.remoting.ClusterConstants;
+import org.jboss.aspects.remoting.ClusteredPojiProxy;
+import org.jboss.aspects.remoting.FamilyWrapper;
+import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
+import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.ha.client.loadbalance.RoundRobin;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * Unit tests for {@link ClusteredPojiProxy}.
+ * 
+ * @author Brian Stansberry
+ *
+ */
+public class ClusteredPojiProxyUnitTestCase extends TestCase
+{
+   protected static final String[] TARGETS = { "A", "B", "C" };
+   protected static final String FAMILY_BASE = "ClusteredPojiProxy";
+   protected static final String MOCK_URI = "http://localhost";
+   protected static final String OK = "OK";
+   protected static int testCount = 0;
+   
+   /**
+    * Create a new ClusteredPojiProxyUnitTestCase.
+    * 
+    * @param name
+    */
+   public ClusteredPojiProxyUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Tests that the proxy sets the expected metadata
+    */
+   public void testInvocationMetaData() throws Throwable
+   {
+      invocationMetaDataTest(TARGETS[0]);
+   }
+
+   /**
+    * Tests that the proxy sets the expected metadata when no originTarget
+    * is provided.
+    */
+   public void testNullOriginTarget() throws Throwable
+   {
+      invocationMetaDataTest(null);
+   }
+   
+   private void invocationMetaDataTest(Object originTarget) throws Throwable
+   {
+      testCount++;
+      List<String> targets = Arrays.asList(TARGETS);
+      FamilyWrapper wrapper = new FamilyWrapper(FAMILY_BASE + testCount, targets); 
+      
+      MockNextInterceptor interceptor = new MockNextInterceptor();
+      interceptor.setReturnValue(OK);
+      
+      Object oid = new Object();
+      LoadBalancePolicy lbp = new RoundRobin();
+      InvokerLocator uri = new InvokerLocator(MOCK_URI);
+      ClusteredPojiProxy proxy = new ClusteredPojiProxy(oid, uri, new Interceptor[]{interceptor}, wrapper, lbp, FAMILY_BASE, originTarget);
+      
+      assertEquals(OK, proxy.invoke(this, Object.class.getDeclaredMethod("toString", new Class[]{}), new Object[]{}));
+      
+      List<SimpleMetaData> history = interceptor.getInvocationHistory();
+      SimpleMetaData metadata = history.get(0);
+      assertSame(wrapper, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.CLUSTER_FAMILY_WRAPPER));
+      assertSame(lbp, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY));
+      assertSame(FAMILY_BASE, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.PARTITION_NAME));
+      assertSame(originTarget, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.HA_TARGET));
+      assertSame(oid, metadata.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID));
+      assertSame(uri, metadata.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR));
+      assertEquals("AOP", metadata.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM));
+      
+   }
+
+}




More information about the jboss-cvs-commits mailing list