[jboss-cvs] JBossAS SVN: r57493 - in branches/JEE5_TCK/ejb3/src: main/org/jboss/annotation/ejb main/org/jboss/ejb3/session main/org/jboss/ejb3/stateful main/org/jboss/ejb3/stateless resources/test/clusteredsession/META-INF test/org/jboss/ejb3/test/clusteredsession test/org/jboss/ejb3/test/clusteredsession/unit
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Oct 8 00:33:19 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-10-08 00:33:16 -0400 (Sun, 08 Oct 2006)
New Revision: 57493
Modified:
branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java
branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/ClusteredImpl.java
branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/ejb-jar.xml
branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/jboss.xml
branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatefulBean.java
branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/BeanUnitTestCase.java
Log:
[EJBTHREE-424] Make ${jboss.partition.name:DefaultPartition} @Clustered.partition() default
Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -40,5 +40,5 @@
{
Class loadBalancePolicy() default LoadBalancePolicy.class;
- String partition() default "DefaultPartition";
+ String partition() default "${jboss.partition.name:DefaultPartition}";;
}
Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/ClusteredImpl.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/ClusteredImpl.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/annotation/ejb/ClusteredImpl.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -32,7 +32,7 @@
public class ClusteredImpl implements Clustered
{
private Class loadBalancePolicy = LoadBalancePolicy.class;
- private String partition = "DefaultPartition";
+ private String partition = null;
public Class loadBalancePolicy()
Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -26,12 +26,17 @@
import javax.ejb.HomeHandle;
import javax.ejb.Remote;
import javax.ejb.RemoteHome;
+import javax.management.ObjectName;
+
import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.aop.Advisor;
import org.jboss.ejb3.Container;
import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.KernelAbstraction;
+import org.jboss.ejb3.KernelAbstractionFactory;
import org.jboss.ejb3.ProxyFactory;
import org.jboss.logging.Logger;
+import org.jboss.util.StringPropertyReplacer;
import org.jboss.ejb3.proxy.EJBMetaDataImpl;
import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
@@ -104,5 +109,39 @@
return metadata;
}
+
+ /**
+ * Performs a system property substitution if the given value conforms to the
+ * "${property.name}" or "${property.name:defaultvalue}" patterns; otherwise just
+ * returns <code>value</value>.
+ *
+ * TODO Put this in a utility somewhere; this is just the common parent of
+ * the places that currently use it.
+ *
+ * @param value a String that may represent a system property.
+ *
+ * @return the value of the given system property, or the provided default value
+ * if there was no system property matching the given string, or
+ * <code>value</code> itself if it didn't encode a system property name.
+ */
+ protected String substituteSystemProperty(String value)
+ {
+ try
+ {
+ String replacedValue = StringPropertyReplacer.replaceProperties(value);
+ if (value != replacedValue)
+ {
+ log.debug("Replacing @Clustered partition attribute " + value + " with " + replacedValue);
+ value = replacedValue;
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to replace @Clustered partition attribute " + value +
+ ". Caused by " + e.getClass() + " " + e.getMessage());
+ }
+
+ return value;
+ }
}
Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -86,7 +86,9 @@
locator = new InvokerLocator(clientBindUrl);
Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation. Cannot deploy.");
- String partitionName = clustered.partition();
+ // Partition name may be ${jboss.partition.name:DefaultPartition}
+ // so do a system property substitution
+ String partitionName = substituteSystemProperty(clustered.partition());
proxyFamilyName = container.getEjbName() + locator.getProtocol() + partitionName;
HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -79,7 +79,9 @@
locator = new InvokerLocator(clientBindUrl);
Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation. Cannot deploy.");
- String partitionName = clustered.partition();
+ // Partition name may be ${jboss.partition.name:DefaultPartition}
+ // so do a system property substitution
+ String partitionName = substituteSystemProperty(clustered.partition());
proxyFamilyName = container.getEjbName() + locator.getProtocol() + partitionName;
HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
Modified: branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/ejb-jar.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/ejb-jar.xml 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/ejb-jar.xml 2006-10-08 04:33:16 UTC (rev 57493)
@@ -7,6 +7,20 @@
version="3.0">
<enterprise-beans>
<session>
+ <ejb-name>NonAnnotationStateful</ejb-name>
+ <remote>org.jboss.ejb3.test.clusteredsession.StatefulRemote</remote>
+ <ejb-class>org.jboss.ejb3.test.clusteredsession.NonAnnotationStatefulBean</ejb-class>
+ <session-type>Stateful</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+ <session>
+ <ejb-name>EjbJarOverrideAnnotationStateful</ejb-name>
+ <remote>org.jboss.ejb3.test.clusteredsession.StatefulRemote</remote>
+ <ejb-class>org.jboss.ejb3.test.clusteredsession.OverrideAnnotationStatefulBean</ejb-class>
+ <session-type>Stateful</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+ <session>
<ejb-name>NonClusteredStateful</ejb-name>
<remote>org.jboss.ejb3.test.clusteredsession.OverrideStatefulRemote</remote>
<ejb-class>org.jboss.ejb3.test.clusteredsession.OverrideStatefulBean</ejb-class>
Modified: branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/jboss.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/jboss.xml 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/resources/test/clusteredsession/META-INF/jboss.xml 2006-10-08 04:33:16 UTC (rev 57493)
@@ -16,6 +16,30 @@
</cluster-config>
</session>
<session>
+ <ejb-name>NonAnnotationStateful</ejb-name>
+ <clustered>true</clustered>
+ <cluster-config>
+ <partition-name>${jboss.partition.name:DefaultPartition}</partition-name>
+ <load-balance-policy>org.jboss.ha.framework.interfaces.FirstAvailableIdenticalAllProxies</load-balance-policy>
+ </cluster-config>
+ </session>
+ <session>
+ <ejb-name>OverrideAnnotationStateful</ejb-name>
+ <clustered>true</clustered>
+ <cluster-config>
+ <partition-name>${jboss.partition.name:DefaultPartition}</partition-name>
+ <load-balance-policy>org.jboss.ha.framework.interfaces.FirstAvailableIdenticalAllProxies</load-balance-policy>
+ </cluster-config>
+ </session>
+ <session>
+ <ejb-name>EjbJarOverrideAnnotationStateful</ejb-name>
+ <clustered>true</clustered>
+ <cluster-config>
+ <partition-name>${jboss.partition.name:DefaultPartition}</partition-name>
+ <load-balance-policy>org.jboss.ha.framework.interfaces.FirstAvailableIdenticalAllProxies</load-balance-policy>
+ </cluster-config>
+ </session>
+ <session>
<ejb-name>NonClusteredStateful</ejb-name>
<jndi-name>NonClusteredStatefulRemote</jndi-name>
<clustered>false</clustered>
Modified: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatefulBean.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatefulBean.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatefulBean.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -1,8 +1,8 @@
/*
- * 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.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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
@@ -23,163 +23,19 @@
import javax.ejb.Remote;
import javax.ejb.Stateful;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
-import javax.ejb.Remove;
-import javax.ejb.EJBException;
-import javax.naming.InitialContext;
-import javax.annotation.PostConstruct;
-import javax.interceptor.Interceptors;
import org.jboss.annotation.ejb.Clustered;
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.system.server.ServerConfig;
-import java.rmi.dgc.VMID;
-import org.jboss.logging.Logger;
-
/**
- * SFSB interface
+ * Stateful bean that configures clustering via annotations.
*
* @author Ben Wang
* @version $Revision$
*/
@Stateful(name="testStateful")
@Clustered
-// Mimic explict failover
- at Interceptors({ExplicitFailoverInterceptor.class})
- at CacheConfig(maxSize=1000, idleTimeoutSeconds=3) // this will get evicted the second time eviction thread wakes up
@Remote(StatefulRemote.class)
-public class StatefulBean implements java.io.Serializable, StatefulRemote
-{
- private Logger log = Logger.getLogger(StatefulBean.class);
- private int counter = 0;
- private String state;
- public transient VMID myId = null;
- public String name;
-
- public int increment()
- {
- System.out.println("INCREMENT - counter: " + (counter++));
- return counter;
- }
-
- public String getHostAddress()
- {
- return System.getProperty(ServerConfig.SERVER_BIND_ADDRESS);
- }
-
- public static int postActivateCalled = 0;
- public static int prePassivateCalled = 0;
-
- /**
- * Sleep to test
- * @throws Exception
- */
- public void longRunning() throws Exception
- {
- log.debug("+++ longRunning() enter ");
- Thread.sleep(20000); // 20000 will break the passivation test now.
- log.debug("+++ longRunning() leave ");
- }
-
- public int getPostActivate()
- {
- return postActivateCalled;
- }
-
- public int getPrePassivate()
- {
- return prePassivateCalled;
- }
-
- public void setState(String state)
- {
- this.state = state;
- }
-
- public String getState()
- {
- log.debug("getState(): entering ...");
- return this.state;
- }
-
- public void reset()
- {
- state = null;
- postActivateCalled = 0;
- prePassivateCalled = 0;
- }
-
- public void resetActivationCounter() {
- postActivateCalled = 0;
- prePassivateCalled = 0;
- }
-
- @PostActivate
- public void postActivate()
- {
- ++postActivateCalled;
- if (this.myId == null)
- {
- //it is a failover: we need to assign ourself an id
- this.myId = new VMID();
- }
- log.debug("Activate. My ID: " + this.myId + " name: " + this.name);
- }
-
- @PrePassivate
- public void prePassivate()
- {
- ++prePassivateCalled;
- log.debug("Passivate. My ID: " + this.myId + " name: " + this.name);
- }
-
- @Remove
- public void remove()
- {
- }
-
- @PostConstruct
- public void ejbCreate()
- {
- this.myId = new VMID();
- log.debug("My ID: " + this.myId);
- }
-
- // Remote Interface implementation ----------------------------------------------
-
- public NodeAnswer getNodeState()
- {
- if (this.myId == null)
- {
- //it is a failover: we need to assign ourself an id because of transient nature
- this.myId = new VMID();
- }
-
- NodeAnswer state = new NodeAnswer(this.myId, this.name);
- log.debug("getNodeState, " + state);
- return state;
- }
-
- public void setName(String name)
- {
- this.name = name;
- log.debug("Name set to " + name);
- }
-
- public void setNameOnlyOnNode(String name, VMID node)
- {
- if (node.equals(this.myId))
- this.setName(name);
- else
- throw new EJBException("Trying to assign value on node " + this.myId + " but this node expected: " + node);
- }
-
- public void setUpFailover(String failover) {
- // To setup the failover property
- log.debug("Setting up failover property: " +failover);
- System.setProperty ("JBossCluster-DoFail", failover);
- }
-
+public class StatefulBean extends NonAnnotationStatefulBean
+{
+ // Only difference from superclass is the added class-level annotations
}
Modified: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/BeanUnitTestCase.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/BeanUnitTestCase.java 2006-10-08 04:30:19 UTC (rev 57492)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/BeanUnitTestCase.java 2006-10-08 04:33:16 UTC (rev 57493)
@@ -1,10 +1,24 @@
/*
- * JBoss, Home of Professional Open Source
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.
*
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ * 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.ejb3.test.clusteredsession.unit;
import org.jboss.test.JBossClusteredTestCase;
@@ -62,17 +76,40 @@
public void testBasic()
throws Exception
{
+ basicTest("testStateful/remote");
+ }
+
+ public void testBasicWithoutAnnotation()
+ throws Exception
+ {
+ basicTest("NonAnnotationStateful/remote");
+ }
+
+ public void testBasicWithXMLOverride()
+ throws Exception
+ {
+ basicTest("OverrideAnnotationStateful/remote");
+ }
+
+ public void testBasicWithEjbJarXMLOverride()
+ throws Exception
+ {
+ basicTest("EjbJarOverrideAnnotationStateful/remote");
+ }
+
+ private void basicTest(String jndiBinding) throws Exception
+ {
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
- getLog().debug("Test Stateful Bean");
+ getLog().debug("Basic Test with " + jndiBinding);
getLog().debug("==================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
- +"Looking up testBasic...");
- StatefulRemote stateful = (StatefulRemote) ctx.lookup("testStateful/remote");
+ +"Looking up " + jndiBinding + "...");
+ StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("The Code");
_sleep(300);
@@ -90,16 +127,40 @@
public void testStatefulBeanCounterFailover()
throws Exception
{
+ statefulBeanCounterFailoverTest("testStateful/remote");
+ }
+
+ public void testStatefulBeanCounterFailoverWithoutAnnotation()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("NonAnnotationStateful/remote");
+ }
+
+ public void testStatefulBeanCounterFailoverWithXMLOverride()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("OverrideAnnotationStateful/remote");
+ }
+
+ public void testStatefulBeanCounterFailoverWithEjbJarXMLOverride()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("EjbJarOverrideAnnotationStateful/remote");
+ }
+
+ private void statefulBeanCounterFailoverTest(String jndiBinding)
+ throws Exception
+ {
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
- getLog().debug("Test Stateful Bean Failover");
- getLog().debug("==================================");
+ getLog().debug("Test Stateful Bean Counter Failover with " + jndiBinding);
+ getLog().debug("=========================================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
- +"Looking up testStateful...");
- StatefulRemote stateful = (StatefulRemote) ctx.lookup("testStateful/remote");
+ +"Looking up " + jndiBinding + "...");
+ StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("The Code");
NodeAnswer node1 = stateful.getNodeState ();
@@ -131,16 +192,40 @@
public void testStatefulBeanFailover()
throws Exception
{
+ statefulBeanFailoverTest("testStateful/remote");
+ }
+
+ public void testStatefulBeanFailoverWithoutAnnotation()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("NonAnnotationStateful/remote");
+ }
+
+ public void testStatefulBeanFailoverWithXMLOverride()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("OverrideAnnotationStateful/remote");
+ }
+
+ public void testStatefulBeanFailoverWithEjbJarXMLOverride()
+ throws Exception
+ {
+ statefulBeanCounterFailoverTest("EjbJarOverrideAnnotationStateful/remote");
+ }
+
+ private void statefulBeanFailoverTest(String jndiBinding)
+ throws Exception
+ {
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
- getLog().debug("Test Stateful Bean Failover");
- getLog().debug("==================================");
+ getLog().debug("Test Stateful Bean Failover with " + jndiBinding);
+ getLog().debug("================================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
- +"Looking up testStateful...");
- StatefulRemote stateful = (StatefulRemote) ctx.lookup("testStateful/remote");
+ +"Looking up " + jndiBinding + "...");
+ StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("Bupple-Dupple");
_sleep(300);
@@ -172,7 +257,6 @@
assertNotNull("State node id should not be null: ", node1.nodeId);
getLog ().debug (node1);
- _sleep(300);
assertNotSame ("No failover has occured!", node1.nodeId, node2.nodeId);
assertEquals ("Value is not identical on replicated node", "Changed", node1.answer );
More information about the jboss-cvs-commits
mailing list