[jboss-cvs] JBossAS SVN: r77643 - in trunk/cluster/src: main/org/jboss/ha/framework/server and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 29 07:51:11 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-08-29 07:51:11 -0400 (Fri, 29 Aug 2008)
New Revision: 77643

Added:
   trunk/cluster/src/etc/clustering-deployer-jboss-beans.xml
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/AbstractHAPartitionDependencyDeployer.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/DefaultHAPartitionDependencyCreator.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb2HAPartitionDependencyDeployer.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb3HAPartitionDependencyDeployer.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/HAPartitionDependencyCreator.java
Log:
[JBAS-4592] Add clustering dependencies to clustered EJBs

Added: trunk/cluster/src/etc/clustering-deployer-jboss-beans.xml
===================================================================
--- trunk/cluster/src/etc/clustering-deployer-jboss-beans.xml	                        (rev 0)
+++ trunk/cluster/src/etc/clustering-deployer-jboss-beans.xml	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Clustering-related deployers
+$Id:$
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   
+   <!-- Policy for converting HAPartition names into MC dependency names -->
+   <bean name="HAPartitionDependencyCreator" 
+         class="org.jboss.ha.framework.server.deployers.DefaultHAPartitionDependencyCreator"/>
+         
+   <!--  Adds a dependency on the appropriate HAPartition to clustered EJB2 beans. -->
+   <bean name="Ejb2HAPartitionDependencyDeployer" 
+         class="org.jboss.ha.framework.server.deployers.Ejb2HAPartitionDependencyDeployer">         
+      <property name="haPartitionDependencyCreator"><inject bean="HAPartitionDependencyCreator"/></property>
+   </bean>
+   
+   <!--  Adds a dependency on the appropriate HAPartition to clustered EJB3 beans. -->
+   <bean name="Ejb3HAPartitionDependencyDeployer" 
+         class="org.jboss.ha.framework.server.deployers.Ejb3HAPartitionDependencyDeployer">         
+      <property name="haPartitionDependencyCreator"><inject bean="HAPartitionDependencyCreator"/></property>
+   </bean>
+
+</deployment>

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/AbstractHAPartitionDependencyDeployer.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/AbstractHAPartitionDependencyDeployer.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/AbstractHAPartitionDependencyDeployer.java	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,88 @@
+package org.jboss.ha.framework.server.deployers;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb.deployers.MergedJBossMetaDataDeployer;
+import org.jboss.metadata.ejb.jboss.ClusterConfigMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+
+public abstract class AbstractHAPartitionDependencyDeployer extends AbstractDeployer
+{
+
+   private HAPartitionDependencyCreator dependencyCreator;
+
+   public AbstractHAPartitionDependencyDeployer()
+   {
+      super();     
+      addInput(MergedJBossMetaDataDeployer.EJB_MERGED_ATTACHMENT_NAME);
+      addOutput(MergedJBossMetaDataDeployer.EJB_MERGED_ATTACHMENT_NAME);
+      setStage(DeploymentStages.POST_CLASSLOADER);
+   }
+
+   public synchronized HAPartitionDependencyCreator getHaPartitionDependencyCreator()
+   {
+      if (dependencyCreator == null)
+      {
+         dependencyCreator = DefaultHAPartitionDependencyCreator.INSTANCE;
+      }
+      return dependencyCreator;
+   }
+
+   public synchronized void setHaPartitionDependencyCreator(HAPartitionDependencyCreator dependencyCreator)
+   {
+      this.dependencyCreator = dependencyCreator;
+   }
+
+   /**
+    * Adds the dependency to relevant metadata.
+    * 
+    * {@inheritDoc}
+    */
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      JBossMetaData metaData = unit.getAttachment(MergedJBossMetaDataDeployer.EJB_MERGED_ATTACHMENT_NAME, JBossMetaData.class);
+      if (metaData != null && accepts(metaData))
+      {
+         JBossEnterpriseBeansMetaData beans = metaData.getEnterpriseBeans();
+         if (beans != null)
+         {
+            for (Iterator<JBossEnterpriseBeanMetaData> it = beans.iterator(); it.hasNext(); )
+            {
+               JBossEnterpriseBeanMetaData bmd = it.next();
+               ClusterConfigMetaData ccmd = getClusteredBeanClusterConfig(bmd);
+               if (ccmd != null)
+               {
+                  addHAPartitionDependency(bmd, ccmd);
+               }
+            }
+         }
+      }
+   }
+   
+   protected abstract boolean accepts(JBossMetaData metaData);
+   
+   protected abstract void configureDeploymentStage();
+   
+   protected abstract ClusterConfigMetaData getClusteredBeanClusterConfig(JBossEnterpriseBeanMetaData bmd);
+
+   private void addHAPartitionDependency(JBossEnterpriseBeanMetaData bmd, ClusterConfigMetaData ccmd)
+   {
+      String dependencyName = getHaPartitionDependencyCreator().getHAPartitionDependencyName(ccmd.getPartitionName());
+      Set<String> depends = bmd.getDepends();
+      if (depends == null)
+      {
+         depends = new HashSet<String>();
+      }
+      depends.add(dependencyName);
+      bmd.setDepends(depends);
+   }
+
+}
\ No newline at end of file

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/DefaultHAPartitionDependencyCreator.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/DefaultHAPartitionDependencyCreator.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/DefaultHAPartitionDependencyCreator.java	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,120 @@
+/*
+ * 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.ha.framework.server.deployers;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.ClusterConfigMetaData;
+import org.jboss.util.StringPropertyReplacer;
+
+/**
+ * Default impl of {@link HAPartitionDependencyCreator}.  Prepends a configurable
+ * prefix to the system-property-replaced partition name.
+ * 
+ * @author Brian Stansberry
+ */
+public class DefaultHAPartitionDependencyCreator implements HAPartitionDependencyCreator
+{
+   private static final Logger log = Logger.getLogger(DefaultHAPartitionDependencyCreator.class);
+   
+   public static final String DEFAULT_HA_PARTITION_DEPENDENCY_PREFIX = "partition:partitionName=";
+   
+   /** Shared instance, although this isn't a singleton */
+   public static final DefaultHAPartitionDependencyCreator INSTANCE = new DefaultHAPartitionDependencyCreator();
+   
+   private final String prefix;
+
+   // ----------------------------------------------------------- Constructors
+   
+   /**
+    * Create a new DefaultHAPartitionDependencyCreator using the
+    * {@link #DEFAULT_HA_PARTITION_DEPENDENCY_PREFIX default prefix}.
+    */
+   public DefaultHAPartitionDependencyCreator()
+   {
+      this(DEFAULT_HA_PARTITION_DEPENDENCY_PREFIX);
+   }
+   
+   /**
+    * Create a new DefaultHAPartitionDependencyCreator.
+    * 
+    * @param prefix the string that should be prepended to 
+    * {@link ClusterConfigMetaData#getPartitionName() the bean metadata's partition name}
+    * to determine the name of the dependency.
+    */
+   public DefaultHAPartitionDependencyCreator(String prefix)
+   {
+      if (prefix == null)
+         throw new IllegalArgumentException("prefix cannot be null");
+      
+      this.prefix = prefix;
+   }
+
+   // -------------------------------------------  HAPartitionDependencyCreator
+
+   public String getHAPartitionDependencyName(String partitionName)
+   {
+      return getHaPartitionDependencyPrefix() + getPropertyReplacedPartitionName(partitionName);
+   }
+
+   // -------------------------------------------------------------  Properties
+   
+   /**
+    * Gets the string that should be prepended to 
+    * {@link ClusterConfigMetaData#getPartitionName() the bean metadata's partition name}
+    * to determine the name of the dependency.
+    * <p>
+    * <code>ClusterPartition</code> will also use the property to determine
+    * the name of a microcontainer alias to itself, which it will register
+    * in order to satisfy the dependency.
+    * </p>
+    * 
+    * @return the prefix, or {@link #DEFAULT_HA_PARTITION_DEPENDENCY_PREFIX} if
+    *         not configured.
+    */
+   public String getHaPartitionDependencyPrefix()
+   {
+      return prefix == null ? DEFAULT_HA_PARTITION_DEPENDENCY_PREFIX : prefix;
+   }
+
+
+   private static String getPropertyReplacedPartitionName(String partitionName)
+   {
+      String value = partitionName;
+      try
+      {
+         String replacedValue = StringPropertyReplacer.replaceProperties(value);
+         if (value != replacedValue)
+         {            
+            log.debug("Replacing " + ClusterConfigMetaData.class.getSimpleName() + 
+                  " partitionName property " + value + " with " + replacedValue);
+            value = replacedValue;
+         }
+      }
+      catch (Exception e)
+      {
+         log.warn("Unable to replace partition name " + value, e);         
+      }
+      
+      return value;
+   }
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb2HAPartitionDependencyDeployer.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb2HAPartitionDependencyDeployer.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb2HAPartitionDependencyDeployer.java	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,84 @@
+/*
+ * 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.ha.framework.server.deployers;
+
+
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.metadata.ejb.jboss.ClusterConfigMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * Adds a dependency on the HAPartition to any JBossSessionBeanMetaData
+ * whose <code>isClustered</code> returns <code>true</code>.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision : $
+ */
+public class Ejb2HAPartitionDependencyDeployer extends AbstractHAPartitionDependencyDeployer
+{
+   /**
+    * Create a new Ejb2HAPartitionDependencyDeployer.
+    * 
+    */
+   public Ejb2HAPartitionDependencyDeployer()
+   {
+      super();
+   }
+
+   // -------------------------------------------------------------  Properties
+
+   @Override
+   protected boolean accepts(JBossMetaData metaData)
+   {      
+      return !metaData.isEJB3x();
+   }
+   
+   protected void configureDeploymentStage()
+   {
+      setStage(DeploymentStages.PRE_DESCRIBE);
+   }
+   
+   protected ClusterConfigMetaData getClusteredBeanClusterConfig(JBossEnterpriseBeanMetaData bmd)
+   {
+      if (bmd instanceof JBossSessionBeanMetaData)
+      {
+         JBossSessionBeanMetaData sbmd = (JBossSessionBeanMetaData) bmd;
+         if (sbmd.isClustered())
+         {
+            return sbmd.getClusterConfig();
+         }               
+      }
+      else if (bmd instanceof JBossEntityBeanMetaData)
+      {
+         JBossEntityBeanMetaData ebmd = (JBossEntityBeanMetaData) bmd;
+         if (ebmd.isClustered())
+         {
+            return ebmd.getClusterConfig();
+         }               
+      }
+      return null;
+   }
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb3HAPartitionDependencyDeployer.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb3HAPartitionDependencyDeployer.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/Ejb3HAPartitionDependencyDeployer.java	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,84 @@
+/*
+ * 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.ha.framework.server.deployers;
+
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.metadata.ejb.jboss.ClusterConfigMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class Ejb3HAPartitionDependencyDeployer extends AbstractHAPartitionDependencyDeployer
+{
+
+   /**
+    * Create a new Ejb3HAPartitionDependencyDeployer.
+    * 
+    */
+   public Ejb3HAPartitionDependencyDeployer()
+   {
+      super();
+   }
+
+   @Override
+   protected boolean accepts(JBossMetaData metaData)
+   {      
+      return metaData.isEJB3x();
+   }
+
+   /**
+    * Overrides the superclass to run in PRE_REAL as the merge of annotation
+    * metadata and xml metadata only occurs in POST_CLASSLOADER.
+    */
+   @Override
+   protected void configureDeploymentStage()
+   {
+      setStage(DeploymentStages.PRE_REAL);
+   }
+
+   /**
+    * FIXME: use superclass behavior when JBMETA-100 is fixed.
+    */
+   @Override
+   protected ClusterConfigMetaData getClusteredBeanClusterConfig(JBossEnterpriseBeanMetaData bmd)
+   {
+      if (bmd instanceof JBossSessionBeanMetaData)
+      {
+         JBossSessionBeanMetaData sbmd = (JBossSessionBeanMetaData) bmd;
+         return sbmd.getClusterConfig();                        
+      }
+      else if (bmd instanceof JBossEntityBeanMetaData)
+      {
+         JBossEntityBeanMetaData ebmd = (JBossEntityBeanMetaData) bmd;
+         return ebmd.getClusterConfig();                        
+      }
+      return null;
+   }
+
+   
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/HAPartitionDependencyCreator.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/HAPartitionDependencyCreator.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/deployers/HAPartitionDependencyCreator.java	2008-08-29 11:51:11 UTC (rev 77643)
@@ -0,0 +1,43 @@
+/*
+ * 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.ha.framework.server.deployers;
+
+/**
+ * Policy for creating an MC bean name from a partition name. Bean name
+ * can be added as a dependency to metadata for deployments that use
+ * the specified partition.
+ * 
+ * @author Brian Stansberry
+ *
+ */
+public interface HAPartitionDependencyCreator
+{
+   /**
+    * Gets the MC bean name upon which a bean using the given partition
+    * can depend.
+    * 
+    * @param partitionName the partition name. Cannot be <code>null</code>
+    * @return the bean name
+    */
+   String getHAPartitionDependencyName(String partitionName);
+}




More information about the jboss-cvs-commits mailing list