FileDocCategorySizeDatePackage
ServiceUnavailableClientInterceptor.javaAPI DocJBoss 4.2.14837Fri Jul 13 20:52:36 BST 2007org.jboss.ha.framework.test

ServiceUnavailableClientInterceptor

public class ServiceUnavailableClientInterceptor extends org.jboss.proxy.Interceptor
Used for testing clustering: mimics an exhausted set of targets. This interceptor should be placed between a RetryInterceptor and the InvokerInterceptor.
author
brian.stansberry@jboss.com.
version
$Id$

Fields Summary
private static final long
serialVersionUID
The serialVersionUID
private String
proxyFamilyName
Constructors Summary
public ServiceUnavailableClientInterceptor()

   
   // Static --------------------------------------------------------
   
   // Constructors --------------------------------------------------

     
   
   
Methods Summary
static java.lang.StringgetProxyFamilyName(org.jboss.invocation.Invocation invocation)

      InvocationContext ctx = invocation.invocationContext;
      JRMPInvokerProxyHA invoker = (JRMPInvokerProxyHA) ctx.getInvoker();
      
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      invoker.writeExternal(oos);
      oos.close();
      byte[] bytes = baos.toByteArray();
      
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      ObjectInputStream ois = new ObjectInputStream(bais);
      Object targets = ois.readObject();
      Object loadBalancePolicy = ois.readObject();
      String proxyFamilyName = (String) ois.readObject();
      ois.close();
      
      return proxyFamilyName;
   
public java.lang.Objectinvoke(org.jboss.invocation.Invocation mi)

      Object data = mi.getValue ("DO_FAIL_DURING_NEXT_CALL");
      
      if (data != null &&
            data instanceof java.lang.Boolean &&
            data.equals (java.lang.Boolean.TRUE))
      {
         
         // Clear the instruction
         mi.setValue ("DO_FAIL_DURING_NEXT_CALL", Boolean.FALSE, PayloadKey.AS_IS);
         
         if (proxyFamilyName == null)
         {
            proxyFamilyName = getProxyFamilyName(mi);
         }
         
         // Clear the targets to simulate exhausting them all
         FamilyClusterInfo info = ClusteringTargetsRepository.getFamilyClusterInfo(proxyFamilyName);
         ArrayList targets = info.getTargets();
         for (Iterator it = targets.iterator(); it.hasNext(); )
            info.removeDeadTarget(it.next());
         
         throw new ServiceUnavailableException("Service unavailable", 
                                               new Exception("Test"));
      } 

      return getNext().invoke(mi);