Search in sources :

Example 6 with GetOpt

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

the class QueueFuse method main.

/**
     * Runs QueueFuse.
     * @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", "filter=", "purge=", "sasl-mechanism=" };
    try {
        boolean includeRingQueues = false;
        String connectionOptions = "{reconnect: true}";
        List<Pattern> filter = new ArrayList<Pattern>();
        float purge = 0.2f;
        GetOpt getopt = new GetOpt(args, "hf:p:", 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("-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("-p") || opt[0].equals("--purge")) {
                int percent = Integer.parseInt(opt[1]);
                if (percent < 0 || percent > 100) {
                    System.out.println(_usage);
                    System.exit(1);
                }
                purge = percent / 100.0f;
            } 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) {
            QueueFuse queueFuse = new QueueFuse(url, connectionOptions, filter, purge);
        }
    } catch (IllegalArgumentException e) {
        System.out.println(_usage);
        System.out.println(e.getMessage());
        System.exit(1);
    }
    try {
        // Block here
        Thread.currentThread().join();
    } catch (InterruptedException ie) {
    }
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) GetOpt(org.apache.qpid.qmf2.util.GetOpt)

Example 7 with GetOpt

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

the class ConnectionLogger method main.

/**
     * Runs ConnectionLogger.
     * @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=", "sasl-mechanism=" };
    try {
        String host = "localhost";
        String connectionOptions = "{reconnect: true}";
        boolean logQueues = false;
        GetOpt getopt = new GetOpt(args, "ha:q", 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("-q")) {
                logQueues = true;
            } else if (opt[0].equals("--sasl-mechanism")) {
                connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
            }
        }
        ConnectionLogger logger = new ConnectionLogger(host, connectionOptions, logQueues);
    } 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("ConnectionLogger 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