View | Details | Raw Unified | Return to bug 49045
Collapse All | Expand All

(-)catalina/mbeans/MBeanFactory.java (-3 / +104 lines)
Lines 36-41 Link Here
36
import org.apache.catalina.core.StandardContext;
36
import org.apache.catalina.core.StandardContext;
37
import org.apache.catalina.core.StandardEngine;
37
import org.apache.catalina.core.StandardEngine;
38
import org.apache.catalina.core.StandardHost;
38
import org.apache.catalina.core.StandardHost;
39
import org.apache.catalina.core.StandardServer;
39
import org.apache.catalina.core.StandardService;
40
import org.apache.catalina.core.StandardService;
40
import org.apache.catalina.loader.WebappLoader;
41
import org.apache.catalina.loader.WebappLoader;
41
import org.apache.catalina.realm.DataSourceRealm;
42
import org.apache.catalina.realm.DataSourceRealm;
Lines 51-56 Link Here
51
import org.apache.catalina.valves.RemoteHostValve;
52
import org.apache.catalina.valves.RemoteHostValve;
52
import org.apache.catalina.valves.ValveBase;
53
import org.apache.catalina.valves.ValveBase;
53
import org.apache.tomcat.util.modeler.BaseModelMBean;
54
import org.apache.tomcat.util.modeler.BaseModelMBean;
55
import org.apache.tomcat.util.modeler.Registry;
54
56
55
57
56
/**
58
/**
Lines 61-67 Link Here
61
 * @version $Revision$ $Date$
63
 * @version $Revision$ $Date$
62
 */
64
 */
63
65
64
public class MBeanFactory extends BaseModelMBean {
66
public class MBeanFactory{
65
67
66
    private static final org.apache.juli.logging.Log log = 
68
    private static final org.apache.juli.logging.Log log = 
67
        org.apache.juli.logging.LogFactory.getLog(MBeanFactory.class);
69
        org.apache.juli.logging.LogFactory.getLog(MBeanFactory.class);
Lines 232-237 Link Here
232
234
233
    }
235
    }
234
    
236
    
237
    private Server getServer(ObjectName oname) throws Exception{
238
    	Server server=null;
239
    	
240
    	if(container instanceof Service){
241
    		throw new Exception("Base container is a Service.");
242
    	} else if(container instanceof Server){
243
    		server=(Server)this.container;
244
    	}
245
    	
246
    	StandardServer standardServer=null;
247
    	if(server instanceof StandardServer){
248
    		standardServer = (StandardServer)server;
249
    	}
250
    	
251
    	if(oname != null && standardServer != null 
252
    			&& !oname.getDomain().equals(standardServer.getObjectName().getDomain())){
253
    		throw new Exception("Server with the domain is not found");
254
    	}
255
    	
256
    	return server;
257
    }
258
    
259
    /**
260
     * Creates a new StandardService.
261
     *
262
     * @param parent       MBean Name of the associated parent component (Server)
263
     * @param name         Name of this service
264
     * @param container    Name of the associated container (Engine) instance with this service
265
     * @param domain       Domain name for the container instance
266
     * @param defaultHost  Name of the default host to be used in the Engine
267
     * @param baseDir      Base directory value for Engine 
268
     *
269
     * @exception Exception if an MBean cannot be created or registered
270
     */
271
    public String createStandardService(String parent, String name, 
272
    	String container, String domain, String defaultHost, String baseDir) throws Exception{
273
    	
274
    	ObjectName pname = new ObjectName(parent);
275
    	Server server=getServer(pname);
276
    	StandardService service = new StandardService();
277
    	service.setName(name);
278
    	
279
    	ObjectName oname;
280
    	if(domain != null){
281
    		oname=new ObjectName(domain + ":type=Service,serviceName="+name);
282
    	}else{
283
    		oname=new ObjectName(pname.getDomain() + ":type=Service,serviceName="+name);
284
    	}
285
    	
286
    	service.preRegister(Registry.getRegistry(null, null).getMBeanServer(), oname);
287
        Registry.getRegistry(null, null).registerComponent(service, oname, null);
288
    	server.addService(service);
289
        
290
        return (oname.toString());
291
    	
292
    }
