1 2 9 10 package org.jboss.remoting; 11 12 import org.jboss.remoting.transport.Connector; 13 14 import javax.management.MBeanRegistration ; 15 import javax.management.MBeanServer ; 16 import javax.management.ObjectName ; 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 22 23 36 public class ServerInterceptorChain 37 implements MBeanRegistration , ServerInvocationHandler 38 { 39 40 private MBeanServer server; 41 42 private Connector connector; 43 private ObjectName connectorName; 44 private String subsystem; 45 private List interceptorNames; 46 private List interceptors; 47 48 public ServerInterceptorChain() 49 { 50 51 } 53 54 59 public Connector getConnector() 60 { 61 return connector; 62 } 63 64 69 public void setConnector(Connector newConnector) 70 { 71 this.connector = newConnector; 72 } 73 74 75 83 public ObjectName getConnectorName() 84 { 85 return connectorName; 86 } 87 88 94 public void setConnectorName(ObjectName newConnectorName) 95 { 96 this.connectorName = newConnectorName; 97 } 98 99 100 107 public String getSubsystem() 108 { 109 return subsystem; 110 } 111 112 118 public void setSubsystem(String newSubsystem) 119 { 120 this.subsystem = newSubsystem; 121 } 122 123 124 129 public List getInterceptors() 130 { 131 return interceptors; 132 } 133 134 139 public void setInterceptors(List newInterceptors) 140 { 141 this.interceptors = newInterceptors; 142 } 143 144 145 152 public List getInterceptorNames() 153 { 154 return interceptorNames; 155 } 156 157 163 public void setInterceptorNames(List newInterceptorNames) 164 { 165 this.interceptorNames = newInterceptorNames; 166 } 167 168 169 171 179 public ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception 180 { 181 this.server = server; 182 return objectName; 183 } 184 185 189 public void postRegister(Boolean success) 190 { 191 192 } 193 194 199 public void preDeregister() throws Exception 200 { 201 202 } 203 204 208 public void postDeregister() 209 { 210 211 } 212 213 221 public void start() throws Exception 222 { 223 List interceptors = new ArrayList (); 224 for (Iterator i = interceptorNames.iterator(); i.hasNext(); ) 225 { 226 ObjectName iname = (ObjectName )i.next(); 227 ServerInterceptor si = (ServerInterceptor)server.getAttribute(iname, "Instance"); 228 interceptors.add(si); 229 } this.interceptors = interceptors; 231 232 if (connector != null) 234 { 235 connector.addInvocationHandler(subsystem, this); 236 } else 238 { 239 server.invoke(connectorName, 240 "addInvocationHandler", 241 new Object [] {subsystem, this}, 242 new String [] {String .class.getName(), ServerInvocationHandler.class.getName()}); 243 } 245 246 } 247 248 255 public void stop() throws Exception 256 { 257 if (connector != null) 259 { 260 connector.removeInvocationHandler(subsystem); 261 } else 263 { 264 server.invoke(connectorName, 265 "removeInvocationHandler", 266 new Object [] {subsystem}, 267 new String [] {String .class.getName()}); 268 } interceptors.clear(); } 271 272 273 275 280 public void addListener(InvokerCallbackHandler invokerCallbackHandler) 281 { 282 283 } 284 285 290 public void removeListener(InvokerCallbackHandler invokerCallbackHandler) 291 { 292 293 } 294 295 300 public void setMBeanServer(MBeanServer MBeanServer) 301 { 302 303 } 304 305 312 public Object invoke(InvocationRequest invocation) throws Throwable 313 { 314 InterceptorIterator iterator = new InterceptorIterator(interceptors.iterator(), invocation); 315 return iterator.invokeNext(); 316 } 317 318 323 public void setInvoker(ServerInvoker serverInvoker) 324 { 325 326 } 327 328 public static class InterceptorIterator 329 { 330 private final Iterator iterator; 331 private final InvocationRequest invocation; 332 333 public InterceptorIterator(final Iterator iterator, final InvocationRequest invocation) 334 { 335 this.iterator = iterator; 336 this.invocation = invocation; 337 } 338 339 public Object invokeNext() throws Throwable 340 { 341 return ((ServerInterceptor)iterator.next()).invoke(this, invocation); 342 } 343 344 } 345 346 } | Popular Tags |