FileDocCategorySizeDatePackage
JMXCmd.javaAPI DocGlassfish v2 API9456Fri May 04 22:24:50 BST 2007com.sun.cli.jmx.cmd

JMXCmd

public abstract class JMXCmd extends CmdBase

Fields Summary
final String[]
ALL_TARGET
public static final String
ENV_PROXY
public static final String
ENV_CONNECTION
public static final String
ENV_TARGET
public static final String
ENV_CONNECT_NAME_BASE
public static final String
ENV_ALIAS_MGR
public static final String
ENV_PROVIDERS
static final String
DEFAULT_CONNECTION_NAME
private static ConnectionMgrImpl
sConnectionMgr
private static com.sun.cli.jmx.support.AliasMgrMBean
sAliasMgr
Constructors Summary
JMXCmd(CmdEnv env)

	
	
	    
	
		super( env );
		
		env.put( ENV_ALIAS_MGR, sAliasMgr, false);
		
		// force initialization
	
Methods Summary
voidclearProxy()

		envRemove( ENV_PROXY );
	
java.lang.StringconnectionNameToEnvName(java.lang.String connectionName)

		return( ENV_CONNECT_NAME_BASE + connectionName );
	
static com.sun.cli.jmx.support.AliasMgrMBeancreateAliasMgr()

		final AliasMgrHashMapImpl	aliasMgrImpl	= new AliasMgrHashMapImpl();
		final AliasMgr				aliasMgr		= new AliasMgr( aliasMgrImpl );
		
		
		try
		{
			aliasMgrImpl.load( JMXAdminFileNames.getAliasesFile() );
			StandardAliasesIniter.init( aliasMgr );
		}
		catch( Exception e )
		{
			StandardAliasesIniter.init( aliasMgr );
			System.err.println( "can't load aliases file: " + e.getMessage());
			
		}
		return( aliasMgr );
	
java.lang.StringenvNameToConnectionName(java.lang.String envName)

		return( envName.substring( ENV_CONNECT_NAME_BASE.length(), envName.length() ) );
	
com.sun.cli.jmx.support.CLISupportMBeanProxyestablishProxy(java.lang.String name, ConnectInfo connectInfo)

		CLISupportMBeanProxy	proxy	= null;
		
		proxy	= setProxy( name, connectInfo );
		
		final String host		= connectInfo.getParam( JMXConnectorProvider.HOST );
		final String port		= connectInfo.getParam( JMXConnectorProvider.PORT );
		String protocol			= connectInfo.getParam( JMXConnectorProvider.PROTOCOL );
		if ( protocol == null )
		{
			protocol 	= "jmxmp";
		}
		
		println( "Established connection to " +
			host + ":" + port + " using " + protocol );

		return( proxy );
	
com.sun.cli.jmx.support.CLISupportMBeanProxyestablishProxy(ConnectInfo connectInfo)

		final String	envName	= connectionNameToEnvName( DEFAULT_CONNECTION_NAME );
		
		final CLISupportMBeanProxy	proxy	= establishProxy( envName , connectInfo );
		
		return( proxy );
	
voidestablishProxy()

		if ( envGet( ENV_PROXY ) == null )
		{
			final String	envName	= connectionNameToEnvName( DEFAULT_CONNECTION_NAME );
		
			final String connectString	= (String)envGet( envName );
			if ( connectString != null )
			{
				establishProxy( new ConnectInfo( connectString ) );
			}
		}
		
		if ( envGet( ENV_PROXY ) == null )
		{
			throw new java.io.IOException( "can't connect" );
		}
	
com.sun.cli.jmx.support.AliasMgrMBeangetAliasMgr()

		final AliasMgrMBean	proxy	= (AliasMgrMBean)envGet( ENV_ALIAS_MGR );
		
		return( proxy );
	
private com.sun.cli.jmx.support.CLISupportMBeangetCLISupport(javax.management.MBeanServerConnection conn)

		final CLISupportMBean		cliSupport		= new CLISupport( conn, sAliasMgr);
		
		return( cliSupport );
	
javax.management.MBeanServerConnectiongetConnection()

		final MBeanServerConnection	conn	= (MBeanServerConnection)envGet( ENV_CONNECTION );
		
		return( conn );
	
ConnectionMgrgetConnectionMgr()

		initConnectionMgr();
		return( sConnectionMgr );
	
java.lang.String[]getEnvTargets()

		final String	targetsEnv	= (String)envGet( ENV_TARGET );
		if ( targetsEnv == null )
			return( null );
		
		// convert to String []
		final String []	targets	= (String [])
							TargetPersister.DEFAULT.asObject( targetsEnv );
		
		return( targets );
	
com.sun.cli.jmx.support.CLISupportMBeanProxygetProxy()

		final CLISupportMBeanProxy	proxy	= (CLISupportMBeanProxy)envGet( ENV_PROXY );
		
		return( proxy );
	
java.lang.String[]getTargets()

		String [] 	targets	= getOperands();
		
		if ( targets.length == 0 )
		{
			targets	= getEnvTargets();
		}
		
		return( targets );
	
voidhandleException(java.lang.Exception e)

		super.handleException( e );
	
		if ( e instanceof java.io.IOException )
		{
			clearProxy();
		}
	
voidinitConnectionMgr()

		if ( sConnectionMgr != null )
			return;
			
		sConnectionMgr	= new ConnectionMgrImpl( );
		
		final String	providersString	= ((String)envGet( ENV_PROVIDERS, "")).trim();
		
		if ( providersString != null && providersString.length() != 0 )
		{
			final String []	providers	= providersString.split( "," );
			
			for( int i = 0; i < providers.length; ++i )
			{
				try
				{
					final Class	theClass	= Class.forName( providers[ i ] );
				
					sConnectionMgr.addProvider( theClass );
					println( "Added JMXConnectorProvider: " + providers[ i ] );
				}
				catch( Exception e )
				{
					printError( "WARNING: Can't add JMXConnectorProvider: " + providers[ i ] );
				}
			}
		}
	
voidpreExecute()

		getConnectionMgr();
		super.preExecute();
	
voidputEnvTargets(java.lang.String[] targets)

		// put targets into environment
		final String	targetsStr	= TargetPersister.DEFAULT.asString( targets );
		envPut( ENV_TARGET, targetsStr, true);
	
com.sun.cli.jmx.support.CLISupportMBeanProxysetProxy(java.lang.String name, ConnectInfo connectInfo)

		JMXConnector	jmxConnector	= null;
		
		try
		{
			jmxConnector	= getConnectionMgr().connect( name, connectInfo );
		}
		catch( java.io.IOException e )
		{
			throw new Exception( e.getMessage() + " (" + connectInfo.toString() + ")", e);
		}
		
		final MBeanServerConnection	managedServer	= jmxConnector.getMBeanServerConnection();

		final CLISupportMBean		cliSupport		= getCLISupport( managedServer );
			
		final CLISupportMBeanProxy	proxy	= new CLISupportMBeanProxy( sAliasMgr, cliSupport );
			
		envPut( connectionNameToEnvName( name ), connectInfo.toString(), true );
		envPut( ENV_PROXY, proxy, false );
		envPut( ENV_CONNECTION, managedServer, false );
		
		return( proxy );