All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cyclopsgroup.jmxterm.cmd.DomainsCommand Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
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 Jiaqi Guo
 */
@Cli(name = "domains", description = "List all available domain names")
public class DomainsCommand extends Command {
  /**
   * Gets list of domains for current JMX connection.
   */
  static List getCandidateDomains(Session session) {
    String[] domains;
    try {
      domains = session.getConnection().getServerConnection().getDomains();
    } catch (IOException e) {
      throw new RuntimeIOException("Couldn't get candate domains", e);
    }
    List result = new ArrayList(Arrays.asList(domains));
    Collections.sort(result);
    return result;
  }

  @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);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy