User: patriot1burke Date: 01/09/20 00:57:41 Modified: src/main/org/jboss/ha HARMITarget.java Added: src/main/org/jboss/ha HARMIServerImpl.java HARMIServer.java HARMIResponse.java HARMIClient.java Log: work in progress Revision Changes Path 1.3 +1 -5 jbossmx/src/main/org/jboss/ha/HARMITarget.java Index: HARMITarget.java =================================================================== RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/HARMITarget.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HARMITarget.java 2001/09/19 23:57:43 1.2 +++ HARMITarget.java 2001/09/20 07:57:41 1.3 @@ -22,7 +22,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a> * @author <a href="mailto:[EMAIL PROTECTED]">Bill Burke</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * * <p><b>Revisions:</b> * @@ -224,10 +224,6 @@ { // ignore System.out.println("Connection failure"); - } - else if (targetException instanceof RemoteException) - { - System.out.println("RemoteException called: " + targetException.getClass().getName()); } else { 1.1 jbossmx/src/main/org/jboss/ha/HARMIServerImpl.java Index: HARMIServerImpl.java =================================================================== package org.jboss.ha; import java.util.Vector; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Collection; import java.rmi.Remote; import java.rmi.server.RemoteStub; import java.rmi.server.UnicastRemoteObject; import java.io.Serializable; import java.rmi.RemoteException; import org.jboss.logging.Logger; import org.jboss.ejb.plugins.jrmp.interfaces.RemoteMethodInvocation; import java.rmi.MarshalledObject; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; public class HARMIServerImpl implements HARMIServer, DistributedReplicantManager.ReplicantListener { protected String replicantName; protected long lastSet = 0; protected ArrayList replicants; protected Object handler; protected HashMap invokerMap = new HashMap(); public HARMIServerImpl(HAPartition partition, String replicantName, Object handler) throws Exception { this.replicantName = replicantName; this.handler = handler; Method[] methods = handler.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { invokerMap.put(new Long(RemoteMethodInvocation.calculateHash(methods[i])), methods[i]); } RemoteStub stub = UnicastRemoteObject.exportObject(this); partition.getDistributedReplicantManager().registerListener(replicantName, this); partition.getDistributedReplicantManager().add(replicantName, stub); } public long getTag() { return lastSet; } public void replicantsChanged(String key, ArrayList newReplicants) { replicants = newReplicants; lastSet = System.currentTimeMillis(); } public HARMIResponse invoke(long tag, MarshalledObject mimo) throws Exception { RemoteMethodInvocation rmi = (RemoteMethodInvocation)mimo.get(); rmi.setMethodMap(invokerMap); Method method = rmi.getMethod(); try { HARMIResponse rsp = new HARMIResponse(); if (tag < lastSet) { rsp.newReplicants = replicants.toArray(); rsp.tag = lastSet; } rsp.response = method.invoke(handler, rmi.getArguments()); return rsp; } catch (IllegalAccessException iae) { throw iae; } catch (IllegalArgumentException iae) { throw iae; } catch (InvocationTargetException ite) { throw (Exception)ite.getTargetException(); } } } 1.1 jbossmx/src/main/org/jboss/ha/HARMIServer.java Index: HARMIServer.java =================================================================== package org.jboss.ha; import java.util.Vector; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Collection; import java.rmi.Remote; import java.rmi.server.RemoteStub; import java.rmi.server.UnicastRemoteObject; import java.io.Serializable; import java.rmi.RemoteException; import org.jboss.logging.Logger; import org.jboss.ejb.plugins.jrmp.interfaces.RemoteMethodInvocation; import java.rmi.MarshalledObject; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; public interface HARMIServer extends Remote { public HARMIResponse invoke(long tag, MarshalledObject mimo) throws Exception; } 1.1 jbossmx/src/main/org/jboss/ha/HARMIResponse.java Index: HARMIResponse.java =================================================================== package org.jboss.ha; public class HARMIResponse implements java.io.Serializable { public Object[] newReplicants = null; public long tag = 0; public Object response = null; } 1.1 jbossmx/src/main/org/jboss/ha/HARMIClient.java Index: HARMIClient.java =================================================================== /* * JBoss, the OpenSource J2EE WebOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha; import java.util.Vector; import java.util.ArrayList; import java.rmi.ConnectException; import java.rmi.ConnectIOException; import java.rmi.NoSuchObjectException; import java.rmi.UnknownHostException; import java.rmi.RemoteException; import java.rmi.ServerException; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import org.jboss.ejb.plugins.jrmp.interfaces.RemoteMethodInvocation; import java.rmi.MarshalledObject; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a> * @author <a href="mailto:[EMAIL PROTECTED]">Bill Burke</a> * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> * * <p><b>20010831 Bill Burke:</b> * <ul> * <li> First import of sources * </ul> */ public class HARMIClient implements java.io.Serializable, java.lang.reflect.InvocationHandler { protected Object[] targets = new Object[0]; protected LoadBalancePolicy loadBalancePolicy; protected long tag = 0; public HARMIClient(Object[] targets, LoadBalancePolicy policy) { this.targets = targets; this.loadBalancePolicy = policy; } public Object[] getTargets() { return targets; } public void setTargets(Object[] newTargets) { synchronized(targets) { targets = newTargets; } } public long getTag() { return tag; } public void setTag(long tag) { this.tag = tag; } public Object getRemoteTarget() { System.out.println("number of targets: " + targets.length); if (targets.length == 0) { return null; } synchronized (targets) { return loadBalancePolicy.chooseTarget(targets); } } public void remoteTargetHasFailed(Object target) { removeDeadTarget(target); } protected void removeDeadTarget (Object target) { //System.out.println("Size before : " + Integer.toString(targets.length)); if (targets != null) { synchronized (targets) { //System.out.println("removeDeadTarget has been called"); int length = targets.length; for (int i=0; i<length; ++i) { if (targets[i] == target) { Object[] copy = new Object[length - 1]; System.arraycopy(targets, 0, copy, 0, i); if ( (i+1) < length) { System.arraycopy(targets, i+1, copy, i, length - i - 1); } targets = copy; return; } } } } // nothing found } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { HARMIServer target = (HARMIServer)getRemoteTarget(); while (target != null) { try { RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, method, args); MarshalledObject mo = new MarshalledObject(rmi); // Is this step actually necessary? Can I just do method.invoke(target, args); ? HARMIResponse rsp = target.invoke(tag, mo); if (rsp.newReplicants != null) { System.out.println("new set of replicants"); setTargets(rsp.newReplicants); setTag(rsp.tag); } return rsp.response; } catch (ConnectException ce) { } catch (ConnectIOException cioe) { } catch (NoSuchObjectException nsoe) { } catch (UnknownHostException uhe) { } // If we reach here, this means that we must fail-over remoteTargetHasFailed(target); target = (HARMIServer)getRemoteTarget(); } // if we get here this means list was exhausted throw new RemoteException("Service unavailable."); } } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development