User: slaboure
Date: 01/09/20 16:29:28
Modified: src/main/org/jboss/ha HARMIServerImpl.java
Log:
Tightend integration of HANamingService with the new HARMIServerImpl.
Revision Changes Path
1.2 +109 -84 jbossmx/src/main/org/jboss/ha/HARMIServerImpl.java
Index: HARMIServerImpl.java
===================================================================
RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/HARMIServerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HARMIServerImpl.java 2001/09/20 07:57:41 1.1
+++ HARMIServerImpl.java 2001/09/20 23:29:27 1.2
@@ -1,84 +1,109 @@
-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();
- }
- }
-}
-
-
+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 ();
+ protected HAPartition partition = null;
+ protected RemoteStub myStub = null;
+
+ public HARMIServerImpl (HAPartition partition, String replicantName, Object
handler) throws Exception
+ {
+ this.replicantName = replicantName;
+ this.partition = partition;
+ 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]);
+
+ this.myStub = UnicastRemoteObject.exportObject (this);
+
+ partition.getDistributedReplicantManager ().registerListener (replicantName,
this);
+ partition.getDistributedReplicantManager ().add (replicantName, this.myStub);
+ }
+
+ public void destroy ()
+ {
+ try
+ {
+ this.partition.getDistributedReplicantManager ().unregisterListener
(this.replicantName, this);
+ this.partition.getDistributedReplicantManager ().remove
(this.replicantName);
+
+ UnicastRemoteObject.unexportObject (this, true);
+ } catch (Exception e)
+ {e.printStackTrace ();}
+ }
+
+ public RemoteStub getStub ()
+ {
+ return this.myStub;
+ }
+
+ 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 ();
+ }
+ }
+}
\ No newline at end of file
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development