293
    
294
    /**
295
     * Creates a new StandardEngine.
296
     *
297
     * @param parent       MBean Name of the associated parent component (Service)
298
     * @param name         Name of this engine
299
     * @param domain       Domain name for the container instance
300
     * @param defaultHost  Name of the default host to be used in the Engine
301
     * @param baseDir      Base directory value for Engine 
302
     *
303
     * @exception Exception if an MBean cannot be created or registered
304
     */
305
    public String createStandardEngine(String parent, String name, String domain,
306
    		String defaultHost, String baseDir) throws Exception{
307
    	
308
        StandardEngine engine = new StandardEngine();
309
        engine.setName( name );
310
        engine.setDomain(domain);
311
        engine.setDefaultHost(defaultHost);
312
        engine.setBaseDir(baseDir);
313
        
314
        ObjectName pname = new ObjectName(parent);
315
        Service service=getService(pname);
316
        service.setContainer(engine);
317
        
318
        return engine.getJmxName().toString();
319
        
320
    }
235
    
321
    
236
    /**
322
    /**
237
     * Create a new AccessLoggerValve.
323
     * Create a new AccessLoggerValve.
Lines 685-691 Link Here
685
771
686
    }
772
    }
687
773
688
774
    
689
    /**
775
    /**
690
     * Create a new StandardManager.
776
     * Create a new StandardManager.
691
     *
777
     *
Lines 777-783 Link Here
777
        
863
        
778
    }
864
    }
779
865
780
866
    /**
867
     * Remove an existing Service.
868
     *
869
     * @param name MBean Name of the service to remove
870
     *
871
     * @exception Exception if a component cannot be removed
872
     */
873
    public void removeService(String name) throws Exception{
874
    	
875
    	ObjectName oname = new ObjectName(name);
876
    	Service service = getService(oname);
877
    	Server server = service.getServer();
878
    	server.removeService(service);
879
    	
880
    }
881
    
781
    /**
882
    /**
782
     * Remove an existing Connector.
883
     * Remove an existing Connector.
783
     *
884
     *
(-)catalina/mbeans/MBeanUtils.java (-1 / +30 lines)
Lines 133-139 Link Here
133
        return (className);
133
        return (className);
134
134
135
    }
135
    }
136
136
    
137
    /**
138
     * Create, register, and return an MBean for this
139
     * <code>Engine</code> object.
140
     *
141
     * @param engine The Engine to be managed
142
     *
143
     * @exception Exception if an MBean cannot be created or registered
144
     */
145
    static DynamicMBean createMBean(Engine engine) throws Exception{
146
    	
147
    	String mname= createManagedName(engine);
148
    	ManagedBean managed=registry.findManagedBean(mname);
149
    	
150
    	if(managed == null){
151
            Exception e = new Exception("ManagedBean is not found with "+mname);
152
            throw new MBeanException(e);
153
    	}
154
    	String domain = managed.getDomain();
155
        if (domain == null)
156
            domain = mserver.getDefaultDomain();
157
        DynamicMBean mbean = managed.createMBean(engine);
158
        ObjectName oname = createObjectName(domain, engine);
159
        if( mserver.isRegistered( oname ))  {
160
            mserver.unregisterMBean(oname);
161
        }
162
        mserver.registerMBean(mbean, oname);
163
        return (mbean); 
164
    		
165
    }
137
    
166
    
