FileDocCategorySizeDatePackage
JRMPInvokerHA.javaAPI DocJBoss 4.2.18012Fri Jul 13 20:52:40 BST 2007org.jboss.invocation.jrmp.server

JRMPInvokerHA

public class JRMPInvokerHA extends JRMPInvoker implements org.jboss.invocation.InvokerHA
The JRMPInvokerHA is an HA-RMI implementation that can generate Invocations from RMI/JRMP into the JMX base
author
Sacha Labourey.
author
Scott.Stark@jboss.org
version
$Revision: 57188 $

Fields Summary
protected HashMap
beanMap
Constructors Summary
public JRMPInvokerHA()
Explicit no-args constructor.


          
    
   
      super();
   
Methods Summary
public org.jboss.invocation.InvokercreateProxy(javax.management.ObjectName beanName, org.jboss.ha.framework.interfaces.LoadBalancePolicy policy, java.lang.String proxyFamilyName)

      Integer hash = new Integer(beanName.hashCode());
      HATarget target = (HATarget) beanMap.get(hash);
      if (target == null)
      {
         throw new IllegalStateException("The bean hashCode not found");
      }

      String familyName = proxyFamilyName;
      if (familyName == null)
         familyName= target.getAssociatedPartition().getPartitionName() + "/" + beanName;

      JRMPInvokerProxyHA proxy = new JRMPInvokerProxyHA(target.getReplicants(), 
                                                        policy, 
                                                        familyName, 
                                                        target.getCurrentViewId ());
      return proxy;
   
public java.lang.Objectinvoke(org.jboss.invocation.Invocation invocation)
Invoke a Remote interface method.

      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 = (ObjectName) Registry.lookup(invocation.getObjectName());
         long clientViewId = ((Long)invocation.getValue("CLUSTER_VIEW_ID")).longValue();

         HATarget target = (HATarget)beanMap.get(invocation.getObjectName());
         if (target == null) 
         {
            // We could throw IllegalStateException but we have a race condition that could occur:
            // when we undeploy a bean, the cluster takes some time to converge
            // and to recalculate a new viewId and list of replicant for each HATarget.
            // Consequently, a client could own an up-to-date list of the replicants
            // (before the cluster has converged) and try to perform an invocation
            // on this node where the HATarget no more exist, thus receiving a
            // wrong exception and no failover is performed with an IllegalStateException
            //
            throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, 
                                                 "target is not/no more registered on this node");            
         }
         
         if (!target.invocationsAllowed ())
            throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, 
                                        "invocations are currently not allowed on this target");            

         // The cl on the thread should be set in another interceptor
         Object rtn = support.getServer().invoke(mbean,
                                                 "invoke",
                                                 new Object[] { invocation },
                                                 Invocation.INVOKE_SIGNATURE);
         
         HARMIResponse rsp = new HARMIResponse();

         if (clientViewId != target.getCurrentViewId())
         {
            rsp.newReplicants = new ArrayList(target.getReplicants());
            rsp.currentViewId = target.getCurrentViewId();
         }
         rsp.response = rtn;
         
         return new MarshalledObject(rsp);
      }
      catch (InstanceNotFoundException e)
      {
         throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, e);
      }
      catch (ReflectionException e)
      {
         throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, e);
      }
      catch (Exception e)
      {
         org.jboss.mx.util.JMXExceptionDecoder.rethrow(e);

         // the compiler does not know an exception is thrown by the above
         throw new org.jboss.util.UnreachableStatementException();
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldCl);
      }      
   
public voidregisterBean(javax.management.ObjectName beanName, org.jboss.ha.framework.server.HATarget target)

      Integer hash = new Integer(beanName.hashCode());
      log.debug("registerBean: "+beanName);
      
      if (beanMap.containsKey(hash))
      {
         // FIXME [oleg] In theory this is possible!
         throw new IllegalStateException("Trying to register bean with the existing hashCode");
      }
      beanMap.put(hash, target);
   
protected voidstartService()

      loadCustomSocketFactories();

      if (log.isDebugEnabled())
      {
         log.debug("RMI Port='" +  (rmiPort == ANONYMOUS_PORT ?
            "Anonymous" : Integer.toString(rmiPort)+"'"));
         log.debug("Client SocketFactory='" + (clientSocketFactory == null ?
            "Default" : clientSocketFactory.toString()+"'"));
         log.debug("Server SocketFactory='" + (serverSocketFactory == null ?
            "Default" : serverSocketFactory.toString()+"'"));
         log.debug("Server SocketAddr='" + (serverAddress == null ?
            "Default" : serverAddress+"'"));
         log.debug("SecurityDomain='" + (sslDomain == null ?
            "None" : sslDomain+"'"));
      }

      exportCI();
      Registry.bind(support.getServiceName(), this);
   
protected voidstopService()

      unexportCI();
   
public voidunregisterBean(javax.management.ObjectName beanName)

      Integer hash = new Integer(beanName.hashCode());
      beanMap.remove(hash);