1 23 24 29 30 package com.sun.cli.jmx.cmd; 31 32 33 import com.sun.cli.jmx.support.ResultsForGetSet; 34 import com.sun.cli.jmx.support.CLISupportMBeanProxy; 35 import com.sun.cli.jmx.support.InvokeResult; 36 import com.sun.cli.util.stringifier.*; 37 38 public class InvokeCmd extends JMXCmd 39 { 40 public 41 InvokeCmd( final CmdEnv env ) 42 { 43 super( env ); 44 } 45 46 int 47 getNumRequiredOperands() 48 { 49 return( 0 ); 51 } 52 53 public String 54 getUsage() 55 { 56 return( CmdStrings.INVOKE_HELP.toString() ); 57 } 58 59 public static String FORMAL_NAME = "invoke"; 60 61 public static String [] 62 getNames( ) 63 { 64 return( new String [] { FORMAL_NAME, CmdFactory.DEFAULT_CMD_NAME} ); 65 } 66 67 72 void 73 executeInternal() 74 throws Exception 75 { 76 final String cmdString = getCmdNameAsInvoked(); 77 String [] targets = getTargets(); 78 79 final int colonPos = cmdString.indexOf( ":" ); 80 81 if ( cmdString.equals( FORMAL_NAME ) ) 82 { 83 printUsage(); 84 return; 85 } 86 else if ( colonPos < 0 ) 87 { 88 printError( CmdStrings.NO_SUCH_COMMAND + cmdString ); 89 return; 90 } 91 92 93 String argList = null; 94 String methodName = null; 95 final int dotIndex = cmdString.indexOf( '.' ); 96 if ( dotIndex > 0 && dotIndex < colonPos ) 97 { 98 requireNumOperands( 0 ); 99 targets = new String [] { cmdString.substring( 0, dotIndex ) }; 100 methodName = cmdString.substring( dotIndex + 1, colonPos ); 101 } 102 else 103 { 104 105 methodName = cmdString.substring( 0, colonPos ); 106 } 107 108 if ( colonPos + 1 != cmdString.length() ) 109 { 110 argList = cmdString.substring( colonPos + 1, cmdString.length() ); 111 } 112 else 113 { 114 argList = null; 115 } 116 117 118 120 establishProxy(); 121 122 final InvokeResult [] results = invoke( methodName, argList, targets ); 123 124 getProxy().mbeanInvoke( methodName, argList, targets ); 125 126 if ( results.length == 0 ) 127 { 128 println( "Invocation failed: no targets found that match the expression" ); 129 } 130 else 131 { 132 displayResults( results ); 133 } 134 } 135 136 void 137 displayResults( final InvokeResult [] results ) 138 { 139 println( new SmartStringifier( "\n", false ).stringify( results ) ); 140 } 141 142 InvokeResult [] 143 invoke( String operationName, final String argList, final String [] targets ) 144 throws Exception 145 { 146 final InvokeResult [] results = getProxy().mbeanInvoke( operationName, argList, targets ); 147 148 return( results ); 149 } 150 } 151 152 153 154 | Popular Tags |