User: patriot1burke
  Date: 02/01/13 17:58:30

  Modified:    src/main/org/jboss/invocation/jrmp/server JRMPInvokerHA.java
  Log:
  No longer attached to a partition.  ProxyFactoryHA registers beans within it.
  It manages Replicants by accessing the registered beans HATargets.
  
  Revision  Changes    Path
  1.4       +64 -80    
jbossmx/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java
  
  Index: JRMPInvokerHA.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JRMPInvokerHA.java        2002/01/08 23:56:45     1.3
  +++ JRMPInvokerHA.java        2002/01/14 01:58:30     1.4
  @@ -7,6 +7,7 @@
   package org.jboss.invocation.jrmp.server;
   
   import java.rmi.ServerException;
  +import java.rmi.MarshalledObject;
   
   import javax.naming.InitialContext;
   import javax.management.ObjectName;
  @@ -18,41 +19,38 @@
   import javax.management.AttributeChangeNotification;
   
   import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxyHA;
  +import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy;
   import org.jboss.invocation.Invocation;
  +import org.jboss.invocation.MarshalledInvocation;
   import org.jboss.invocation.Invoker;
   import org.jboss.logging.Logger;
   import org.jboss.system.Registry;
   
  -import org.jboss.ha.framework.server.HARMIServerImpl;
  +import org.jboss.ha.framework.interfaces.HARMIResponse;
  +import org.jboss.ha.framework.server.HATarget;
   import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
  -import org.jboss.ha.framework.interfaces.HAPartition;
   
  -import java.util.HashSet;
  +import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.StringTokenizer;
   
  +
   /**
    *  The JRMPInvokerHA is an HA-RMI implementation that can generate Invocations 
from RMI/JRMP 
    * into the JMX base
    *
    *  @author <a href="mailto:[EMAIL PROTECTED]>Bill Burke</a>
    *
  - *  @version $Revision: 1.3 $
  + *  @version $Revision: 1.4 $
    */
   
   public class JRMPInvokerHA
      extends JRMPInvoker
  -   implements JRMPInvokerHAMBean
   {
      // Constants -----------------------------------------------------
  -   protected static final String DEFAULT_LB_POLICIES = 
"RoundRobin=org.jboss.ha.framework.interfaces.RoundRobin;FirstAvailable=org.jboss.ha.framework.interfaces.FirstAvailable";
      
      // Attributes ----------------------------------------------------
  -   protected String partitionName = "DefaultPartition";
  -   protected String loadBalancePolicies = DEFAULT_LB_POLICIES;
  -   protected HashSet policies = new HashSet();
  -   protected HAPartition partition = null;
  -   protected HARMIServerImpl rmiserver = null;
  +   protected HashMap beanMap = new HashMap();
      
      // Static --------------------------------------------------------
      
  @@ -61,22 +59,7 @@
      // Public --------------------------------------------------------
      
      // MBean parameters
  -   public String getPartitionName() { return partitionName; }
  -
  -   public void setPartitionName(String pname) 
  -   { 
  -      if (getState() == STARTED) return; // can't set partition name dynamically
  -      partitionName = pname;
  -   }
   
  -   public String getLoadBalancePolicies() { return loadBalancePolicies; }
  -
  -   public void setLoadBalancePolicies(String lb) 
  -   {
  -      if (getState() == STARTED) return; // can't set policies dynamically
  -      loadBalancePolicies = lb + ";" + DEFAULT_LB_POLICIES;
  -   }
  -
      public String getName() {return "JRMPInvokerHA";}
      
      // Service implementation -------------------------------
  @@ -103,8 +86,8 @@
   
         try
         {
  -         // Export CI
  -         exportCI();
  +      exportCI();
  +      Registry.bind(serviceName, this);
         }
         catch (Exception e)
         {
  @@ -130,7 +113,7 @@
            unexportCI();
         }
         catch (Throwable e)
  -      {
  +      {  
            state = FAILED;
            log.error("Failed", e);
            return;
  @@ -143,63 +126,64 @@
      {
      }
      
  -   // Package protected ---------------------------------------------
  -   
  -   // Protected -----------------------------------------------------
  -   
  -   /**
  -    * This method will parse loadBalancePolicies and registry an invoker in the 
Registry
  -    * for each load-balance policy.  This is how we allow pluggable load-balance 
policies.
  -    */
  -   protected void registerHAProxies() throws Exception
  -   {
  -      ClassLoader cl = Thread.currentThread().getContextClassLoader();
  -      StringTokenizer tokenizer = new StringTokenizer(loadBalancePolicies, ";");
  -      while (tokenizer.hasMoreTokens())
  -      {
  -      String token = tokenizer.nextToken().trim();
  -      StringTokenizer nv = new StringTokenizer(token, "=");
  -      if (!nv.hasMoreTokens()) continue;
  -      String lbname = nv.nextToken();
  -      if (!nv.hasMoreTokens()) continue;
  -      String className = nv.nextToken();
  -      Class clazz = cl.loadClass(className);
  -      String proxyName = serviceName.toString() + ",load-balance=" + lbname;
  -      Invoker stub = 
(Invoker)rmiserver.createHAStub((LoadBalancePolicy)(clazz.newInstance()));
  -      JRMPInvokerProxyHA proxy = new JRMPInvokerProxyHA(stub);
  -      Registry.bind(new ObjectName(proxyName), proxy);
  -      policies.add(proxyName);
  -      log.info("Bounded HA Invoker: " + proxyName);
  -      }
  -
  -   }
  -
  -   protected void unregisterHAProxies() throws Exception
  +   public void registerBean(String beanName, HATarget target) throws Exception
      {
  -      log.info("unbind Registry");
  -      Iterator it = policies.iterator();
  -      while (it.hasNext())
  -      {
  -      String proxyName = (String)it.next();
  -      Registry.unbind(proxyName);
  -      }
  +      beanMap.put(beanName, target);
      }
  -   protected void exportCI() throws Exception
  +   
  +   public JRMPInvokerProxy createProxy(String beanName, LoadBalancePolicy policy) 
throws Exception
      {
  -      partition = (HAPartition)new InitialContext().lookup("/HAPartition/" + 
partitionName);
  -      this.rmiserver = new HARMIServerImpl(partition, serviceName.toString(),
  -                                        Invoker.class, 
  -                                        this, rmiPort, this.clientSocketFactory, 
  -                                        this.serverSocketFactory);
  -      registerHAProxies();
  +      HATarget target = (HATarget)beanMap.get(beanName);
  +      return new JRMPInvokerProxyHA(target.getReplicants(), policy);
      }
      
  -   protected void unexportCI() throws Exception
  +   public void unregisterBean(String beanName) throws Exception
      {
  -      unregisterHAProxies();
  -      log.info("destroy ha rmiserver");
  -      this.rmiserver.destroy();         
  +      beanMap.remove(beanName);
      }
  +   
  +   /**
  +   *  Invoke a Remote interface method.
  +   */
  +   public Object invoke(Invocation invocation)
  +   throws Exception
  +   {     
  +      
  +      ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  +      
  +      try
  +      {
  +         // Deserialize the transaction if it is there  
  +         invocation.setTransaction(importTPC(((MarshalledInvocation) 
invocation).getTransactionPropagationContext()));
  +               
  +         // Extract the ObjectName, the rest is still marshalled
  +         ObjectName mbean = new ObjectName((String) invocation.getContainer());
  +      long clientViewId = 
((Long)invocation.getValue("CLUSTER_VIEW_ID")).longValue();
  +
  +         
  +         // The cl on the thread should be set in another interceptor
  +         Object rtn = server.invoke(mbean, invocation.getType(),  new Object[] 
{invocation}, new String[] {"java.lang.Object"}); 
  +      HARMIResponse rsp = new HARMIResponse();
  +      HATarget target = (HATarget)beanMap.get((String)invocation.getContainer());
  +      if (clientViewId != target.getCurrentViewId())
  +      {
  +         rsp.newReplicants = new ArrayList(target.getReplicants());
  +         rsp.currentViewId = target.getCurrentViewId();
  +      }
  +      rsp.response = rtn;
  +      return new MarshalledObject(rsp);
  +      }
  +      catch (MBeanException mbe) { throw mbe.getTargetException(); }
  +      catch (Exception e) {e.printStackTrace(); throw e;}
  +      finally
  +      {
  +         Thread.currentThread().setContextClassLoader(oldCl);
  +      }      
  +   }
  +   
  +   // Package protected ---------------------------------------------
  +   
  +   // Protected -----------------------------------------------------
      
      // Inner classes -------------------------------------------------
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to