Methods Summary |
---|
void | establishProxy()
// defeat default behavior; this is the 'connect' command after all
|
void | executeInternal()
final String [] operands = getOperands();
// at least one argument
if ( operands.length > 1 )
{
throw new IllegalArgumentException( "requires 0 or 1 operands" );
}
if ( getBoolean( "list", null ) != null )
{
listNamedConnections();
println( "" );
listActiveConnections();
}
else if ( countOptions() == 0 )
{
if ( operands.length == 0 )
{
// connect to default connection
final ConnectInfo connectInfo = getDefaultConnectInfo();
if ( connectInfo != null )
{
handleNamedConnect( DEFAULT_CONNECTION_NAME );
}
else
{
printError( "No default connection available. Please specify a connect string.\n" );
printUsage();
}
}
else
{
// named connection
handleNamedConnect( operands[ 0 ] );
}
}
else
{
final String host = getString( "host", "localhost" );
final String port = getString( "port", null );
final String protocol = getString( "protocol", "jmxmp" );
final String user = getString( "user", null );
final String passwordFile = getString( "password-file", null );
final String options = getString( "options", null );
final HashMap params = new HashMap();
maybePut( params, JMXConnectorProvider.HOST, host );
maybePut( params, JMXConnectorProvider.PORT, port );
maybePut( params, JMXConnectorProvider.PROTOCOL, protocol );
maybePut( params, JMXConnectorProvider.USER, user );
maybePut( params, JMXConnectorProvider.PASSWORD_FILE, passwordFile );
final String connectionName = (operands.length > 0) ?
operands[ 0 ] : DEFAULT_CONNECTION_NAME;
handleConnect( connectionName, new ConnectInfo( params ) );
}
|
ConnectInfo | getDefaultConnectInfo()
final String envName = connectionNameToEnvName( DEFAULT_CONNECTION_NAME );
final String defaultString = (String)envGet( envName );
final ConnectInfo connectInfo = defaultString == null ?
null : new ConnectInfo( defaultString );
return( connectInfo );
|
public static java.lang.String[] | getNames()
return( new String [] { NAME, NAME_ABBREV } );
|
int | getNumRequiredOperands()
// require 1, by default
return( 0 );
|
ArgHelper.OptionsInfo | getOptionInfo()
return( new ArgHelperOptionsInfo( OPTIONS_INFO ) );
|
static com.sun.cli.jmx.spi.JMXConnectorProviderInfo | getProviderInfo(java.lang.Class theClass)
return( JMXConnectorProviderInfo.InfoGetter.getInfo( theClass ) );
|
public java.lang.String | getUsage()
final String usage = CmdStrings.CONNECT_HELP.toString();
String extra = null;
try
{
extra = "\n\nConnector usage:\n";
final JMXConnectorProvider [] providers = getConnectionMgr().getProviders();
for ( int i = 0; i < providers.length; ++i )
{
extra = extra + providers[ i ].getClass().getName() + ":\n";
final JMXConnectorProviderInfo info = getProviderInfo( providers[ i ].getClass() );
if ( info != null )
{
extra = extra + info.getUsage() + "\n";
}
else
{
extra = extra + "<none available>";
}
extra = extra + "\n";
}
}
catch( Exception e )
{
}
return( usage + extra );
|
void | handleConnect(java.lang.String name, ConnectInfo connectInfo)
envRemove( connectionNameToEnvName( name ) );
envPut( connectionNameToEnvName( name ), connectInfo.toString(), true);
handleNamedConnect( name );
|
void | handleNamedConnect(java.lang.String name)
// see if it's a name for an existing connection
final String connectString = (String)envGet( connectionNameToEnvName( name ) );
if ( connectString != null )
{
final ConnectInfo connectInfo = new ConnectInfo( connectString );
if ( connectInfo.equals( getConnectionMgr().getConnectInfo( name ) ) )
{
println( "Connection already active: " + connectInfo.toString() );
setProxy( name, connectInfo );
}
else
{
setProxy( name, connectInfo );
println( "Connection " + name +
" (" + connectInfo.toString() + ") is now the active connection" );
}
envPut( connectionNameToEnvName( DEFAULT_CONNECTION_NAME ), connectInfo.toString(), true);
}
else
{
printError( "ERROR: No such named connection: " + name );
}
|
boolean | isNamedConnection(java.lang.String name)
final String key = connectionNameToEnvName( name );
final String value = (String)envGet( key );
return( value != null );
|
boolean | isValidConnectionName(java.lang.String name)
return( name.indexOf( ':" ) < 0 && name.indexOf( '@" ) < 0 );
|
void | listActiveConnections()
println( "Active connections:" );
final ConnectionMgr mgr = getConnectionMgr();
final Iterator iter = mgr.getNames().iterator();
while ( iter.hasNext() )
{
final String name = (String)iter.next();
println( name + ": " + mgr.getConnectInfo( name ) );
}
|
void | listNamedConnections()
println( "Named connections:" );
final Iterator iter = getEnvKeys( ENV_CONNECT_NAME_BASE + ".+" ).iterator();
while ( iter.hasNext() )
{
final String envName = (String)iter.next();
final String value = (String)envGet( envName );
println( envNameToConnectionName( envName ) + ": " + new ConnectInfo( value ) );
}
|
static void | maybePut(java.util.Map m, java.lang.String key, java.lang.Object value)
if ( value != null )
{
m.put( key, value );
}
|