KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > jmx > MBeanServerConnection_Debug


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 /*
25  * $Header: /cvs/glassfish/admin-core/mbeanapi/src/java/com/sun/appserv/management/util/jmx/MBeanServerConnection_Debug.java,v 1.3 2005/12/25 03:51:26 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:51:26 $
28  */

29 package com.sun.appserv.management.util.jmx;
30
31 import javax.management.*;
32 import java.io.IOException JavaDoc;
33 import java.io.PrintStream JavaDoc;
34 import java.util.Set JavaDoc;
35
36 import com.sun.appserv.management.util.misc.DebugState;
37 import com.sun.appserv.management.util.misc.Output;
38
39
40
41 /**
42     This class allows use of MBeanServerConnection methods with ObjectName patterns
43     that resolve to a single MBean. This is useful to avoid hard-coupling to specific
44     ObjectNames; instead an ObjectName pattern may be used which resolves to a
45     single MBean.
46     
47     For example, if you know the 'name' property is unique (at least for your MBean),
48     you could use the ObjectName "*:name=myname,*" instead of a possibly much longer
49     and complicated name (which potentially could change each time the MBean is registered).
50  */

51 public class MBeanServerConnection_Debug
52     extends MBeanServerConnection_Hook
53 {
54     final MBeanServerConnection_Hook.Hook mHook;
55     final DebugState mDebugState;
56     final Output mOutput;
57     
58         public
59     MBeanServerConnection_Debug(
60         MBeanServerConnection impl,
61         DebugState debugState,
62         Output output )
63     {
64         super( impl );
65         
66         mDebugState = debugState;
67         mOutput = output;
68         mHook = new DebugHook();
69     }
70     
71         Hook
72     getHook()
73     {
74         return( mHook );
75     }
76     
77         final DebugState
78     getDebugState()
79     {
80         return( mDebugState );
81     }
82     
83     private final static Object JavaDoc [] EMPTY_ARRAY = new Object JavaDoc [ 0 ];
84         
85     private class DebugHook extends MBeanServerConnection_Hook.HookImpl
86     {
87             public
88         DebugHook()
89         {
90         }
91         
92             final void
93         printDebug( Object JavaDoc o )
94         {
95             if ( getDebugState().getDebug() )
96             {
97                 mOutput.printDebug( o );
98             }
99         }
100         
101             public long
102         preHook( String JavaDoc methodName )
103         {
104             return( preHook( methodName, EMPTY_ARRAY ) );
105         }
106         
107             public long
108         preHook( String JavaDoc methodName, Object JavaDoc [] args )
109         {
110             final long id = getNewID();
111             
112             printDebug( "pre: " + getInvocationString( id, methodName, args ) );
113             
114             return( id );
115         }
116         
117             public void
118         postHook( long id, String JavaDoc methodName )
119         {
120             printDebug( "post: " + getInvocationString( id, methodName, null ) );
121         }
122         
123             public void
124         postHook( long id, String JavaDoc methodName, Object JavaDoc [] args )
125         {
126             printDebug( "post: " + getInvocationString( id, methodName, args ) );
127         }
128         
129             public void
130         postHook( long id, String JavaDoc methodName, Object JavaDoc [] args, Object JavaDoc result )
131         {
132             final String JavaDoc resultString = result == null ?
133                 "null" : result.getClass().getName() + " => " + result.toString();
134                 
135             printDebug( "post: " +
136                 getInvocationString( id, methodName, args ) + resultString );
137         }
138     }
139 };
140
141
Popular Tags