[jboss-cvs] JBossAS SVN: r77644 - trunk/cluster/src/main/org/jboss/ha/framework/server.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 29 07:52:12 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-08-29 07:52:12 -0400 (Fri, 29 Aug 2008)
New Revision: 77644
Modified:
trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
[JBAS-4592] Add clustering dependencies to clustered EJBs
Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java 2008-08-29 11:51:11 UTC (rev 77643)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java 2008-08-29 11:52:12 UTC (rev 77644)
@@ -34,6 +34,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
@@ -52,8 +53,12 @@
import org.jboss.ha.framework.interfaces.DistributedState;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.ResponseFilter;
+import org.jboss.ha.framework.server.deployers.DefaultHAPartitionDependencyCreator;
+import org.jboss.ha.framework.server.deployers.HAPartitionDependencyCreator;
import org.jboss.invocation.MarshalledValueInputStream;
import org.jboss.invocation.MarshalledValueOutputStream;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
import org.jboss.naming.NonSerializableFactory;
import org.jboss.system.ServiceMBeanSupport;
@@ -225,8 +230,8 @@
/** The DistributedState service we manage */
protected DistributedStateImpl distributedState;
/** The cluster instance log category */
- protected Logger log;
- protected Logger clusterLifeCycleLog;
+ protected Logger log = Logger.getLogger(HAPartition.class.getName());;
+ protected Logger clusterLifeCycleLog = Logger.getLogger(HAPartition.class.getName() + ".lifecycle");
/** The current cluster view id */
protected long currentViewId = -1;
/** Whether to bind the partition into JNDI */
@@ -251,6 +256,9 @@
protected Exception connectException;
private final Object channelLock = new Object();
private final MessageListenerAdapter messageListener = new MessageListenerAdapter();
+
+ private HAPartitionDependencyCreator haPartitionDependencyCreator;
+ private KernelControllerContext kernelControllerContext;
// Static --------------------------------------------------------
@@ -310,6 +318,10 @@
// Create the asynchronous handler for view changes
this.asynchHandler = new AsynchEventHandler(this, "AsynchViewChangeHandler");
+
+ // Add a well-known MC alias that other beans can depend on
+ addCanonicalAlias();
+
this.log.debug("done initializing partition");
}
@@ -496,6 +508,8 @@
{
this.log.debug("Destroying HAPartition: " + this.getPartitionName());
+ removeCanonicalAlias();
+
if (this.distributedState != null)
{
this.distributedState.destroyService();
@@ -517,6 +531,54 @@
this.log.info("Partition " + this.getPartitionName() + " destroyed.");
}
+
+ /**
+ * Adds an alias to our controller context -- the concatenation of
+ * {@link #getAliasPrefix()} and {@link #getPartitionName()}.
+ * This mechanism allows Ejb2HAPartitionDependencyDeployer to add
+ * dependencies to deployments based on the partition name specified in
+ * their metadata, without needing to know the bean name of this partition.
+ */
+ private void addCanonicalAlias()
+ {
+ if (kernelControllerContext != null)
+ {
+ KernelController kc = (KernelController) kernelControllerContext.getController();
+ String aliasName = getHaPartitionDependencyCreator().getHAPartitionDependencyName(this.partitionName);
+ try
+ {
+ kc.addAlias(aliasName, kernelControllerContext.getName());
+ }
+ catch (Throwable t)
+ {
+ log.error("Failed adding alias " + aliasName + " to context " + kernelControllerContext.getName(), t);
+ }
+ }
+ }
+
+ /**
+ * Removes the alias created in {@link #addCanonicalAlias()}
+ */
+ private void removeCanonicalAlias()
+ {
+ if (kernelControllerContext != null)
+ {
+ KernelController kc = (KernelController) kernelControllerContext.getController();
+ String aliasName = getHaPartitionDependencyCreator().getHAPartitionDependencyName(this.partitionName);
+ Set<Object> aliases = kernelControllerContext.getAliases();
+ if (aliases != null && aliases.contains(aliasName))
+ {
+ try
+ {
+ kc.removeAlias(aliasName);
+ }
+ catch (Throwable t)
+ {
+ log.error("Failed removing alias " + aliasName + " from context " + kernelControllerContext.getName(), t);
+ }
+ }
+ }
+ }
// ---------------------------------------------------------- State Transfer
@@ -1529,6 +1591,20 @@
this.threadPool = threadPool;
}
+ public synchronized HAPartitionDependencyCreator getHaPartitionDependencyCreator()
+ {
+ if (haPartitionDependencyCreator == null)
+ {
+ haPartitionDependencyCreator = DefaultHAPartitionDependencyCreator.INSTANCE;
+ }
+ return haPartitionDependencyCreator;
+ }
+
+ public synchronized void setHaPartitionDependencyCreator(HAPartitionDependencyCreator haPartitionDependencyCreator)
+ {
+ this.haPartitionDependencyCreator = haPartitionDependencyCreator;
+ }
+
protected Vector<ClusterNode> translateAddresses(Vector<Address> addresses)
{
if (addresses == null)
@@ -1682,7 +1758,23 @@
{
this.method_call_timeout = timeout;
}
+
+ // KernelControllerContextAware --------------------------------------------
+
+ @Override
+ public void setKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+ {
+ super.setKernelControllerContext(controllerContext);
+ this.kernelControllerContext = controllerContext;
+ }
+ @Override
+ public void unsetKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+ {
+ super.unsetKernelControllerContext(controllerContext);
+ this.kernelControllerContext = null;
+ }
+
// Protected --------------------------------------------------------------
/**
More information about the jboss-cvs-commits
mailing list