KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > oldconfig > OldConfigProxies


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.support.oldconfig;
25
26 import java.util.Set JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.MBeanServer JavaDoc;
30 import javax.management.MBeanServerInvocationHandler JavaDoc;
31
32 import com.sun.appserv.management.util.misc.GSetUtil;
33 import com.sun.appserv.management.util.jmx.JMXUtil;
34 import com.sun.appserv.management.base.Util;
35
36
37 /**
38     Provides support for getting proxies to "old" (8.0) config MBeans.
39  */

40 public class OldConfigProxies
41 {
42     final MBeanServer JavaDoc mServer;
43     
44         private
45     OldConfigProxies( final MBeanServer JavaDoc server )
46     {
47         mServer = server;
48     }
49     
50     private final String JavaDoc OLD_DOMAIN = "com.sun.appserv";
51     private final String JavaDoc CONFIGS_IN_OLD_DOMAIN = "com.sun.appserv:category=config";
52     
53     private static OldConfigProxies INSTANCE = null;
54     
55         public static synchronized OldConfigProxies
56     getInstance( final MBeanServer JavaDoc server )
57     {
58         if ( INSTANCE == null )
59         {
60             INSTANCE = new OldConfigProxies( server );
61         }
62         else
63         {
64             assert( INSTANCE.getMBeanServer() == server );
65         }
66         return( INSTANCE );
67     }
68     
69         private MBeanServer JavaDoc
70     getMBeanServer()
71     {
72         return( mServer );
73     }
74     
75     /**
76         @param target the target MBean ObjectName
77         @param interfaceClass the interface class to use
78      */

79         public <T> T
80     newProxy(
81         final ObjectName JavaDoc target,
82         final Class JavaDoc<T> interfaceClass )
83     {
84         return interfaceClass.cast( MBeanServerInvocationHandler.newProxyInstance(
85                     mServer, target, interfaceClass, false ) );
86     }
87     
88     /**
89         @param props properties for use in an ObjectName query
90         @param interfaceClass the interface class to use
91      */

92         public <T> T
93     newProxy(
94         final String JavaDoc props,
95         final Class JavaDoc<T> interfaceClass )
96     {
97         final ObjectName JavaDoc objectName = queryOldConfigObjectName( props );
98         
99         return newProxy( objectName, interfaceClass );
100     }
101     
102         private ObjectName JavaDoc
103     queryOldConfigObjectName( String JavaDoc props )
104     {
105         final ObjectName JavaDoc pattern =
106             Util.newObjectNamePattern( OLD_DOMAIN,
107                 Util.concatenateProps( props, "category=config" ) );
108         
109         final Set JavaDoc<ObjectName JavaDoc> candidates = JMXUtil.queryNames( mServer, pattern, null );
110         
111         ObjectName JavaDoc oldConfigObjectName = null;
112         
113         if ( candidates.size() == 1 )
114         {
115             oldConfigObjectName = GSetUtil.getSingleton( candidates );
116         }
117         else if ( candidates.size() == 0 )
118         {
119             oldConfigObjectName = null;
120         }
121         else
122         {
123             throw new IllegalArgumentException JavaDoc( "found more than one match: " + props );
124         }
125         
126         return( oldConfigObjectName );
127         
128     }
129
130         public OldProperties
131     getOldProperties( final ObjectName JavaDoc objectName )
132     {
133         return( newProxy( objectName, OldProperties.class ) );
134     }
135     
136         public OldConfigsMBean
137     getOldConfigsMBean()
138     {
139         return( newProxy( "type=configs", OldConfigsMBean.class ) );
140     }
141     
142         public OldConfig
143     getOldConfig( final String JavaDoc name )
144     {
145         return( newProxy( "type=config,name=" + name, OldConfig.class ) );
146     }
147                 
148         public OldClustersMBean
149     getOldClustersMBean()
150     {
151         return( newProxy( "type=clusters", OldClustersMBean.class ) );
152     }
153                 
154         public OldServersMBean
155     getOldServersMBean()
156     {
157         return( newProxy( "type=servers", OldServersMBean.class ) );
158     }
159     
160         public OldResourcesMBean
161     getOldResourcesMBean()
162     {
163         return( newProxy( "type=resources", OldResourcesMBean.class ) );
164     }
165                 
166                 public OldApplicationsConfigMBean
167     getOldApplicationsConfigMBean()
168     {
169         return( newProxy(
170                 "type=applications", OldApplicationsConfigMBean.class ) );
171     }
172                 
173         public OldDomainMBean
174     getOldDomainMBean()
175     {
176         return( newProxy( "type=domain", OldDomainMBean.class ) );
177     }
178     
179         public OldClusterMBean
180     getOldClusterMBean( final String JavaDoc clusterName )
181     {
182         return( newProxy(
183                 "type=cluster,name=" + clusterName, OldClusterMBean.class ) );
184     }
185     
186         public OldServerMBean
187     getOldServerMBean( final String JavaDoc serverName )
188     {
189         return( newProxy(
190                 "type=server,name=" + serverName, OldServerMBean.class ) );
191     }
192     
193         public OldAdminServiceMBean
194     getOldAdminServiceMBean( final String JavaDoc configName )
195     {
196         return( newProxy(
197                 "type=admin-service,config=" + configName, OldAdminServiceMBean.class ) );
198     }
199     
200         public OldHTTPServiceMBean
201     getOldHTTPServiceMBean( final String JavaDoc configName )
202     {
203         return( newProxy(
204                 "type=http-service,config=" + configName, OldHTTPServiceMBean.class ) );
205     }
206     
207         public OldVirtualServerMBean
208     getOldVirtualServerMBean(
209         final String JavaDoc configName,
210         final String JavaDoc virtualServer )
211     {
212         return( newProxy(
213                 "type=virtual-server,config=" + configName +
214                 ",id=" + virtualServer, OldVirtualServerMBean.class ) );
215     }
216     
217         public OldIIOPServiceMBean
218     getOldIIOPServiceMBean( final String JavaDoc configName )
219     {
220         return( newProxy(
221                 "type=iiop-service,config=" + configName, OldIIOPServiceMBean.class ) );
222     }
223     
224     
225         public OldSecurityServiceMBean
226     getOldSecurityServiceMBean( final String JavaDoc configName )
227     {
228         return( newProxy(
229                 "type=security-service,config=" + configName, OldSecurityServiceMBean.class ) );
230     }
231     
232     
233         public OldTransactionServiceMBean
234     getOldTransactionServiceMBean( final String JavaDoc configName )
235     {
236         return( newProxy(
237                 "type=transaction-service,config=" + configName, OldTransactionServiceMBean.class ) );
238     }
239     
240     
241         public OldLogServiceMBean
242     getOldLogServiceMBean( final String JavaDoc configName )
243     {
244         return( newProxy(
245                 "type=log-service,config=" + configName, OldLogServiceMBean.class ) );
246     }
247     
248     
249         public OldMonitoringServiceMBean
250     getOldMonitoringServiceMBean( final String JavaDoc configName )
251     {
252         return( newProxy(
253                 "type=monitoring-service,config=" + configName, OldMonitoringServiceMBean.class ) );
254     }
255     
256         public OldSessionConfigMBean
257     getOldSessionConfigMBean( final String JavaDoc configName )
258     {
259         return( newProxy(
260                 "type=session,config=" + configName, OldSessionConfigMBean.class ) );
261     }
262     
263         public OldSessionManagerMBean
264     getOldSessionManagerMBean( final String JavaDoc configName )
265     {
266         return( newProxy(
267                 "type=session-manager,config=" + configName, OldSessionManagerMBean.class ) );
268     }
269     
270     
271         public OldEJBContainerConfigMBean
272     getOldEJBContainerConfigMBean( final String JavaDoc configName )
273     {
274         return( newProxy(
275                 "type=ejb-container,config=" + configName, OldEJBContainerConfigMBean.class ) );
276     }
277     
278     
279         public OldWebContainerConfigMBean
280     getOldWebContainerConfigMBean( final String JavaDoc configName )
281     {
282         return( newProxy(
283                 "type=web-container,config=" + configName, OldWebContainerConfigMBean.class ) );
284     }
285     
286         public OldAvailabilityServiceMBean
287     getOldAvailabilityServiceMBean( final String JavaDoc configName )
288     {
289         return( newProxy(
290                 "type=availability,config=" + configName, OldAvailabilityServiceMBean.class ) );
291     }
292     
293     
294         public OldJavaConfigMBean
295     getOldJavaConfigMBean( final String JavaDoc configName )
296     {
297         return( newProxy(
298                 "type=java-config,config=" + configName, OldJavaConfigMBean.class ) );
299     }
300     
301     
302         public OldModuleLogLevelsMBean
303     getOldModuleLogLevelsMBean( final String JavaDoc configName )
304     {
305         return( newProxy(
306                 "type=module-log-levels,config=" + configName, OldModuleLogLevelsMBean.class ) );
307     }
308     
309     
310         public OldModuleMonitoringLevelsMBean
311     getOldModuleMonitoringLevelsMBean( final String JavaDoc configName )
312     {
313         return( newProxy(
314                 "type=module-monitoring-levels,config=" + configName, OldModuleMonitoringLevelsMBean.class ) );
315     }
316     
317     
318         public OldThreadPoolsConfigMBean
319     getOldThreadPoolsConfigMBean( final String JavaDoc configName )
320     {
321         return( newProxy(
322                 "type=thread-pools,config=" + configName, OldThreadPoolsConfigMBean.class ) );
323     }
324     
325     
326         public OldDASConfigMBean
327     getOldDASConfigMBean( final String JavaDoc configName )
328     {
329         return( newProxy(
330                 "type=das-config,config=" + configName, OldDASConfigMBean.class ) );
331     }
332     
333                 public OldSystemServicesMBean
334     getOldSystemServicesMBean()
335     {
336         return( newProxy(
337             "ias:type=system-services,server=server",
338                         OldSystemServicesMBean.class ) );
339     }
340
341         public OldJMSServiceMBean
342     getOldJMSServiceMBean( final String JavaDoc configName )
343     {
344         return( newProxy(
345                 "type=jms-service,config=" + configName, OldJMSServiceMBean.class ) );
346     }
347                 
348          public OldMessageSecurityConfigMBean
349     getOldMessageSecurityConfigMBean( final String JavaDoc name )
350     {
351         return( newProxy(
352                     "type=message-security-config,name=" + name,
353                         OldMessageSecurityConfigMBean.class ) );
354     }
355
356
357         public OldLbConfigs
358     getOldLbConfigs( )
359     {
360         return( newProxy( "type=lb-configs", OldLbConfigs.class ) );
361     }
362     
363         public OldLbConfig
364     getOldLbConfig( final String JavaDoc name)
365     {
366             return( (OldLbConfig)newProxy(
367                 "type=lb-config,name="+name, OldLbConfig.class ) );
368     }
369                 
370         public OldServerRefMBean
371     getOldServerRefMBean( final String JavaDoc name)
372     {
373             return( ( OldServerRefMBean)newProxy(
374                "type=server-ref,ref=" + name, OldServerRefMBean.class));
375     }
376     
377         public OldClusterRefMBean
378     getOldClusterRefMBean( final String JavaDoc name)
379     {
380             return( ( OldClusterRefMBean)newProxy(
381                "type=cluster-ref,ref=" + name, OldClusterRefMBean.class));
382     }
383
384                 public OldLoadBalancers
385     getOldLoadBalancers( )
386     {
387         return( newProxy( "type=load-balancers", OldLoadBalancers.class ) );
388     }
389     
390         private static String JavaDoc
391     getManagementRulesProps( final String JavaDoc configName )
392     {
393         return "type=management-rules,config=" + configName;
394     }
395     
396         public ObjectName JavaDoc
397     createOldManagementRules( final String JavaDoc configName )
398     {
399         final String JavaDoc props = getManagementRulesProps( configName );
400         
401         ObjectName JavaDoc objectName =
402             queryOldConfigObjectName( props );
403             
404         if ( objectName == null )
405         {
406             // null seems to be OK
407
getOldConfig( configName ).createManagementRules( null );
408             
409             objectName = queryOldConfigObjectName( props );
410         }
411         return objectName;
412     }
413     
414     
415         public OldManagementRules
416     getOldManagementRules( final String JavaDoc configName )
417     {
418         return(
419             newProxy( getManagementRulesProps( configName ), OldManagementRules.class ) );
420     }
421     
422     
423         public OldConnectorConnectionPoolMBean
424     getOldConnectorConnectionPool( final String JavaDoc name )
425     {
426         return(
427             newProxy( "type=connector-connection-pool,name=" + name, OldConnectorConnectionPoolMBean.class ) );
428     }
429     
430     
431         public ObjectName JavaDoc
432     getOldSecurityMapObjectName(
433         final String JavaDoc connectorConnectionPoolName,
434         final String JavaDoc name )
435     {
436         return getOldConnectorConnectionPool( connectorConnectionPoolName ).getSecurityMapByName( name );
437     }
438     
439         public OldSecurityMap
440     getOldSecurityMap(
441         final String JavaDoc connectorConnectionPoolName,
442         final String JavaDoc name )
443     {
444         final ObjectName JavaDoc securityMapObjectName =
445             getOldSecurityMapObjectName( connectorConnectionPoolName, name );
446         
447         return newProxy( securityMapObjectName, OldSecurityMap.class );
448     }
449
450         public OldWebServiceEndpointConfigMBean
451     getOldWebServiceEndpointConfigMBean( final String JavaDoc name)
452     {
453             return( ( OldWebServiceEndpointConfigMBean)newProxy(
454                "type=web-service-endpoint,name=" + name,
455                OldWebServiceEndpointConfigMBean.class));
456     }
457
458 }
459
460
461
462
463
464
465
466
467
468
469
470
Popular Tags