Package org.cyclopsgroup.jmxterm.cmd

Source Code of org.cyclopsgroup.jmxterm.cmd.DomainsCommand

package org.cyclopsgroup.jmxterm.cmd;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.cyclopsgroup.jcli.annotation.Cli;
import org.cyclopsgroup.jmxterm.Command;
import org.cyclopsgroup.jmxterm.Session;
import org.cyclopsgroup.jmxterm.io.RuntimeIOException;

/**
* List domains for JMX connection
*
* @author <a href="mailto:jiaqi.guo@gmail.com">Jiaqi Guo</a>
*/
@Cli( name = "domains", description = "List all available domain names" )
public class DomainsCommand
    extends Command
{
    /**
     * Get list of domains for current JMX connection
     *
     * @param session Current session
     * @return Sorted list of domain names
     * @throws IOException
     */
    static List<String> getCandidateDomains( Session session )
    {
        String[] domains;
        try
        {
            domains = session.getConnection().getServerConnection().getDomains();
        }
        catch ( IOException e )
        {
            throw new RuntimeIOException( "Couldn't get candate domains", e );
        }
        List<String> result = new ArrayList<String>( Arrays.asList( domains ) );
        Collections.sort( result );
        return result;
    }

    /**
     * @inheritDoc
     */
    @Override
    public void execute()
        throws IOException
    {
        Session session = getSession();

        session.output.printMessage( "following domains are available" );
        for ( String domain : getCandidateDomains( session ) )
        {
            session.output.println( domain );
        }
    }
}
TOP

Related Classes of org.cyclopsgroup.jmxterm.cmd.DomainsCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.