KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > transport > Connector


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.remoting.transport;
10
11 import java.net.InetAddress JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16 import javax.management.MBeanRegistration JavaDoc;
17 import javax.management.MBeanServer JavaDoc;
18 import javax.management.MBeanServerInvocationHandler JavaDoc;
19 import javax.management.MalformedObjectNameException JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21 import org.jboss.logging.Logger;
22 import org.jboss.remoting.InvokerLocator;
23 import org.jboss.remoting.InvokerRegistry;
24 import org.jboss.remoting.ServerInvocationHandler;
25 import org.jboss.remoting.ServerInvoker;
26 import org.jboss.remoting.marshal.MarshalFactory;
27 import org.jboss.remoting.marshal.MarshallLoaderFactory;
28 import org.w3c.dom.Element JavaDoc;
29 import org.w3c.dom.NamedNodeMap JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31 import org.w3c.dom.NodeList JavaDoc;
32
33 /**
34  * Connector is an implementation of the ConnectorMBean interface.
35  * <p/>
36  * The Connector is root component for the remoting server. It binds the server transport, marshaller,
37  * and handler together to form the remoting server instance.
38  * <p/>
39  * A transport connector is configured via *-service.xml such as:
40  * <code>
41  * <?xml version="1.0" encoding="UTF-8"?>
42  * <!DOCTYPE server>
43  * <server>
44  * <!-- NOTE: set this up to the path where your libraries are -->
45  * <classpath codebase="lib" archives="*"/>
46  * <mbean code="org.jboss.remoting.network.NetworkRegistry"
47  * name="jboss.remoting:service=NetworkRegistry"/>
48  * <p/>
49  * <mbean code="org.jboss.remoting.transport.Connector"
50  * xmbean-dd="org/jboss/remoting/transport/Connector.xml"
51  * name="jboss.remoting:service=Connector,transport=Socket"
52  * display-name="Socket transport Connector">
53  * <p/>
54  * <!-- Can either just specify the InvokerLocator attribute and not the invoker element in the -->
55  * <!-- Configuration attribute, or do the full invoker configuration in the in invoker element -->
56  * <!-- of the Configuration attribute. -->
57  * <!-- Remember that if you do use more than one param on the uri, will have to include as a CDATA, -->
58  * <!-- otherwise, parser will complain. -->
59  * <!-- <attribute name="InvokerLocator"><![CDATA[socket://${jboss.bind.address}:8084/?enableTcpNoDelay=false&clientMaxPoolSize=30]]></attribute>-->
60  * <attribute name="Configuration">
61  * <config>
62  * <invoker transport="socket">
63  * <attribute name="numAcceptThreads">1</attribute>
64  * <attribute name="maxPoolSize">303</attribute>
65  * <attribute name="clientMaxPoolSize" isParam="true">304</attribute>
66  * <attribute name="socketTimeout">60000</attribute>
67  * <attribute name="serverBindAddress">${jboss.bind.address}</attribute>
68  * <attribute name="serverBindPort">6666</attribute>
69  * <!-- <attribute name="clientConnectAddress">216.23.33.2</attribute> -->
70  * <!-- <attribute name="clientConnectPort">7777</attribute> -->
71  * <attribute name="enableTcpNoDelay" isParam="true">false</attribute>
72  * <attribute name="backlog">200</attribute>
73  * </invoker>
74  * <handlers>
75  * <handler subsystem="mock">org.jboss.remoting.transport.mock.MockServerInvocationHandler</handler>
76  * </handlers>
77  * </config>
78  * </attribute>
79  * </mbean>
80  * <p/>
81  * <mbean code="org.jboss.remoting.detection.multicast.MulticastDetector"
82  * name="jboss.remoting:service=Detector,transport=multicast">
83  * <!-- you can specifically bind the detector to a specific IP address here -->
84  * <!-- <attribute name="BindAddress">${jboss.bind.address}</attribute> -->
85  * <attribute name="Port">2410</attribute>
86  * </mbean>
87  * <p/>
88  * </server>
89  * </code>
90  *
91  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
92  * @author <a HREF="mailto:adrian.brock@happeningtimes.com">Adrian Brock</a>
93  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
94  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>
95  * @author <a HREF="mailto:tom@jboss.org">Tom Elrod</a>
96  * @version $Revision: 1.10 $
97  * @jmx.mbean description = "An MBean wrapper around a ServerInvoker."
98  * @jboss.xmbean
99  */

