1 22 package org.jboss.invocation.unified.server; 23 24 import java.rmi.MarshalledObject ; 25 import javax.management.MBeanServer ; 26 import javax.management.ObjectName ; 27 import org.jboss.invocation.Invocation; 28 import org.jboss.invocation.unified.interfaces.UnifiedInvokerProxy; 29 import org.jboss.mx.util.JMXExceptionDecoder; 30 import org.jboss.remoting.InvocationRequest; 31 import org.jboss.remoting.InvokerLocator; 32 import org.jboss.remoting.ServerInvocationHandler; 33 import org.jboss.remoting.ServerInvoker; 34 import org.jboss.remoting.callback.InvokerCallbackHandler; 35 import org.jboss.remoting.transport.ConnectorMBean; 36 import org.jboss.system.Registry; 37 import org.jboss.system.ServiceMBeanSupport; 38 39 46 public class UnifiedInvoker extends ServiceMBeanSupport implements ServerInvocationHandler, UnifiedInvokerMBean 47 { 48 private ConnectorMBean connector; 49 private ServerInvoker serverInvoker; 50 51 private MBeanServer mbServer; 52 53 private boolean strictRMIException = false; 54 55 private UnifiedInvokerProxy proxy; 56 57 private String subsystem = "invoker"; 58 59 67 public void setStrictRMIException(boolean isStrict) 68 { 69 this.strictRMIException = isStrict; 70 } 71 72 80 public boolean getStrictRMIException() 81 { 82 return strictRMIException; 83 } 84 85 89 public String getSubSystem() 90 { 91 return subsystem; 92 } 93 94 public void setSubSystem(String subsystem) 95 { 96 this.subsystem = subsystem; 97 } 98 99 104 public void setConnector(ConnectorMBean connector) 105 { 106 this.connector = connector; 107 } 108 109 protected void createService() throws Exception 110 { 111 if(connector != null) 112 { 113 try 114 { 115 connector.addInvocationHandler(getSubSystem(), this); 116 } 117 catch(Exception e) 118 { 119 log.error("Error adding unified invoker as handler upon connector being set.", e); 120 } 121 } 122 } 123 124 130 protected void startService() throws Exception 131 { 132 log.debug("Starting unified invoker service."); 133 134 InvokerLocator locator = null; 135 if(serverInvoker != null) 136 { 137 locator = serverInvoker.getLocator(); 138 if(!serverInvoker.isStarted()) 139 { 140 serverInvoker.start(); 141 } 142 } 143 else if(connector != null) 144 { 145 locator = connector.getLocator(); 146 } 147 else 148 { 149 155 log.error("Error referencing either remoting connector or server invoker to be used. " + 156 "Please check configuration to make sure proper dependancies are set."); 157 throw new RuntimeException ("Error getting locator because server invoker is null."); 158 } 159 160 proxy = new UnifiedInvokerProxy(locator, strictRMIException); 161 162 jmxBind(); 163 164 } 165 166 protected void jmxBind() 167 { 168 Registry.bind(getServiceName(), proxy); 169 } 170 171 176 public void stopService() throws Exception 177 { 178 if(serverInvoker != null) 179 { 180 serverInvoker.stop(); 181 } 182 } 183 184 189 public String getName() 190 { 191 return "Unified-Invoker"; 192 } 193 194 199 public String getInvokerLocator() 200 { 201 if(serverInvoker != null) 202 { 203 return serverInvoker.getLocator().getLocatorURI(); 204 } 205 else 206 { 207 return null; 208 } 209 } 210 211 219 public Object invoke(InvocationRequest invocationReq) throws Throwable 220 { 221 Invocation invocation = (Invocation) invocationReq.getParameter(); 222 Thread currentThread = Thread.currentThread(); 223 ClassLoader oldCl = currentThread.getContextClassLoader(); 224 ObjectName mbean = null; 225 try 226 { 227 mbean = (ObjectName ) Registry.lookup(invocation.getObjectName()); 228 229 Object obj = getServer().invoke(mbean, 231 "invoke", 232 new Object []{invocation}, 233 Invocation.INVOKE_SIGNATURE); 234 return new MarshalledObject (obj); 235 } 236 catch(Exception e) 237 { 238 Throwable th = JMXExceptionDecoder.decode(e); 239 if(log.isTraceEnabled()) 240 { 241 log.trace("Failed to invoke on mbean: " + mbean, th); 242 } 243 244 if(th instanceof Exception ) 245 { 246 e = (Exception ) th; 247 } 248 249 throw e; 250 } 251 finally 252 { 253 currentThread.setContextClassLoader(oldCl); 254 Thread.interrupted(); } 256 257 } 258 259 264 public void setMBeanServer(MBeanServer server) 265 { 266 mbServer = server; 267 } 268 269 public MBeanServer getServer() 270 { 271 return mbServer; 272 } 273 274 279 public void setInvoker(ServerInvoker invoker) 280 { 281 286 serverInvoker = invoker; 287 } 288 289 protected ServerInvoker getInvoker() 290 { 291 return serverInvoker; 292 } 293 294 301 public void addListener(InvokerCallbackHandler callbackHandler) 302 { 303 } 305 306 313 public void removeListener(InvokerCallbackHandler callbackHandler) 314 { 315 } 317 318 } | Popular Tags |