138
    /**
167
    /**
139
     * Create, register, and return an MBean for this
168
     * Create, register, and return an MBean for this
(-)catalina/mbeans/ServerLifecycleListener.java (-1 / +2 lines)
Lines 414-420 Link Here
414
        if (log.isDebugEnabled()) {
414
        if (log.isDebugEnabled()) {
415
            log.debug("Creating MBean for Engine " + engine);
415
            log.debug("Creating MBean for Engine " + engine);
416
        }
416
        }
417
        //MBeanUtils.createMBean(engine);
417
        
418
        MBeanUtils.createMBean(engine);
418
        engine.addContainerListener(this);
419
        engine.addContainerListener(this);
419
        if (engine instanceof StandardEngine) {
420
        if (engine instanceof StandardEngine) {
420
            ((StandardEngine) engine).addPropertyChangeListener(this);
421
            ((StandardEngine) engine).addPropertyChangeListener(this);
(-)catalina/mbeans/mbeans-descriptors.xml (-21 / +48 lines)
Lines 18-24 Link Here
18
<mbeans-descriptors>
18
<mbeans-descriptors>
19
19
20
  <mbean         name="MBeanFactory"
20
  <mbean         name="MBeanFactory"
21
            className="org.apache.catalina.mbeans.MBeanFactory"
21
            type="org.apache.catalina.mbeans.MBeanFactory"
22
          description="Factory for MBeans and corresponding components"
22
          description="Factory for MBeans and corresponding components"
23
               domain="Catalina">
23
               domain="Catalina">
24
24
Lines 27-32 Link Here
27
    <!-- value is the object name of the corresponding MBean for the new    -->
27
    <!-- value is the object name of the corresponding MBean for the new    -->
28
    <!-- component.                                                         -->
28
    <!-- component.                                                         -->
29
29
30
	<operation   name="createStandardService"
31
          description="Create a new StandardService"
32
               impact="ACTION"
33
           returnType="java.lang.String">
34
      <parameter name="parent"
35
          description="MBean Name of the associated parent component"
36
                 type="java.lang.String"/>
37
      <parameter name="name"
38
          description="Name of the service"
39
                 type="java.lang.String"/>
40
      <parameter name="container"
41
          description="Name of the associated container instance with the service"
42
                 type="java.lang.String"/>
43
      <parameter name="domain"
44
          description="JMX Domain for the new container. Nullable. Defaults to Server domain."
45
                 type="java.lang.String"/>
46
      <parameter name="defaultHost"
47
          description="Name of the default host to be used in the Engine"
48
                 type="java.lang.String"/>
49
      <parameter name="baseDir"
50
          description="Base directory value for Engine"
51
                 type="java.lang.String"/>
52
    </operation>
53
    
54
    <operation   name="createStandardEngine"
55
          description="Create a new StandardEngine"
56
               impact="ACTION"
57
           returnType="java.lang.String">
58
      <parameter name="parent"
59
          description="MBean Name of the associated parent component"
60
                 type="java.lang.String"/>
61
      <parameter name="name"
62
          description="Name of the engine"
63
                 type="java.lang.String"/>
64
      <parameter name="domain"
65
          description="JMX Domain for the new container. Nullable. Defaults to Server domain."
66
                 type="java.lang.String"/>
67
      <parameter name="defaultHost"
68
          description="Name of the default host to be used in the Engine"
69
                 type="java.lang.String"/>
70
      <parameter name="baseDir"
71
          description="Base directory value for Engine"
72
                 type="java.lang.String"/>
73
    </operation>
74
     
30
    <operation   name="createAccessLoggerValve"
75
    <operation   name="createAccessLoggerValve"
31
          description="Create a new AccessLoggerValve"
76
          description="Create a new AccessLoggerValve"
32
               impact="ACTION"
77
               impact="ACTION"
Lines 196-202 Link Here
196
      <parameter name="docBase"
241
      <parameter name="docBase"
197
          description="Document base directory (or WAR) for ths Context"
242
          description="Document base directory (or WAR) for ths Context"
198
                 type="java.lang.String"/>
243
                 type="java.lang.String"/>
199
    </operation>
244
    </operation><!--
200
245
201
    <operation   name="createStandardEngine"
246
    <operation   name="createStandardEngine"
202
          description="Create a new StandardEngine"
247
          description="Create a new StandardEngine"
Lines 213-219 Link Here
213
                 type="java.lang.String"/>
258
                 type="java.lang.String"/>
214
    </operation>
259
    </operation>
215
260
216
    <operation   name="createStandardEngineService"
261
    --><operation   name="createStandardEngineService"
217
          description="Create a new StandardEngine and StandardService"
262
          description="Create a new StandardEngine and StandardService"
218
               impact="ACTION"
263
               impact="ACTION"
219
           returnType="java.lang.String">
264
           returnType="java.lang.String">
Lines 264-272 Link Here
264
               type="boolean"/>
309
               type="boolean"/>
265
    </operation>
310
    </operation>
266
311
267
268
269
270
    <operation   name="createStandardManager"
312
    <operation   name="createStandardManager"
271
          description="Create a new StandardManager"
313
          description="Create a new StandardManager"
272
               impact="ACTION"
314
               impact="ACTION"
Lines 276-296 Link Here
276
                 type="java.lang.String"/>
318
                 type="java.lang.String"/>
277
    </operation>
319
    </operation>
278
320
279
    <operation   name="createStandardService"
280
          description="Create a new StandardService"
281
               impact="ACTION"
282
           returnType="java.lang.String">
283
      <parameter name="parent"
284
          description="MBean Name of the associated parent component"
285
                 type="java.lang.String"/>
286
      <parameter name="name"
287
          description="Unique name of this Service"
288
                 type="java.lang.String"/>
289
      <parameter name="domain"
290
          description="The domain of this Service"
291
                 type="java.lang.String"/>
292
    </operation>
293
294
    <operation   name="createSystemErrLogger"
321
    <operation   name="createSystemErrLogger"
295
          description="Create a new System Error Logger"
322
          description="Create a new System Error Logger"
296
               impact="ACTION"
323
               impact="ACTION"
(-)tomcat/util/modeler/BaseModelMBean.java (-1 / +1 lines)
Lines 291-297 Link Here
291
        // Invoke the selected method on the appropriate object
291
        // Invoke the selected method on the appropriate object
292
        Object result = null;
292
        Object result = null;
293
        try {
293
        try {
294
            if( method.getDeclaringClass().isAssignableFrom( this.getClass()) ) {
294
            if( method.getDeclaringClass().isAssignableFrom( this.getClass())) {
295
                result = method.invoke(this, params );
295
                result = method.invoke(this, params );
296
            } else {
296
            } else {
297
                result = method.invoke(resource, params);
297
                result = method.invoke(resource, params);
(-)tomcat/util/modeler/ManagedBean.java (-8 / +12 lines)
Lines 599-616 Link Here
599
                types[i] = BaseModelMBean.getAttributeClass(signature[i]);
599
                types[i] = BaseModelMBean.getAttributeClass(signature[i]);
600
            }
600
            }
601
601
602
            // Locate the method to be invoked, either in this MBean itself
602
            // Locate the method to be invoked, either in the corresponding managed resource 
603
            // or in the corresponding managed resource
603
            // or in this MBean itself
604
            // FIXME - Accessible methods in superinterfaces?
604
            // FIXME - Accessible methods in superinterfaces?
605
            Object object = null;
605
            Object object = null;
606
            Exception exception = null;
606
            Exception exception = null;
607
            try {
607
            try {
608
                object = bean;
609
                method = object.getClass().getMethod(aname, types);
610
            } catch (NoSuchMethodException e) {
611
                exception = e;
612
            }
613
            try {
614
                if ((method == null) && (resource != null)) {
608
                if ((method == null) && (resource != null)) {
615
                    object = resource;
609
                    object = resource;
616
                    method = object.getClass().getMethod(aname, types);
610
                    method = object.getClass().getMethod(aname, types);
Lines 618-623 Link Here
618
            } catch (NoSuchMethodException e) {
612
            } catch (NoSuchMethodException e) {
619
                exception = e;
613
                exception = e;
620
            }
614
            }
615
            
616
            if(method == null){
617
	            try {
618
	                object = bean;
619
	                method = object.getClass().getMethod(aname, types);
620
	            } catch (NoSuchMethodException e) {
621
	                exception = e;
622
	            }
623
            }
624
            
621
            if (method == null) {
625
            if (method == null) {
622
                throw new ReflectionException(exception, "Cannot find method "
626
                throw new ReflectionException(exception, "Cannot find method "
623
                        + aname + " with this signature");
627
                        + aname + " with this signature");

Return to bug 49045