1 22 package org.jboss.invocation.http.server; 23 24 import java.util.ArrayList ; 25 import javax.management.JMException ; 26 import javax.management.MBeanServer ; 27 import javax.management.MBeanException ; 28 import javax.management.ObjectName ; 29 import javax.management.ReflectionException ; 30 import javax.management.MBeanInfo ; 31 import javax.management.MBeanAttributeInfo ; 32 import javax.management.MBeanConstructorInfo ; 33 import javax.management.MBeanOperationInfo ; 34 import javax.management.MBeanNotificationInfo ; 35 import javax.management.MBeanParameterInfo ; 36 37 import org.jboss.ha.framework.interfaces.HARMIResponse; 38 import org.jboss.ha.framework.interfaces.GenericClusteringException; 39 import org.jboss.ha.framework.server.HATarget; 40 import org.jboss.invocation.Invocation; 41 import org.jboss.logging.Logger; 42 import org.jboss.mx.util.JMXExceptionDecoder; 43 import org.jboss.mx.util.DynamicMBeanSupport; 44 45 46 53 public class HAInvokerWrapper extends DynamicMBeanSupport 54 { 55 private static Logger log = Logger.getLogger(HAInvokerWrapper.class); 56 private MBeanServer mbeanServer; 57 private MBeanInfo info; 58 59 private ObjectName targetName; 60 private HATarget target; 61 62 public HAInvokerWrapper(MBeanServer mbeanServer, ObjectName targetName, HATarget target) 63 { 64 this.mbeanServer = mbeanServer; 65 this.targetName = targetName; 66 this.target = target; 67 MBeanAttributeInfo [] attrInfo = null; 68 MBeanConstructorInfo [] ctorInfo = null; 69 MBeanParameterInfo [] sig = { 70 new MBeanParameterInfo ("invocation", Invocation.class.getName(), 71 "The invocation content information") 72 }; 73 MBeanOperationInfo [] opInfo = { 74 new MBeanOperationInfo ("invoke", "The detached invoker entry point", 75 sig, "java.lang.Object", MBeanOperationInfo.ACTION) 76 }; 77 MBeanNotificationInfo [] eventInfo = null; 78 this.info = new MBeanInfo (getClass().getName(), 79 "A wrapper inovker that delegates to the target invoker", 80 attrInfo, 81 ctorInfo, 82 opInfo, 83 eventInfo); 84 } 85 86 96 public Object invoke(String actionName, Object [] params, String [] signature) 97 throws MBeanException , ReflectionException 98 { 99 if( params == null || params.length != 1 || 100 (params[0] instanceof Invocation) == false ) 101 { 102 NoSuchMethodException e = new NoSuchMethodException (actionName); 103 throw new ReflectionException (e, actionName); 104 } 105 106 Invocation invocation = (Invocation) params[0]; 107 try 108 { 109 Object value = invoke(invocation); 110 return value; 111 } 112 catch(Exception e) 113 { 114 throw new ReflectionException (e, "Invoke failure"); 115 } 116 } 117 118 124 public Object invoke(Invocation invocation) 125 throws Exception 126 { 127 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 128 try 129 { 130 Object [] args = {invocation}; 132 String [] sig = {"org.jboss.invocation.Invocation"}; 133 Object rtn = mbeanServer.invoke(targetName, "invoke", args, sig); 134 135 Long clientViewId = (Long ) invocation.getValue("CLUSTER_VIEW_ID"); 137 HARMIResponse rsp = new HARMIResponse(); 138 if (clientViewId.longValue() != target.getCurrentViewId()) 139 { 140 rsp.newReplicants = new ArrayList (target.getReplicants()); 141 rsp.currentViewId = target.getCurrentViewId(); 142 } 143 rsp.response = rtn; 144 145 return rsp; 147 } 148 catch (Exception e) 149 { 150 e = (Exception ) JMXExceptionDecoder.decode(e); 152 if( e instanceof JMException ) 154 e = new GenericClusteringException (GenericClusteringException.COMPLETED_NO, e.getMessage()); 155 156 if( log.isTraceEnabled() ) 158 log.trace("operation failed", e); 159 throw e; 160 } 161 finally 162 { 163 Thread.currentThread().setContextClassLoader(oldCl); 164 } 165 } 166 167 public MBeanInfo getMBeanInfo() 168 { 169 return info; 170 } 171 } 172 | Popular Tags |