User: patriot1burke Date: 02/02/15 11:55:18 Modified: src/main/org/jboss/ha/framework/server HARMIServerImpl.java HATarget.java Log: refactored Revision Changes Path 1.13 +20 -69 jbossmx/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java Index: HARMIServerImpl.java =================================================================== RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- HARMIServerImpl.java 5 Jan 2002 01:12:46 -0000 1.12 +++ HARMIServerImpl.java 15 Feb 2002 19:55:18 -0000 1.13 @@ -33,7 +33,7 @@ * * @author [EMAIL PROTECTED] * @author [EMAIL PROTECTED] - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * * <p><b>Revisions:</b><br> * <p><b>2001/11/09: Sacha Labourey</b> @@ -41,25 +41,27 @@ * <li>Added possibility to replace underlying HAPartition without impacting already living HARMIClient(s)</li> * <li> => needed to changed the condition as to when to give a new view to the client. * </ol> + * <p><b>2002/02/15: Bill Burke</b> + * <ol> + * <li>Replicant management delegated to HATargety. This class almost looks the same as JRMPInvokerHA, but is a tiny bit + * more lightweight. + * </ol> */ -public class HARMIServerImpl implements ReplicantListener, HARMIServer +public class HARMIServerImpl implements HARMIServer { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- - protected String replicantName; - protected ArrayList replicants = new ArrayList(); protected Object handler; protected Map invokerMap = new HashMap(); - protected HAPartition partition = null; protected org.jboss.logging.Logger log; protected RemoteStub rmistub; protected Object stub; protected String key; protected Class intf; - protected long clusterViewId = -1; + protected HATarget target; // Static -------------------------------------------------------- @@ -74,21 +76,20 @@ RMIServerSocketFactory ssf) throws Exception { - this.replicantName = replicantName; this.handler = handler; this.log = org.jboss.logging.Logger.getLogger(this.getClass()); this.intf = intf; + this.key = partition.getPartitionName() + "/" + replicantName; Method[] methods = handler.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { - Long key = new Long(MarshalledInvocation.calculateHash(methods[i])); - invokerMap.put(key, methods[i]); + Long methodkey = new Long(MarshalledInvocation.calculateHash(methods[i])); + invokerMap.put(methodkey, methods[i]); } this.rmistub = (RemoteStub)UnicastRemoteObject.exportObject(this, port, csf, ssf);// casting is necessary because interface has changed in JDK>=1.2 + this.target = new HATarget(partition, replicantName, rmistub); - updateHAPartition(partition); - HARMIServer.rmiServers.put(key, this); } @@ -116,7 +117,7 @@ */ public Object createHAStub(LoadBalancePolicy policy) { - HARMIClient client = new HARMIClient(replicants, policy, key, handler); + HARMIClient client = new HARMIClient(target.getReplicants(), policy, key, handler); return Proxy.newProxyInstance( intf.getClassLoader(), new Class[] @@ -128,8 +129,7 @@ { try { - this.cleanExistenceInCurrentHAPartition(); - + target.destroy(); HARMIServer.rmiServers.remove(key); UnicastRemoteObject.unexportObject(this, true); @@ -149,10 +149,10 @@ try { HARMIResponse rsp = new HARMIResponse(); - if (clientViewId != this.clusterViewId) + if (clientViewId != target.getCurrentViewId()) { - rsp.newReplicants = new ArrayList(replicants); - rsp.currentViewId = clusterViewId; + rsp.newReplicants = new ArrayList(target.getReplicants()); + rsp.currentViewId = target.getCurrentViewId(); } rsp.response = method.invoke(handler, mi.getArguments()); @@ -171,66 +171,17 @@ throw (Exception)ite.getTargetException(); } } - + public List getReplicants() throws Exception { - return replicants; + return target.getReplicants(); } - + public Object getLocal() throws Exception { return handler; } - public void updateHAPartition(HAPartition partition) throws Exception - { - cleanExistenceInCurrentHAPartition(); - - this.partition = partition; - - this.key = partition.getPartitionName() + "/" + this.replicantName; - partition.getDistributedReplicantManager().registerListener(this.replicantName, this); - partition.getDistributedReplicantManager().add(this.replicantName, rmistub); - - this.clusterViewId = partition.getCurrentViewId(); - } - - // DistributedReplicantManager.ReplicantListener implementation ---------------------------------------------- - - public void replicantsChanged(String key, ArrayList newReplicants) - { - if (log.isDebugEnabled()) - log.debug("replicantsChanged '" + key + "' to " + newReplicants.size()); - synchronized(replicants) - { - // client has reference to replicants so it will automatically get - // updated - replicants.clear(); - replicants.addAll(newReplicants); - } - this.clusterViewId = partition.getCurrentViewId(); - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - protected void cleanExistenceInCurrentHAPartition() - { - if (this.partition != null) - { - try - { - this.partition.getDistributedReplicantManager().unregisterListener(this.replicantName, this); - this.partition.getDistributedReplicantManager().remove (this.replicantName); - } - catch (Exception e) - { - e.printStackTrace (); - } - } - } - // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- 1.2 +5 -3 jbossmx/src/main/org/jboss/ha/framework/server/HATarget.java Index: HATarget.java =================================================================== RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/HATarget.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HATarget.java 14 Jan 2002 01:56:29 -0000 1.1 +++ HATarget.java 15 Feb 2002 19:55:18 -0000 1.2 @@ -13,10 +13,12 @@ import org.jboss.ha.framework.interfaces.HAPartition; import java.io.Serializable; /** - * This class is a holder of replicants. + * This class is a holder and manager of replicants. + * It manages lists of replicated objects and changes the list as the HAPartition + * notifies it. * * @author [EMAIL PROTECTED] - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * * <p><b>Revisions:</b><br> * <p><b>2002/01/13: Bill Burke</b> @@ -71,7 +73,7 @@ } } - public ArrayList getReplicants() throws Exception + public ArrayList getReplicants() { return replicants; }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development