Search in sources :

Example 1 with GetOpt

use of org.apache.qpid.qmf2.util.GetOpt in project qpid by apache.

the class QpidCtrl method main.

/**
     * Runs QpidCtrl.
     * @param args the command line arguments.
     */
public static void main(final String[] args) {
    String logLevel = System.getProperty("amqj.logging.level");
    // Set default log level to FATAL rather than DEBUG.
    logLevel = (logLevel == null) ? "FATAL" : logLevel;
    System.setProperty("amqj.logging.level", logLevel);
    // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting.
    // Setting the following property to true makes it a Daemon Thread.
    System.setProperty("qpid.jms.daemon.dispatcher", "true");
    String[] longOpts = { "help", "broker-address=", "class=", "package=", "id=", "agent=", "sasl-mechanism=" };
    try {
        String host = "localhost";
        String connectionOptions = "{reconnect: true}";
        String cls = "broker";
        String pkg = "org.apache.qpid.broker";
        String id = "amqp-broker";
        String agentName = "qpidd";
        String command = null;
        String arg = null;
        GetOpt getopt = new GetOpt(args, "ha:c:p:i:v", longOpts);
        List<String[]> optList = getopt.getOptList();
        String[] cargs = {};
        cargs = getopt.getEncArgs().toArray(cargs);
        for (String[] opt : optList) {
            if (opt[0].equals("-h") || opt[0].equals("--help")) {
                System.out.println(_usage);
                System.out.println(_options);
                System.exit(1);
            } else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) {
                host = opt[1];
            } else if (opt[0].equals("-c") || opt[0].equals("--class")) {
                cls = opt[1];
            } else if (opt[0].equals("-p") || opt[0].equals("--package")) {
                pkg = opt[1];
            } else if (opt[0].equals("-i") || opt[0].equals("--id")) {
                id = opt[1];
            } else if (opt[0].equals("--agent")) {
                agentName = opt[1];
            } else if (opt[0].equals("-v")) {
                System.setProperty("amqj.logging.level", "DEBUG");
            } else if (opt[0].equals("--sasl-mechanism")) {
                connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
            }
        }
        if (cargs.length < 1 || cargs.length > 2) {
            System.out.println(Arrays.asList(cargs));
            System.out.println(_usage);
            System.exit(1);
        }
        command = cargs[0];
        if (cargs.length == 2) {
            arg = cargs[1];
            if (!arg.startsWith("{") || !arg.endsWith("}")) {
                System.out.println("Incorrect format for args.");
                System.out.println("This needs to be in a Stringified Map format similar to an Address String");
                System.exit(1);
            }
        }
        QpidCtrl qpidCtrl = new QpidCtrl(host, connectionOptions, pkg, cls, id, agentName, command, arg);
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt)

Example 2 with GetOpt

use of org.apache.qpid.qmf2.util.GetOpt in project qpid by apache.

the class QpidQueueStats method main.

/**
     * Runs QpidQueueStats.
     * @param args the command line arguments.
     */
public static void main(final String[] args) {
    String logLevel = System.getProperty("amqj.logging.level");
    // Set default log level to FATAL rather than DEBUG.
    logLevel = (logLevel == null) ? "FATAL" : logLevel;
    System.setProperty("amqj.logging.level", logLevel);
    String[] longOpts = { "help", "broker-address=", "filter=", "sasl-mechanism=" };
    try {
        String host = "localhost";
        String connectionOptions = "{reconnect: true}";
        List<Pattern> filter = new ArrayList<Pattern>();
        GetOpt getopt = new GetOpt(args, "ha:f:", longOpts);
        List<String[]> optList = getopt.getOptList();
        for (String[] opt : optList) {
            if (opt[0].equals("-h") || opt[0].equals("--help")) {
                System.out.println(_usage);
                System.out.println(_options);
                System.exit(1);
            } else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) {
                host = opt[1];
            } else if (opt[0].equals("-f") || opt[0].equals("--filter")) {
                String[] split = opt[1].split(",");
                for (String s : split) {
                    Pattern p = Pattern.compile(s);
                    filter.add(p);
                }
            } else if (opt[0].equals("--sasl-mechanism")) {
                connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
            }
        }
        QpidQueueStats queueStats = new QpidQueueStats(host, connectionOptions, filter);
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.out.println(e.getMessage());
        System.exit(1);
    }
    BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
    try {
        // Blocks here until return is pressed
        String s = commandLine.readLine();
        System.exit(0);
    } catch (IOException e) {
        System.out.println("QpidQueueStats main(): IOException: " + e.getMessage());
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt) Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 3 with GetOpt

use of org.apache.qpid.qmf2.util.GetOpt in project qpid by apache.

the class ConnectionAudit method main.

// End of readWhitelist()
/**
     * Runs ConnectionAudit.
     * @param args the command line arguments.
     */
