1 23 24 29 package com.sun.cli.jmx.util; 30 31 import javax.management.*; 32 import java.io.IOException ; 33 import java.util.Set ; 34 35 import com.sun.cli.util.DebugState; 36 37 38 39 49 public class MBeanServerConnection_Debug 50 extends MBeanServerConnection_Hook 51 { 52 final MBeanServerConnection_Hook.Hook mHook; 53 final DebugState mDebugState; 54 55 public 56 MBeanServerConnection_Debug( MBeanServerConnection impl, DebugState debugState ) 57 { 58 super( impl ); 59 60 mDebugState = debugState; 61 mHook = new DebugHook(); 62 } 63 64 Hook 65 getHook() 66 { 67 return( mHook ); 68 } 69 70 final DebugState 71 getDebugState() 72 { 73 return( mDebugState ); 74 } 75 76 79 private final static Object [] EMPTY_ARRAY = new Object [ 0 ]; 80 81 class DebugHook extends MBeanServerConnection_Hook.HookImpl 82 { 83 public 84 DebugHook( ) 85 { 86 printDebug( "MBeanServerConnection_Debug: instantiated" ); 87 } 88 89 final void 90 printDebug( Object o ) 91 { 92 if ( getDebugState().getDebug() ) 93 { 94 getDebugState().printDebug( o ); 95 } 96 } 97 98 99 String 100 getInvocationString( long id, String methodName, Object [] args ) 101 { 102 String msg = id + ": " + methodName + "("; 103 104 for( int i = 0; i < args.length; ++i ) 105 { 106 msg = msg + args[ i ].getClass().getName(); 107 if ( i != args.length - 1 ) 108 { 109 msg = msg + ","; 110 } 111 } 112 msg = msg + ")"; 113 114 return( msg ); 115 } 116 117 public long 118 preHook( String methodName ) 119 { 120 return( preHook( methodName, EMPTY_ARRAY ) ); 121 } 122 123 public long 124 preHook( String methodName, Object [] args ) 125 { 126 final long id = getNewID(); 127 128 printDebug( "pre: " + getInvocationString( id, methodName, args ) ); 129 130 return( id ); 131 } 132 133 public void 134 postHook( long id, String methodName ) 135 { 136 printDebug( "post: " + getInvocationString( id, methodName, null ) ); 137 } 138 139 public void 140 postHook( long id, String methodName, Object [] args ) 141 { 142 printDebug( "post: " + getInvocationString( id, methodName, args ) ); 143 } 144 145 public void 146 postHook( long id, String methodName, Object [] args, Object result ) 147 { 148 printDebug( "post: " + 149 getInvocationString( id, methodName, args ) + 150 result.getClass().getName() + " => " + result.toString() 151 ); 152 } 153 } 154 }; 155 156 | Popular Tags |