100 public class Connector implements MBeanRegistration JavaDoc, ConnectorMBean
101 {
102    protected ServerInvoker invoker;
103
104    private String JavaDoc locatorURI;
105
106    private Element JavaDoc xml;
107
108    private MBeanServer JavaDoc server;
109
110    private Connector marshallerLoaderConnector = null;
111    private boolean isMarshallerLoader = false;
112
113    private boolean isStarted = false;
114    private boolean isCreated = false;
115
116    protected final Logger log = Logger.getLogger(getClass());
117
118    public Connector()
119    {
120
121    }
122
123    protected Connector(boolean isMarshallerConnector)
124    {
125       this();
126       this.isMarshallerLoader = isMarshallerConnector;
127    }
128
129    public boolean isStarted()
130    {
131       return isStarted;
132    }
133
134    /**
135     * This method is called by the MBeanServer before registration takes
136     * place. The MBean is passed a reference of the MBeanServer it is
137     * about to be registered with. The MBean must return the ObjectName it
138     * will be registered with. The MBeanServer can pass a suggested object
139     * depending upon how the MBean is registered.<p>
140     * <p/>
141     * The MBean can stop the registration by throwing an exception.The
142     * exception is forwarded to the invoker wrapped in an
143     * MBeanRegistrationException.
144     *
145     * @param server the MBeanServer the MBean is about to be
146     * registered with.
147     * @param name the suggested ObjectName supplied by the
148     * MBeanServer.
149     * @return the actual ObjectName to register this MBean with.
150     * @throws Exception for any error, the MBean is not registered.
151     */

152    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name)
153          throws Exception JavaDoc
154    {
155       this.server = server;
156       return name;
157    }
158
159    /**
160     * This method is called by the MBeanServer after registration takes
161     * place or when registration fails.
162     *
163     * @param registrationDone the MBeanServer passes true when the
164     * MBean was registered, false otherwise.
165     */

166    public void postRegister(Boolean JavaDoc registrationDone)
167    {
168    }
169
170    /**
171     * This method is called by the MBeanServer before deregistration takes
172     * place.<p>
173     * <p/>
174     * The MBean can throw an exception, this will stop the deregistration.
175     * The exception is forwarded to the invoker wrapped in
176     * an MBeanRegistrationException.
177     */

178    public void preDeregister()
179          throws Exception JavaDoc
180    {
181    }
182
183    /**
184     * This method is called by the MBeanServer after deregistration takes
185     * place.
186     */

187    public void postDeregister()
188    {
189    }
190
191    /**
192     * Starts the connector.
193     *
194     * @jmx.managed-operation description = "Start sets up the ServerInvoker we are wrapping."
195     * impact = "ACTION"
196     */

197    public void start()
198          throws Exception JavaDoc
199    {
200       if(!isStarted)
201       {
202
203          // doing this for those who use remoting outside of jboss container
204
// so don't have to call create() and then start()
205
if(!isCreated)
206          {
207             create();
208          }
209
210          ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
211
212          if(cl == null)
213          {
214             cl = getClass().getClassLoader();
215          }
216
217          // want to have handlers registered before starting, so if someone makes invocation,
218
// there is something to handle it.
219
configureHandlers(cl);
220
221          // if marshaller loader not started, start it
222
if(!isMarshallerLoader)
223          {
224             if(marshallerLoaderConnector != null && !marshallerLoaderConnector.isStarted())
225             {
226                marshallerLoaderConnector.start();
227             }
228          }
229
230          // if invoker not started, start it
231
if(invoker.isStarted() == false)
232          {
233             try
234             {
235                invoker.start();
236             }
237             catch(Exception JavaDoc e)
238             {
239                if(marshallerLoaderConnector != null)
240                {
241                   marshallerLoaderConnector.stop();
242                }
243                log.error("Error starting connector.", e);
244                throw e;
245             }
246          }
247          isStarted = true;
248       }
249
250    }
251
252    /**
253     * Starts the connector.
254     *
255     * @param runAsNewThread indicates if should be started on new thread or the current one
256     * @throws Exception
257     */

