<commit_before>/*
 *  Copyright 2007-2011 Zuse Institute Berlin
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package de.zib.scalaris;

import java.lang.management.ManagementFactory;
import java.text.DecimalFormat;
import java.util.Comparator;
import java.util.HashSet;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import de.zib.scalaris.Monitor.GetNodeInfoResult;
import de.zib.scalaris.Monitor.GetNodePerformanceResult;
import de.zib.scalaris.Monitor.GetServiceInfoResult;
import de.zib.scalaris.Monitor.GetServicePerformanceResult;

/**
 * Class to test basic functionality of the package and to use scalaris
 * from command line.
 *
 * @author <NAME>, <EMAIL>
 * @version 2.0
 * @since 2.0
 */
public class Main {
    /**
     * Queries the command line options for an action to perform.
     *
     * <pre>
     * <code>
     * > java -jar scalaris.jar --help
     * usage: scalaris [Options]
     *  -h,--help                                   print this message
     *  -v,--verbose                                print verbose information,
     *                                              e.g. the properties read
     *  -lh,--localhost                             gets the local host's name as
     *                                              known to Java (for debugging
     *                                              purposes)
     *  -b,--minibench <[ops]> <[tpn]> <[benchs]>   run selected mini
     *                                              benchmark(s) [1|...|18|all]
     *                                              (default: all benchmarks, 500
     *                                              operations, 10 threads per
     *                                              Scalaris node)
     *  -m,--monitor <node>                         print monitoring information
     *  -r,--read <key>                             read an item
     *  -w,--write <key> <value>                    write an item
     *     --test-and-set <key> <old> <new>         atomic test and set, i.e.
     *                                              write <key> to <new> if the
     *                                              current value is <old>
     *  -d,--delete <key> <[timeout]>               delete an item (default
     *                                              timeout: 2000ms)
     *                                              WARNING: This function can
     *                                              lead to inconsistent data
     *                                              (e.g. deleted items can
     *                                              re-appear). Also when
     *                                              re-creating an item the
     *                                              version before the delete can
     *                                              re-appear.
     *  -jmx,--jmxservice <node>                    starts a service exposing
     *                                              Scalaris monitoring values
     *                                              via JMX
     * </code>
     * </pre>
     *
     * In order to override node and cookie to use for a connection, specify
     * the <tt>scalaris.node</tt> or <tt>scalaris.cookie</tt> system properties.
     * Their values will be used instead of the values defined in the config
     * file!
     *
     * @param args
     *            command line arguments
     */
    public static void main(final String[] args) {
        boolean verbose = false;
        final CommandLineParser parser = new GnuParser();
        CommandLine line = null;
        final Options options = getOptions();
        try {
            line = parser.parse(options, args);
        } catch (final ParseException e) {
            printException("Parsing failed", e, false);
            return; // will not be reached since printException exits
        }

        if (line.hasOption("verbose")) {
            verbose = true;
            ConnectionFactory.getInstance().printProperties();
        }

        if (line.hasOption("minibench")) {
            final String[] optionValues = line.getOptionValues("minibench");
            int nrOperations = 500;
            int threadsPerNode = 10;
            final HashSet<Integer> benchmarks = new HashSet<Integer>(10);
            boolean all = false;
            if (optionValues != null) {
                checkArguments(optionValues, 0, options, "b");
                if (optionValues.length >= 1) {
                    nrOperations = Integer.parseInt(optionValues[0]);
                }
                if (optionValues.length >= 2) {
                    threadsPerNode = Integer.parseInt(optionValues[1]);
                }
                if (optionValues.length >= 3) {
                    for (int i = 2; i < Math.min(20, optionValues.length); ++i) {
                        final String benchmarks_str = optionValues[i];
                        if (benchmarks_str.equals("all")) {
                            all = true;
                        } else {
                            benchmarks.add(Integer.parseInt(benchmarks_str));
                        }
                    }
                }
            } else {
                all = true;<commit_msg>Java-API: run all benchmarks if no individual list is given<commit_after>/*
 *  Copyright 2007-2011 Zuse Institute Berlin
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package de.zib.scalaris;

import java.lang.management.ManagementFactory;
import java.text.DecimalFormat;
import java.util.Comparator;
import java.util.HashSet;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import de.zib.scalaris.Monitor.GetNodeInfoResult;
import de.zib.scalaris.Monitor.GetNodePerformanceResult;
import de.zib.scalaris.Monitor.GetServiceInfoResult;
import de.zib.scalaris.Monitor.GetServicePerformanceResult;

/**
 * Class to test basic functionality of the package and to use scalaris
 * from command line.
 *
 * @author <NAME>, <EMAIL>
 * @version 2.0
 * @since 2.0
 */
public class Main {
    /**
     * Queries the command line options for an action to perform.
     *
     * <pre>
     * <code>
     * > java -jar scalaris.jar --help
     * usage: scalaris [Options]
     *  -h,--help                                   print this message
     *  -v,--verbose                                print verbose information,
     *                                              e.g. the properties read
     *  -lh,--localhost                             gets the local host's name as
     *                                              known to Java (for debugging
     *                                              purposes)
     *  -b,--minibench <[ops]> <[tpn]> <[benchs]>   run selected mini
     *                                              benchmark(s) [1|...|18|all]
     *                                              (default: all benchmarks, 500
     *                                              operations, 10 threads per
     *                                              Scalaris node)
     *  -m,--monitor <node>                         print monitoring information
     *  -r,--read <key>                             read an item
     *  -w,--write <key> <value>                    write an item
     *     --test-and-set <key> <old> <new>         atomic test and set, i.e.
     *                                              write <key> to <new> if the
     *                                              current value is <old>
     *  -d,--delete <key> <[timeout]>               delete an item (default
     *                                              timeout: 2000ms)
     *                                              WARNING: This function can
     *                                              lead to inconsistent data
     *                                              (e.g. deleted items can
     *                                              re-appear). Also when
     *                                              re-creating an item the
     *                                              version before the delete can
     *                                              re-appear.
     *  -jmx,--jmxservice <node>                    starts a service exposing
     *                                              Scalaris monitoring values
     *                                              via JMX
     * </code>
     * </pre>
     *
     * In order to override node and cookie to use for a connection, specify
     * the <tt>scalaris.node</tt> or <tt>scalaris.cookie</tt> system properties.
     * Their values will be used instead of the values defined in the config
     * file!
     *
     * @param args
     *            command line arguments
     */
    public static void main(final String[] args) {
        boolean verbose = false;
        final CommandLineParser parser = new GnuParser();
        CommandLine line = null;
        final Options options = getOptions();
        try {
            line = parser.parse(options, args);
        } catch (final ParseException e) {
            printException("Parsing failed", e, false);
            return; // will not be reached since printException exits
        }

        if (line.hasOption("verbose")) {
            verbose = true;
            ConnectionFactory.getInstance().printProperties();
        }

        if (line.hasOption("minibench")) {
            final String[] optionValues = line.getOptionValues("minibench");
            int nrOperations = 500;
            int threadsPerNode = 10;
            final HashSet<Integer> benchmarks = new HashSet<Integer>(18);
            boolean all = true;
            if (optionValues != null) {
                checkArguments(optionValues, 0, options, "b");
                if (optionValues.length >= 1) {
                    nrOperations = Integer.parseInt(optionValues[0]);
                }
                if (optionValues.length >= 2) {
                    threadsPerNode = Integer.parseInt(optionValues[1]);
                }
                if (optionValues.length >= 3) {
                    all = false;
                    for (int i = 2; i < Math.min(20, optionValues.length); ++i) {
                        final String benchmarks_str = optionValues[i];
                        if (benchmarks_str.equals("all")) {
                            all = true;
                        } else {
                            benchmarks.add(Integer.parseInt(benchmarks_str));
                        }
                    }
                }
{'fraction_non_alphanumeric': 0.08511638843169528, 'fraction_numerical': 0.006897092248608825, 'mean_word_length': 1.374395236323037, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 78, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4213680', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2894, 'n_words': 897}