public static void main(final String[] args) {
    String logLevel = System.getProperty("amqj.logging.level");
    // Set default log level to FATAL rather than DEBUG.
    logLevel = (logLevel == null) ? "FATAL" : logLevel;
    System.setProperty("amqj.logging.level", logLevel);
    String[] longOpts = { "help", "whitelist=", "sasl-mechanism=" };
    try {
        String connectionOptions = "{reconnect: true}";
        String whitelist = "./whitelist.xml";
        GetOpt getopt = new GetOpt(args, "h", longOpts);
        List<String[]> optList = getopt.getOptList();
        String[] cargs = {};
        cargs = getopt.getEncArgs().toArray(cargs);
        for (String[] opt : optList) {
            if (opt[0].equals("-h") || opt[0].equals("--help")) {
                System.out.println(_usage);
                System.out.println(_description);
                System.out.println(_options);
                System.exit(1);
            } else if (opt[0].equals("--whitelist")) {
                whitelist = opt[1];
            } else if (opt[0].equals("--sasl-mechanism")) {
                connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
            }
        }
        int nargs = cargs.length;
        if (nargs == 0) {
            cargs = new String[] { "localhost" };
        }
        for (String url : cargs) {
            ConnectionAudit eventPrinter = new ConnectionAudit(url, connectionOptions, whitelist);
        }
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.exit(1);
    }
    try {
        // Block here
        Thread.currentThread().join();
    } catch (InterruptedException ie) {
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt)

Example 4 with GetOpt

use of org.apache.qpid.qmf2.util.GetOpt in project qpid by apache.

the class QpidRestAPI method main.

/**
     * Runs QpidRestAPI.
     * @param args the command line arguments.
     */
public static void main(String[] args) throws IOException {
    String logLevel = System.getProperty("amqj.logging.level");
    // Set default log level to FATAL rather than DEBUG.
    logLevel = (logLevel == null) ? "FATAL" : logLevel;
    System.setProperty("amqj.logging.level", logLevel);
    String[] longOpts = { "help", "host=", "port=", "backlog=", "webroot=" };
    try {
        String addr = null;
        int port = 8080;
        String broker = null;
        int backlog = 10;
        String webroot = "qpid-web";
        GetOpt getopt = new GetOpt(args, "ha:i:p:b:w:", longOpts);
        List<String[]> optList = getopt.getOptList();
        String[] cargs = {};
        cargs = getopt.getEncArgs().toArray(cargs);
        for (String[] opt : optList) {
            if (opt[0].equals("-h") || opt[0].equals("--help")) {
                System.out.println(_usage);
                System.out.println(_description);
                System.out.println(_options);
                System.exit(1);
            } else if (opt[0].equals("-a") || opt[0].equals("--broker-addr")) {
                broker = opt[1];
            } else if (opt[0].equals("-i") || opt[0].equals("--addr")) {
                addr = opt[1];
            } else if (opt[0].equals("-p") || opt[0].equals("--port")) {
                port = Integer.parseInt(opt[1]);
            } else if (opt[0].equals("-b") || opt[0].equals("--backlog")) {
                backlog = Integer.parseInt(opt[1]);
            } else if (opt[0].equals("-w") || opt[0].equals("--webroot")) {
                webroot = opt[1];
            }
        }
        QpidRestAPI restAPI = new QpidRestAPI(addr, port, broker, backlog, webroot);
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt)

Example 5 with GetOpt

use of org.apache.qpid.qmf2.util.GetOpt in project qpid by apache.

the class QpidPrintEvents method main.

/**
     * Runs QpidPrintEvents.
     * @param args the command line arguments.
     */
public static void main(final String[] args) {
    String logLevel = System.getProperty("amqj.logging.level");
    // Set default log level to FATAL rather than DEBUG.
    logLevel = (logLevel == null) ? "FATAL" : logLevel;
    System.setProperty("amqj.logging.level", logLevel);
    String[] longOpts = { "help", "heartbeats", "sasl-mechanism=" };
    try {
        String connectionOptions = "{reconnect: true}";
        GetOpt getopt = new GetOpt(args, "h", longOpts);
        List<String[]> optList = getopt.getOptList();
        String[] cargs = {};
        cargs = getopt.getEncArgs().toArray(cargs);
        for (String[] opt : optList) {
            if (opt[0].equals("-h") || opt[0].equals("--help")) {
                System.out.println(_usage);
                System.out.println(_description);
                System.out.println(_options);
                System.exit(1);
            } else if (opt[0].equals("--heartbeats")) {
            // Ignore Java uses heartbeats by default
            } else if (opt[0].equals("--sasl-mechanism")) {
                connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
            }
        }
        int nargs = cargs.length;
        if (nargs == 0) {
            cargs = new String[] { "localhost" };
        }
        for (String url : cargs) {
            QpidPrintEvents eventPrinter = new QpidPrintEvents(url, connectionOptions);
        }
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.exit(1);
    }
    BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
    try {
        // Blocks here until return is pressed
        System.out.println("Hit Return to exit");
        String s = commandLine.readLine();
        System.exit(0);
    } catch (IOException e) {
        System.out.println("QpidPrintEvents main(): IOException: " + e.getMessage());
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

GetOpt (org.apache.qpid.qmf2.util.GetOpt)7 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)2 Pattern (java.util.regex.Pattern)2