258    public void start(boolean runAsNewThread) throws Exception JavaDoc
259    {
260
261       Runnable JavaDoc r = new Runnable JavaDoc()
262       {
263          public void run()
264          {
265             try
266             {
267                start();
268             }
269             catch(Exception JavaDoc e)
270             {
271                log.error("Error starting Connector.", e);
272             }
273          }
274       };
275       Thread JavaDoc t = new Thread JavaDoc(r);
276       t.setDaemon(false);
277       t.start();
278    }
279
280    private void init()
281          throws Exception JavaDoc
282    {
283       Map JavaDoc invokerConfig = new HashMap JavaDoc();
284
285       if(locatorURI == null)
286       {
287          // nothing set for the InvokerLocator attribute, check to see if is part of Configuration attribute
288
if(xml != null)
289          {
290             getInvokerConfig(invokerConfig);
291          }
292       }
293
294       if(locatorURI == null)
295       {
296          throw new IllegalStateException JavaDoc("Connector not configured with LocatorURI.");
297       }
298
299       InvokerLocator locator = new InvokerLocator(locatorURI);
300
301       if(invoker == null)
302       {
303          // create the server invoker
304
invoker = InvokerRegistry.createServerInvoker(locator, invokerConfig);
305
306          // this will set the mbean server on the invoker and register it with mbean server
307
if(server != null)
308          {
309             try
310             {
311                ObjectName JavaDoc objName = new ObjectName JavaDoc(invoker.getMBeanObjectName());
312                if(!server.isRegistered(objName))
313                {
314                   server.registerMBean(invoker, objName);
315                   invoker.setMBeanServer(server);
316                }
317             }
318             catch(Throwable JavaDoc e)
319             {
320                log.warn("Error registering invoker " + invoker + " with MBeanServer.", e);
321             }
322          }
323
324          invoker.create();
325       }
326
327       // if using a generic locator (such as socket://localhost:0), the locator may change so
328
// keep the local cache in synch
329
locatorURI = invoker.getLocator().getLocatorURI();
330
331
332       if(!isMarshallerLoader)
333       {
334          // need to check if should create a marshaller loader on the server side
335
if(marshallerLoaderConnector == null)
336          {
337             marshallerLoaderConnector = createMarshallerLoader(invoker.getLocator());
338          }
339       }
340
341    }
342
343    private Connector createMarshallerLoader(InvokerLocator locator)
344    {
345       /**
346        * This is a bit of a hack, but have to bootstrap the marshaller/unmarshaller here because
347        * need them loaded and added to the MarshalFactory now, because is possible the first client
348        * to make a call on this connector may not have the marshaller/unmarshaller. Therefore, when
349        * the MarshallerLoaderHandler goes to load them for the client (MarshallerLoaderClient), they
350        * have to be there. Otherwise, would not be loaded until first client actually reaches the
351        * target server invoker, where they would otherwise be loaded.
352        */

353       MarshalFactory.getMarshaller(locator, this.getClass().getClassLoader());
354
355       Connector marshallerLoader = null;
356       InvokerLocator loaderLocator = MarshallLoaderFactory.convertLocator(locator);
357       // if loaderLocator is null, then probably not defined to have loader service (i.e. no loader port specified)
358
if(loaderLocator != null)
359       {
360          marshallerLoader = MarshallLoaderFactory.createMarshallLoader(loaderLocator);
361       }
362       return marshallerLoader;
363    }
364
365    private void getInvokerConfig(Map JavaDoc invokerConfig)
366    {
367       try
368       {
369          NodeList JavaDoc invokerNodes = xml.getElementsByTagName("invoker");
370
371          if(invokerNodes != null && invokerNodes.getLength() >= 1)
372          {
373             // only accept on invoker per connector at present
374
Node JavaDoc invokerNode = invokerNodes.item(0);
375
376             NamedNodeMap JavaDoc attributes = invokerNode.getAttributes();
377             Node JavaDoc transportNode = attributes.getNamedItem("transport");
378
379             if(transportNode != null)
380             {
381                String JavaDoc transport = transportNode.getNodeValue();
382
383                // need to log warning if there are more than one invoker elements
384
if(invokerNodes.getLength() > 1)
385                {
386                   log.warn("Found more than one invokers defined in configuration. " +
387                            "Will only be using the first one - " + transport);
388                }
389
390                // now create a map for all the sub attributes
391
Map JavaDoc paramConfig = new HashMap JavaDoc();
392                NodeList JavaDoc invokerAttributes = invokerNode.getChildNodes();
393                int len = invokerAttributes.getLength();
394                for(int x = 0; x < len; x++)
395                {
396                   Node JavaDoc attr = invokerAttributes.item(x);
397                   if("attribute".equals(attr.getNodeName()))
398                   {
399                      String JavaDoc name = attr.getAttributes().getNamedItem("name").getNodeValue();
400                      String JavaDoc value = attr.getFirstChild().getNodeValue();
401                      invokerConfig.put(name, value);
402                      Node JavaDoc isParamAttribute = attr.getAttributes().getNamedItem("isParam");
403                      if(isParamAttribute != null && Boolean.valueOf(isParamAttribute.getNodeValue()).booleanValue())
404                      {
405                         paramConfig.put(name, value);
406                      }
407                   }
408                }
409
410                // should now have my map with all my attributes, now need to look for
411
// specific attributes that will impact the locator uri.
412
String JavaDoc clientConnectAddress = (String JavaDoc) invokerConfig.get("clientConnectAddress");
413                String JavaDoc clientConnectPort = (String JavaDoc) invokerConfig.get("clientConnectPort");
414                String JavaDoc serverBindAddress = (String JavaDoc) invokerConfig.get("serverBindAddress");
415                String JavaDoc serverBindPort = (String JavaDoc) invokerConfig.get("serverBindPort");
416
417                String JavaDoc host = clientConnectAddress != null ? clientConnectAddress : serverBindAddress != null ? serverBindAddress : InetAddress.getLocalHost().getHostAddress();
418                int port = clientConnectPort != null ? Integer.parseInt(clientConnectPort) : serverBindPort != null ? Integer.parseInt(serverBindPort) : PortUtil.findFreePort();
419
420                if("0.0.0.0".equals(host))
421                {
422                   host = InetAddress.getLocalHost().getHostAddress();
423                }
424
425                // finally, let's bild the invoker uri
426
String JavaDoc tempURI = transport + "://" + host + ":" + port;
427
428                // an params to add to the uri?
429
if(paramConfig.size() > 0)
430                {
431                   tempURI += "/?";
432                   Iterator JavaDoc keyItr = paramConfig.keySet().iterator();
433                   if(keyItr.hasNext())
434                   {
435                      Object JavaDoc name = keyItr.next();
436                      Object JavaDoc value = paramConfig.get(name);
437                      tempURI += name + "=" + value;
438                   }
439                   while(keyItr.hasNext())
440                   {
441                      tempURI += "&";
442                      Object JavaDoc name = keyItr.next();
443                      Object JavaDoc value = paramConfig.get(name);
444                      tempURI += name + "=" + value;
445                   }
446                }
447                locatorURI = tempURI;
448             }
449             else
450             {
451                log.error("Invoker element within Configuration attribute does not contain a transport attribute.");
452             }
453
454          }
455       }
456       catch(Exception JavaDoc e)
457       {
458          log.error("Error configuring invoker for connector.", e);
459          throw new IllegalStateException JavaDoc("Error configuring invoker for connector. Can not continue without invoker.");
460       }
461    }
462
463    private void configureHandlers(ClassLoader JavaDoc cl)
464          throws Exception JavaDoc
465    {
466       if(xml != null)
467       {
468          NodeList JavaDoc handlersNodes = xml.getElementsByTagName("handler");
469
470          if(handlersNodes == null || handlersNodes.getLength() <= 0)
471          {
472             throw new IllegalArgumentException JavaDoc("required 'handler' element not found");
473          }
474
475          int len = handlersNodes.getLength();
476
477          for(int c = 0; c < len; c++)
478          {
479             Node JavaDoc node = handlersNodes.item(c);
480             Node JavaDoc subNode = node.getAttributes().getNamedItem("subsystem");
481
482             if(subNode == null)
483             {
484                throw new IllegalArgumentException JavaDoc("Required 'subsystem' attribute on 'handler' element");
485             }
486
487             String JavaDoc handlerClass = node.getFirstChild().getNodeValue();
488
489             boolean isObjName = false;
490             ServerInvocationHandler JavaDoc handler = null;
491
492             //first check to see if this is an ObjectName
493
try
494             {
495                ObjectName JavaDoc objName = new ObjectName JavaDoc(handlerClass);
496                handler = createHandlerProxy(objName);
497                isObjName = true;
498             }
499             catch(MalformedObjectNameException JavaDoc e)
500             {
501                log.debug("Handler supplied is not an object name.");
502             }
503
504             if(!isObjName)
505             {
506                handler = (ServerInvocationHandler JavaDoc) cl.loadClass(handlerClass).newInstance();
507             }
508
509             StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(subNode.getNodeValue(), ",");
510
511             while(tok.hasMoreTokens())
512             {
513                String JavaDoc subsystem = tok.nextToken();
514                addInvocationHandler(subsystem, handler);
515             }
516          }
517       }
518    }
519
520    private ServerInvocationHandler JavaDoc createHandlerProxy(ObjectName JavaDoc objName)
521    {
522       ServerInvocationHandler JavaDoc handler;
523       if(server != null)
524       {
525          handler = (ServerInvocationHandler JavaDoc)
526                MBeanServerInvocationHandler.newProxyInstance(server,
527                                                              objName,
528                                                              ServerInvocationHandler JavaDoc.class,
529                                                              false);
530       }
531       else
532       {
533          throw new RuntimeException JavaDoc("Can not register MBean invocation handler as the Connector has not been registered with a MBeanServer.");
534       }
535       return handler;
536    }
537
538    /**
539     * Stops the connector.
540     *
541     * @jmx.managed-operation description = "Stop tears down the ServerInvoker we are wrapping."
542     * impact = "ACTION"
543     */

