[jboss-cvs] JBossAS SVN: r62714 - in branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3: stateless and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 1 23:23:36 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-05-01 23:23:36 -0400 (Tue, 01 May 2007)
New Revision: 62714
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
Log:
[EJBTHREE-949] Correctly handle topology changes
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2007-05-02 01:27:46 UTC (rev 62713)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2007-05-02 03:23:36 UTC (rev 62714)
@@ -22,6 +22,8 @@
package org.jboss.ejb3.stateful;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
import javax.naming.NamingException;
@@ -38,10 +40,12 @@
import org.jboss.ejb3.ProxyFactoryHelper;
import org.jboss.ejb3.remoting.RemoteProxyFactory;
import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
import org.jboss.ha.framework.interfaces.FirstAvailable;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
import org.jboss.ha.framework.server.HATarget;
+import org.jboss.logging.Logger;
import org.jboss.naming.Util;
import org.jboss.remoting.InvokerLocator;
@@ -54,12 +58,16 @@
*
* @version $Revision$
*/
-public class StatefulClusterProxyFactory extends BaseStatefulProxyFactory implements RemoteProxyFactory
+public class StatefulClusterProxyFactory extends BaseStatefulProxyFactory
+ implements RemoteProxyFactory, DistributedReplicantManager.ReplicantListener
{
+ private static final Logger log = Logger.getLogger(StatefulClusterProxyFactory.class);
+
public static final String FACTORY_ATTRIBUTE = ",element=ProxyFactory,partition=";
private RemoteBinding binding;
private InvokerLocator locator;
+ private DistributedReplicantManager drm;
private HATarget hatarget;
private String proxyFamilyName;
private LoadBalancePolicy lbPolicy;
@@ -105,7 +113,12 @@
lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
}
wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
+
+ this.drm = partition.getDistributedReplicantManager();
+ drm.registerListener(proxyFamilyName, this);
+
super.start();
+
Class[] interfaces = {ProxyFactory.class};
String targetId = getTargetId();
Object factoryProxy = Remoting.createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
@@ -136,6 +149,7 @@
String partitionName = ((StatefulContainer) container).getPartitionName();
Object[] args = {new StatefulClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null),
wrapper, lbPolicy, partitionName)};
+
return proxyConstructor.newInstance(args);
}
catch (InstantiationException e)
@@ -165,6 +179,7 @@
{
Dispatcher.singleton.unregisterTarget(getTargetId());
hatarget.destroy();
+ drm.unregisterListener(proxyFamilyName, this);
((StatefulContainer) container).getClusterFamilies().remove(proxyFamilyName);
Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
super.stop();
@@ -185,5 +200,21 @@
String partition = ((StatefulContainer) container).getPartitionName();
return container.getObjectName().getCanonicalName() + FACTORY_ATTRIBUTE + partition;
}
+
+ public synchronized void replicantsChanged (String key,
+ List newReplicants,
+ int newReplicantsViewId)
+ {
+ try
+ {
+ // Update the FamilyClusterInfo with the new targets
+ ArrayList targets = new ArrayList(newReplicants);
+ wrapper.get().updateClusterInfo(targets, newReplicantsViewId);
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ }
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java 2007-05-02 01:27:46 UTC (rev 62713)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java 2007-05-02 03:23:36 UTC (rev 62714)
@@ -222,15 +222,7 @@
Object proxy = createProxy();
//describeClass(proxy.getClass());
- try
- {
- Util.rebind(container.getInitialContext(), jndiName, proxy);
- } catch (NamingException e)
- {
- NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
- namingException.setRootCause(e);
- throw namingException;
- }
+ bindProxy(proxy);
}
public void stop() throws Exception
@@ -242,6 +234,20 @@
protected abstract void initializeJndiName();
+ protected void bindProxy(Object proxy) throws NamingException
+ {
+ try
+ {
+ log.debug("Binding proxy for " + container.getEjbName() + " in JNDI at " + jndiName);
+ Util.rebind(container.getInitialContext(), jndiName, proxy);
+ } catch (NamingException e)
+ {
+ NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
+ namingException.setRootCause(e);
+ throw namingException;
+ }
+ }
+
public void setContainer(Container container)
{
this.container = container;
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java 2007-05-02 01:27:46 UTC (rev 62713)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java 2007-05-02 03:23:36 UTC (rev 62714)
@@ -21,7 +21,9 @@
*/
package org.jboss.ejb3.stateless;
-import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
import org.jboss.annotation.ejb.Clustered;
import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.aop.Advisor;
@@ -31,12 +33,13 @@
import org.jboss.ejb3.JBossProxy;
import org.jboss.ejb3.ProxyFactoryHelper;
import org.jboss.ejb3.remoting.RemoteProxyFactory;
-import org.jboss.ejb3.stateful.StatefulContainer;
import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
import org.jboss.ha.framework.interfaces.RandomRobin;
import org.jboss.ha.framework.server.HATarget;
+import org.jboss.logging.Logger;
import org.jboss.remoting.InvokerLocator;
@@ -46,14 +49,19 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class StatelessClusterProxyFactory extends BaseStatelessProxyFactory implements RemoteProxyFactory
+public class StatelessClusterProxyFactory extends BaseStatelessProxyFactory
+ implements RemoteProxyFactory, DistributedReplicantManager.ReplicantListener
{
+ private static final Logger log = Logger.getLogger(StatelessClusterProxyFactory.class);
+
private RemoteBinding binding;
private InvokerLocator locator;
+ private DistributedReplicantManager drm;
private HATarget hatarget;
private String proxyFamilyName;
private LoadBalancePolicy lbPolicy;
private FamilyWrapper wrapper;
+ private Object proxy;
public void setRemoteBinding(RemoteBinding binding)
{
@@ -95,13 +103,19 @@
lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
}
wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
+
+ this.drm = partition.getDistributedReplicantManager();
+ drm.registerListener(proxyFamilyName, this);
+
super.start();
}
public void stop() throws Exception
{
super.stop();
+ proxy = null;
hatarget.destroy();
+ drm.unregisterListener(proxyFamilyName, this);
((StatelessContainer) container).getClusterFamilies().remove(proxyFamilyName);
}
@@ -121,8 +135,10 @@
return proxyConstructor.newInstance(args);
*/
String partitionName = ((StatelessContainer) container).getPartitionName();
- return constructProxy(new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null),
- wrapper, lbPolicy, partitionName));
+
+ proxy = constructProxy(new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null),
+ wrapper, lbPolicy, partitionName));
+ return proxy;
}
/*
catch (InstantiationException e)
@@ -153,4 +169,24 @@
return handle;
}
+
+ public synchronized void replicantsChanged (String key,
+ List newReplicants,
+ int newReplicantsViewId)
+ {
+ try
+ {
+ // Update the FamilyClusterInfo with the new targets
+ ArrayList targets = new ArrayList(newReplicants);
+ wrapper.get().updateClusterInfo(targets, newReplicantsViewId);
+
+ // Rebind the proxy as the old one has been serialized
+ if (proxy != null)
+ bindProxy(proxy);
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list