FileDocCategorySizeDatePackage
HttpInvokerHA.javaAPI DocJBoss 4.2.16131Fri Jul 13 20:52:40 BST 2007org.jboss.invocation.http.server

HttpInvokerHA

public class HttpInvokerHA extends HttpInvoker implements org.jboss.invocation.InvokerHA
An extension of the HttpInvoker and supports clustering of HTTP invokers.
author
Omit source code)

');
Fields Summary
protected HashMap
targetMap
Constructors Summary
Methods Summary
public org.jboss.invocation.InvokercreateProxy(javax.management.ObjectName targetName, org.jboss.ha.framework.interfaces.LoadBalancePolicy policy, java.lang.String proxyFamilyName)

      Integer hash = new Integer(targetName.hashCode());
      HATarget target = (HATarget) targetMap.get(hash);
      if (target == null)
      {
         throw new IllegalStateException("The targetName("+targetName
            + "), hashCode("+hash+") not found");
      }
      Invoker proxy = new HttpInvokerProxyHA(target.getReplicants(), target.getCurrentViewId (),
                                             policy, proxyFamilyName);
      return proxy;
   
protected voiddestroyService()

      // Export references to the bean
      Registry.unbind(serviceName);
   
public java.io.SerializablegetStub()

      return super.getInvokerURL();
   
public java.lang.Objectinvoke(org.jboss.invocation.Invocation invocation)
Invoke a Remote interface method.

      ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
      try
      {
         Integer nameHash = (Integer) invocation.getObjectName();
         ObjectName mbean = (ObjectName) Registry.lookup(nameHash);

         // The cl on the thread should be set in another interceptor
         Object[] args = {invocation};
         String[] sig = {"org.jboss.invocation.Invocation"};
         Object rtn = super.getServer().invoke(mbean, 
            "invoke", args, sig);

         // Update the targets list if the client view is out of date
         Long clientViewId = (Long) invocation.getValue("CLUSTER_VIEW_ID");
         HARMIResponse rsp = new HARMIResponse();
         HATarget target = (HATarget) targetMap.get(nameHash);
         if (target == null)
         {
            throw new IllegalStateException("The name for hashCode("+nameHash+") was not found");
         }
         if (clientViewId.longValue() != target.getCurrentViewId())
         {
            rsp.newReplicants = new ArrayList(target.getReplicants());
            rsp.currentViewId = target.getCurrentViewId();
         }
         rsp.response = rtn;

         // Return the raw object and let the http layer marshall it
         return rsp;
      }
      catch (Exception e)
      {
         // Unwrap any JMX exceptions
         e = (Exception) JMXExceptionDecoder.decode(e);
         // Don't send JMX exception back to client to avoid needing jmx
         if( e instanceof JMException )
            e = new GenericClusteringException (GenericClusteringException.COMPLETED_NO, e.getMessage());

         // Only log errors if trace is enabled
         if( log.isTraceEnabled() )
            log.trace("operation failed", e);
         throw e;
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldCl);
      }
   
public voidregisterBean(javax.management.ObjectName targetName, org.jboss.ha.framework.server.HATarget target)

      Integer hash = new Integer(targetName.hashCode());
      log.debug("Registered targetName("+targetName+"), hash="+hash
         + ", target="+target);
      if (targetMap.containsKey(hash))
      {
         throw new IllegalStateException("Duplicate targetName("+targetName
            + ") hashCode: "+hash);
      }
      targetMap.put(hash, target);
   
protected voidstartService()


   // Public --------------------------------------------------------

     
       
   
      // Export the Invoker interface
      ObjectName name = super.getServiceName();
      Registry.bind(name, this);
      // Make sure the invoker URL is valid
      super.checkInvokerURL();
      log.debug("Bound HttpHA invoker for JMX node");
   
protected voidstopService()

      // Unxport the Invoker interface
      ObjectName name = super.getServiceName();
      Registry.unbind(name);
      log.debug("Unbound HttpHA invoker for JMX node");
   
public voidunregisterBean(javax.management.ObjectName targetName)

      Integer hash = new Integer(targetName.hashCode());
      targetMap.remove(hash);
      log.debug("Unregistered targetName("+targetName+"), hash="+hash);