544    public void stop()
545    {
546       if(isStarted)
547       {
548          if(invoker != null)
549          {
550             invoker.stop();
551             invoker.destroy();
552             InvokerRegistry.destroyServerInvoker(invoker);
553             invoker = null;
554          }
555          if(marshallerLoaderConnector != null && marshallerLoaderConnector.isStarted)
556          {
557             marshallerLoaderConnector.stop();
558             marshallerLoaderConnector = null;
559          }
560          isCreated = false;
561          isStarted = false;
562       }
563    }
564
565    /**
566     * Creates the connector.
567     *
568     * @jmx.managed-operation
569     */

570    public void create()
571          throws Exception JavaDoc
572    {
573       if(!isCreated)
574       {
575          init();
576       }
577    }
578
579    /**
580     * Destroys the connector.
581     *
582     * @jmx.managed-operation
583     */

584    public void destroy()
585    {
586       //NOOP as all is taken care of in the stop() method
587
}
588
589    public ServerInvoker getServerInvoker()
590    {
591       return invoker;
592    }
593
594    /**
595     * Will get array of all the handlers registered with the connector's server invoker.
596     *
597     * @return
598     */

599    public ServerInvocationHandler JavaDoc[] getInvocationHandlers()
600    {
601       ServerInvocationHandler JavaDoc[] handlers = null;
602       if(invoker != null)
603       {
604          handlers = invoker.getInvocationHandlers();
605       }
606
607       return handlers;
608    }
609
610    /**
611     * Returns the locator to the connector. Locator is the actual InvokerLocator
612     * object used to identify and get the ServerInvoker we are wrapping.
613     *
614     * @jmx.managed-attribute description = "Locator is the actual InvokerLocator object used to
615     * identify and get the ServerInvoker we are wrapping."
616     * access = "read-only"
617     */

618    public InvokerLocator getLocator()
619    {
620       return invoker.getLocator();
621    }
622
623    /**
624     * Sets the invoker locator. InvokerLocator is the string URI representation
625     * of the InvokerLocator used to get and identify the ServerInvoker
626     * we are wrapping.
627     *
628     * @jmx.managed-attribute description = "InvokerLocator is the string URI representation of the
629     * InvokerLocator used to get and identify the ServerInvoker
630     * we are wrapping."
631     * access = "read-write"
632     */

633    public void setInvokerLocator(String JavaDoc locator)
634          throws Exception JavaDoc
635    {
636       locatorURI = locator;
637    }
638
639
640    /**
641     * Returns the invoker locator. InvokerLocator is the string URI representation
642     * of the InvokerLocator used to get and identify the ServerInvoker
643     * we are wrapping.
644     *
645     * @jmx.managed-attribute
646     */

647    public String JavaDoc getInvokerLocator() throws Exception JavaDoc
648    {
649       return locatorURI;
650    }
651
652    /**
653     * Configuration is an xml element indicating subsystems to be registered
654     * with the ServerInvoker we wrap. Using mbean subsystems that call
655     * registerSubsystem is more flexible.
656     *
657     * @jmx.managed-attribute description = "Configuration is an xml element indicating subsystems
658     * to be registered with the ServerInvoker we wrap. Using
659     * mbean subsystems that call registerSubsystem is more
660     * flexible."
661     * access = "read-write"
662     */

663    public void setConfiguration(Element JavaDoc xml)
664          throws Exception JavaDoc
665    {
666       this.xml = xml;
667    }
668
669    /**
670     * Configuration is an xml element indicating subsystems to be registered
671     * with the ServerInvoker we wrap. Using mbean subsystems that call
672     * registerSubsystem is more flexible.
673     *
674     * @jmx.managed-attribute
675     */

676    public Element JavaDoc getConfiguration()
677    {
678       return xml;
679    }
680
681    /**
682     * Adds a handler to the connector via OjbectName. This will create a mbean proxy of
683     * type of ServerInvocationHandler for the MBean specified by object name passed (so has
684     * to implement ServerInvocationHandler interface).
685     *
686     * @param subsystem
687     * @param handlerObjectName
688     * @return Previous ServerInvocatioHandler with the same subsystem value (case insensitive) or null if one did not previously exist.
689     * @throws Exception
690     * @jmx.managed-operation description = "Add a subsystem invocation handler to the ServerInvoker
691     * we wrap, identified by the subsystem parameter."
692     * impact = "ACTION"
693     * @jmx.managed-parameter name = "subsystem"
694     * type = "java.lang.String"
695     * description = "The subsystem this handler is for."
696     * @jmx.managed-parameter name = "handlerObjectName"
697     * type = "javax.management.ObjectName"
698     * description = "The ServerInvocationHandler MBean we are registering
699     * for the subsystem"
700     */

701    public ServerInvocationHandler JavaDoc addInvocationHandler(String JavaDoc subsystem, ObjectName JavaDoc handlerObjectName) throws Exception JavaDoc
702    {
703       ServerInvocationHandler JavaDoc invocationHandler = createHandlerProxy(handlerObjectName);
704       return addInvocationHandler(subsystem, invocationHandler);
705    }
706
707    /**
708     * Adds an invocation handler for the named subsystem to the invoker we
709     * manage, and sets the mbean server on the invocation handler.
710     *
711     * @return Previous ServerInvocatioHandler with the same subsystem value (case insensitive) or null if one did not previously exist.
712     * @jmx.managed-operation description = "Add a subsystem invocation handler to the ServerInvoker
713     * we wrap, identified by the subsystem parameter."
714     * impact = "ACTION"
715     * @jmx.managed-parameter name = "subsystem"
716     * type = "java.lang.String"
717     * description = "The subsystem this handler is for."
718     * @jmx.managed-parameter name = "handler"
719     * type = "org.jboss.remoting.ServerInvocationHandler"
720     * description = "The ServerInvocationHandler we are registering
721     * for the subsystem"
722     */

723    public ServerInvocationHandler JavaDoc addInvocationHandler(String JavaDoc subsystem, ServerInvocationHandler JavaDoc handler)
724          throws Exception JavaDoc
725    {
726       if(invoker == null)
727       {
728          throw new IllegalStateException JavaDoc("You may only add handlers once the Connector is created (via create() method).");
729       }
730
731       handler.setMBeanServer(server);
732       return invoker.addInvocationHandler(subsystem, handler);
733    }
734
735    /**
736     * Removes an invocation handler for the supplied subsystem from the invoker
737     * we manage, and unsets the MBeanServer on the handler.
738     *
739     * @jmx.managed-operation description = "Remove a subsystem invocation handler to the
740     * ServerInvoker we wrap, identified by the subsystem
741     * parameter."
742     * impact = "ACTION"
743     * @jmx.managed-parameter name = "subsystem"
744     * type = "java.lang.String"
745     * description = "The subsystem this handler is for."
746     */

747    public void removeInvocationHandler(String JavaDoc subsystem) throws Exception JavaDoc
748    {
749       ServerInvocationHandler JavaDoc handler = invoker.removeInvocationHandler(subsystem);
750
751       if(handler != null)
752       {
753          handler.setMBeanServer(null);
754       }
755    }
756
757 }
758
Popular Tags