Example usage for java.lang Integer MAX_VALUE

List of usage examples for java.lang Integer MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MAX_VALUE.

Prototype

int MAX_VALUE

To view the source code for java.lang Integer MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value an int can have, 231-1.

Usage

From source file:com.asakusafw.compiler.bootstrap.BatchCompilerDriver.java

/**
 * The program entry./*from  w  ww  .  ja v a 2 s.c om*/
 * @param args command line arguments
 */
public static void main(String... args) {
    try {
        if (start(args) == false) {
            System.exit(1);
        }
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(Integer.MAX_VALUE);
        formatter.printHelp(MessageFormat.format("java -classpath ... {0}", //$NON-NLS-1$
                BatchCompilerDriver.class.getName()), OPTIONS, true);
        e.printStackTrace(System.out);
        System.exit(1);
    }
}

From source file:hack.VectorScan.java

public static void main(String[] args) throws Exception {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option seqOpt = obuilder.withLongName("seqFile").withRequired(false)
            .withArgument(abuilder.withName("seqFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The Sequence File containing the Clusters").withShortName("s").create();
    Option outputOpt = obuilder.withLongName("output").withRequired(false)
            .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create())
            .withDescription("The output file.  If not specified, dumps to the console").withShortName("o")
            .create();/*w  w w. ja va 2 s.c  o m*/
    Option substringOpt = obuilder.withLongName("substring").withRequired(false)
            .withArgument(abuilder.withName("substring").withMinimum(1).withMaximum(1).create())
            .withDescription("The number of chars of the asFormatString() to print").withShortName("b")
            .create();
    Option countOpt = obuilder.withLongName("count").withRequired(false)
            .withDescription("Report the count only").withShortName("c").create();
    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();

    Group group = gbuilder.withName("Options").withOption(seqOpt).withOption(outputOpt).withOption(substringOpt)
            .withOption(countOpt).withOption(helpOpt).create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {

            printHelp(group);
            return;
        }

        boolean doCount = false;
        if (cmdLine.hasOption(countOpt))
            doCount = true;

        if (cmdLine.hasOption(seqOpt)) {
            Path path = new Path(cmdLine.getValue(seqOpt).toString());
            Configuration conf = new Configuration();
            FileSystem fs = FileSystem.get(path.toUri(), conf);
            SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf);
            int start = 4;
            int end = 5;
            int samples = 1000;
            SimplexSpace<String>[] spaces = makeSpaces(start, end, doCount);
            try {
                int sub = Integer.MAX_VALUE;
                if (cmdLine.hasOption(substringOpt)) {
                    sub = Integer.parseInt(cmdLine.getValue(substringOpt).toString());
                }
                Text key = (Text) reader.getKeyClass().asSubclass(Writable.class).newInstance();
                VectorWritable value = (VectorWritable) reader.getValueClass().asSubclass(Writable.class)
                        .newInstance();
                int count = 0;
                while (reader.next(key, value)) {
                    String text = key.toString();
                    Vector v = value.get();
                    //            int size = v.size();
                    //            int density = v.getNumNondefaultElements();
                    //            System.out.println(size + "," + density);
                    addSpaces(spaces, start, text, v);
                    count++;
                    if (count % 1000 == 0)
                        System.out.print(".");
                    if (count == samples)
                        break;
                }
                if (doCount)
                    printSpacesCounts(spaces, start, samples);
                else
                    printSpacesFull(spaces, start, samples);
            } finally {
            }
        }

    } catch (OptionException e) {
        log.error("Exception", e);
        printHelp(group);
    }

}

From source file:com.hazelcast.jet.benchmark.trademonitor.FlinkTradeMonitor.java

public static void main(String[] args) throws Exception {
    if (args.length != 13) {
        System.err.println("Usage:");
        System.err.println("  " + FlinkTradeMonitor.class.getSimpleName()
                + " <bootstrap.servers> <topic> <offset-reset> <maxLagMs> <windowSizeMs> <slideByMs> <outputPath> <checkpointInterval> <checkpointUri> <doAsyncSnapshot> <stateBackend> <kafkaParallelism> <windowParallelism>");
        System.err.println("<stateBackend> - fs | rocksDb");
        System.exit(1);//from w  w  w  .j a v a  2s.c o  m
    }
    String brokerUri = args[0];
    String topic = args[1];
    String offsetReset = args[2];
    int lagMs = Integer.parseInt(args[3]);
    int windowSize = Integer.parseInt(args[4]);
    int slideBy = Integer.parseInt(args[5]);
    String outputPath = args[6];
    int checkpointInt = Integer.parseInt(args[7]);
    String checkpointUri = args[8];
    boolean doAsyncSnapshot = Boolean.parseBoolean(args[9]);
    String stateBackend = args[10];
    int kafkaParallelism = Integer.parseInt(args[11]);
    int windowParallelism = Integer.parseInt(args[12]);

    System.out.println("bootstrap.servers: " + brokerUri);
    System.out.println("topic: " + topic);
    System.out.println("offset-reset: " + offsetReset);
    System.out.println("lag: " + lagMs);
    System.out.println("windowSize: " + windowSize);
    System.out.println("slideBy: " + slideBy);
    System.out.println("outputPath: " + outputPath);
    System.out.println("checkpointInt: " + checkpointInt);
    System.out.println("checkpointUri: " + checkpointUri);
    System.out.println("doAsyncSnapshot: " + doAsyncSnapshot);
    System.out.println("stateBackend: " + stateBackend);
    System.out.println("kafkaParallelism: " + kafkaParallelism);
    System.out.println("windowParallelism: " + windowParallelism);

    // set up the execution environment
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
    if (checkpointInt > 0) {
        env.enableCheckpointing(checkpointInt);
        env.getCheckpointConfig().setMinPauseBetweenCheckpoints(checkpointInt);
    }
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 5000));
    if ("fs".equalsIgnoreCase(stateBackend)) {
        env.setStateBackend(new FsStateBackend(checkpointUri, doAsyncSnapshot));
    } else if ("rocksDb".equalsIgnoreCase(stateBackend)) {
        env.setStateBackend(new RocksDBStateBackend(checkpointUri));
    } else {
        System.err.println("Bad value for stateBackend: " + stateBackend);
        System.exit(1);
    }

    DeserializationSchema<Trade> schema = new AbstractDeserializationSchema<Trade>() {
        TradeDeserializer deserializer = new TradeDeserializer();

        @Override
        public Trade deserialize(byte[] message) throws IOException {
            return deserializer.deserialize(null, message);
        }
    };

    DataStreamSource<Trade> trades = env
            .addSource(new FlinkKafkaConsumer010<>(topic, schema, getKafkaProperties(brokerUri, offsetReset)))
            .setParallelism(kafkaParallelism);
    AssignerWithPeriodicWatermarks<Trade> timestampExtractor = new BoundedOutOfOrdernessTimestampExtractor<Trade>(
            Time.milliseconds(lagMs)) {
        @Override
        public long extractTimestamp(Trade element) {
            return element.getTime();
        }
    };

    WindowAssigner window = windowSize == slideBy ? TumblingEventTimeWindows.of(Time.milliseconds(windowSize))
            : SlidingEventTimeWindows.of(Time.milliseconds(windowSize), Time.milliseconds(slideBy));

    trades.assignTimestampsAndWatermarks(timestampExtractor).keyBy((Trade t) -> t.getTicker()).window(window)
            .aggregate(new AggregateFunction<Trade, MutableLong, Long>() {

                @Override
                public MutableLong createAccumulator() {
                    return new MutableLong();
                }

                @Override
                public MutableLong add(Trade value, MutableLong accumulator) {
                    accumulator.increment();
                    return accumulator;
                }

                @Override
                public MutableLong merge(MutableLong a, MutableLong b) {
                    a.setValue(Math.addExact(a.longValue(), b.longValue()));
                    return a;
                }

                @Override
                public Long getResult(MutableLong accumulator) {
                    return accumulator.longValue();
                }
            }, new WindowFunction<Long, Tuple5<String, String, Long, Long, Long>, String, TimeWindow>() {
                @Override
                public void apply(String key, TimeWindow window, Iterable<Long> input,
                        Collector<Tuple5<String, String, Long, Long, Long>> out) throws Exception {
                    long timeMs = System.currentTimeMillis();
                    long count = input.iterator().next();
                    long latencyMs = timeMs - window.getEnd() - lagMs;
                    out.collect(
                            new Tuple5<>(Instant.ofEpochMilli(window.getEnd()).atZone(ZoneId.systemDefault())
                                    .toLocalTime().toString(), key, count, timeMs, latencyMs));
                }
            }).setParallelism(windowParallelism).writeAsCsv(outputPath, WriteMode.OVERWRITE);

    env.execute("Trade Monitor Example");
}

From source file:org.dspace.app.cris.batch.ScriptDeleteRP.java

/**
 * Batch script to delete a RP. See the technical documentation for further
 * details./*  w  ww  . j a  v  a2s .c  o  m*/
 */
public static void main(String[] args) {
    log.info("#### START DELETE: -----" + new Date() + " ----- ####");
    Context dspaceContext = null;
    ApplicationContext context = null;
    try {
        dspaceContext = new Context();
        dspaceContext.turnOffAuthorisationSystem();

        DSpace dspace = new DSpace();
        ApplicationService applicationService = dspace.getServiceManager()
                .getServiceByName("applicationService", ApplicationService.class);

        CommandLineParser parser = new PosixParser();

        Options options = new Options();
        options.addOption("h", "help", false, "help");

        options.addOption("r", "researcher", true, "RP id to delete");

        options.addOption("s", "silent", false, "no interactive mode");

        CommandLine line = parser.parse(options, args);

        if (line.hasOption('h')) {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("ScriptHKURPDelete \n", options);
            System.out.println("\n\nUSAGE:\n ScriptHKURPDelete -r <id> \n");
            System.out.println("Please note: add -s for no interactive mode");
            System.exit(0);
        }

        Integer rpId = null;
        boolean delete = false;
        boolean silent = line.hasOption('s');
        Item[] items = null;
        if (line.hasOption('r')) {
            rpId = ResearcherPageUtils.getRealPersistentIdentifier(line.getOptionValue("r"),
                    ResearcherPage.class);
            ResearcherPage rp = applicationService.get(ResearcherPage.class, rpId);

            if (rp == null) {
                if (!silent) {
                    System.out.println("RP not exist...exit");
                }
                log.info("RP not exist...exit");
                System.exit(0);
            }

            log.info("Use browse indexing");

            BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex);
            // now start up a browse engine and get it to do the work for us
            BrowseEngine be = new BrowseEngine(dspaceContext);

            String authKey = ResearcherPageUtils.getPersistentIdentifier(rp);

            // set up a BrowseScope and start loading the values into it
            BrowserScope scope = new BrowserScope(dspaceContext);
            scope.setBrowseIndex(bi);
            // scope.setOrder(order);
            scope.setFilterValue(authKey);
            scope.setAuthorityValue(authKey);
            scope.setResultsPerPage(Integer.MAX_VALUE);
            scope.setBrowseLevel(1);

            BrowseInfo binfo = be.browse(scope);
            log.debug("Find " + binfo.getResultCount() + "item(s) for the reseracher " + authKey);
            items = binfo.getItemResults(dspaceContext);

            if (!silent && rp != null) {
                System.out.println(MESSAGE_ONE);

                // interactive mode
                System.out.println("Attempting to remove Researcher Page:");
                System.out.println("StaffNo:" + rp.getSourceID());
                System.out.println("FullName:" + rp.getFullName());
                System.out
                        .println("the researcher has " + items.length + " relation(s) with item(s) in the HUB");
                System.out.println();

                System.out.println(QUESTION_ONE);
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader reader = new BufferedReader(isr);
                String answer = reader.readLine();
                if (answer.equals("yes")) {
                    delete = true;
                } else {
                    System.out.println("Exit without delete");
                    log.info("Exit without delete");
                    System.exit(0);
                }

            } else {
                delete = true;
            }
        } else {
            System.out.println("\n\nUSAGE:\n ScriptHKURPDelete <-v> -r <RPid> \n");
            System.out.println("-r option is mandatory");
            log.error("-r option is mandatory");
            System.exit(1);
        }

        if (delete) {
            if (!silent) {
                System.out.println("Deleting...");
            }
            log.info("Deleting...");
            cleanAuthority(dspaceContext, items, rpId);
            applicationService.delete(ResearcherPage.class, rpId);
            dspaceContext.complete();
        }

        if (!silent) {
            System.out.println("Ok...Bye");
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        if (dspaceContext != null && dspaceContext.isValid()) {
            dspaceContext.abort();
        }
        if (context != null) {
            context.publishEvent(new ContextClosedEvent(context));
        }
    }
    log.info("#### END: -----" + new Date() + " ----- ####");
    System.exit(0);
}

From source file:com.yobidrive.diskmap.buckets.BucketFNVHash.java

public static void main(String[] args) {
    // need to pass Ethernet address; can either use real one (shown here)
    EthernetAddress nic = EthernetAddress.fromInterface();
    // or bogus which would be gotten with: EthernetAddress.constructMulticastAddress()
    TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(nic);
    // also: we don't specify synchronizer, getting an intra-JVM syncer; there is
    // also external file-locking-based synchronizer if multiple JVMs run JUG

    int numIterations = 4096 * 16 * 24;
    int numBuckets = 4096 * 16 * 2;
    ;/*  w w  w . j ava2 s  .c  o m*/
    int[] buckets = new int[numBuckets];
    BucketFNVHash hash = new BucketFNVHash(numBuckets);
    long smallest = Integer.MAX_VALUE;
    long biggest = Integer.MIN_VALUE;
    int collisionsI = 0;
    int collisions6 = 0;
    int collisions2 = 0;
    int collisions3 = 0;
    int collisions4 = 0;
    int collisions5 = 0;
    long smallestI = Integer.MAX_VALUE;
    long biggestI = Integer.MIN_VALUE;
    int counter = 0;
    int maxCols = 0;

    for (int i = 0; i < numIterations; i++) {
        String key = uuidGenerator.generate().toString();
        long valVoldemort = Math.abs(hash.hashVoldemort(key.getBytes()));
        if (valVoldemort < smallest)
            smallest = valVoldemort;
        if (valVoldemort > biggest)
            biggest = valVoldemort;

        long partition = valVoldemort % 16; // 16 partitions
        if (partition == 7) {
            counter++; // 1 more in partition
            int val = (int) hash.hash(key.getBytes());
            if (val < smallestI)
                smallestI = val;
            if (val > biggestI)
                biggestI = val;
            buckets[val]++;
            if (buckets[val] > maxCols)
                maxCols = buckets[val];
            if (buckets[val] > 1) {
                collisionsI++;
            }
            if (buckets[val] == 2) {
                collisions2++;
            }
            if (buckets[val] == 3) {
                collisions3++;
            }
            if (buckets[val] == 4) {
                collisions4++;
            }
            if (buckets[val] == 5) {
                collisions5++;
            }
            if (buckets[val] > 5) {
                collisions6++;
            }
        }

    }

    System.out.println("Smallest=" + smallest + ", Biggest=" + biggest + ", SmallestI=" + smallestI
            + ", BiggestI=" + biggestI + "/" + numBuckets + ", Partition rate="
            + ((float) counter / numIterations * 100) + "% (target 6,25%), Collision rate="
            + ((float) collisionsI * 100 / counter) + "%, Fill rate" + ((float) counter / numBuckets * 100)
            + ", Max cols=" + (maxCols - 1));
    System.out.println("Chains 2:" + ((float) collisions2 * 100 / collisionsI) + ", 3:"
            + ((float) collisions3 * 100 / collisionsI) + ", 4:" + ((float) collisions4 * 100 / collisionsI)
            + ", 5:" + ((float) collisions5 * 100 / collisionsI) + ", 6:"
            + ((float) collisions6 * 100 / collisionsI));
}

From source file:com.alibaba.rocketmq.example.benchmark.Producer.java

public static void main(String[] args) throws MQClientException, UnsupportedEncodingException {

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    CommandLine commandLine = ServerUtil.parseCmdLine("producer", args, buildCommandlineOptions(options),
            new PosixParser());
    if (null == commandLine) {
        System.exit(-1);//from  w  ww  .ja  v  a2 s.  c o  m
    }

    final int threadCount = commandLine.hasOption('t') ? Integer.parseInt(commandLine.getOptionValue('t')) : 64;
    final int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s'))
            : 128;
    final boolean keyEnable = commandLine.hasOption('k') ? Boolean.parseBoolean(commandLine.getOptionValue('k'))
            : false;

    System.out.printf("threadCount %d messageSize %d keyEnable %s%n", threadCount, messageSize, keyEnable);

    final Logger log = ClientLogger.getLog();

    final Message msg = buildMessage(messageSize);

    final ExecutorService sendThreadPool = Executors.newFixedThreadPool(threadCount);

    final StatsBenchmarkProducer statsBenchmark = new StatsBenchmarkProducer();

    final Timer timer = new Timer("BenchmarkTimerThread", true);

    final LinkedList<Long[]> snapshotList = new LinkedList<Long[]>();

    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            snapshotList.addLast(statsBenchmark.createSnapshot());
            if (snapshotList.size() > 10) {
                snapshotList.removeFirst();
            }
        }
    }, 1000, 1000);

    timer.scheduleAtFixedRate(new TimerTask() {
        private void printStats() {
            if (snapshotList.size() >= 10) {
                Long[] begin = snapshotList.getFirst();
                Long[] end = snapshotList.getLast();

                final long sendTps = (long) (((end[3] - begin[3]) / (double) (end[0] - begin[0])) * 1000L);
                final double averageRT = ((end[5] - begin[5]) / (double) (end[3] - begin[3]));

                System.out.printf(
                        "Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d%n"//
                , sendTps//
                , statsBenchmark.getSendMessageMaxRT().get()//
                , averageRT//
                , end[2]//
                , end[4]//
                );
            }
        }

        @Override
        public void run() {
            try {
                this.printStats();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 10000, 10000);

    final DefaultMQProducer producer = new DefaultMQProducer("benchmark_producer");
    producer.setInstanceName(Long.toString(System.currentTimeMillis()));

    if (commandLine.hasOption('n')) {
        String ns = commandLine.getOptionValue('n');
        producer.setNamesrvAddr(ns);
    }

    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);

    producer.start();

    for (int i = 0; i < threadCount; i++) {
        sendThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        final long beginTimestamp = System.currentTimeMillis();
                        if (keyEnable) {
                            msg.setKeys(String.valueOf(beginTimestamp / 1000));
                        }
                        producer.send(msg);
                        statsBenchmark.getSendRequestSuccessCount().incrementAndGet();
                        statsBenchmark.getReceiveResponseSuccessCount().incrementAndGet();
                        final long currentRT = System.currentTimeMillis() - beginTimestamp;
                        statsBenchmark.getSendMessageSuccessTimeTotal().addAndGet(currentRT);
                        long prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        while (currentRT > prevMaxRT) {
                            boolean updated = statsBenchmark.getSendMessageMaxRT().compareAndSet(prevMaxRT,
                                    currentRT);
                            if (updated)
                                break;

                            prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        }
                    } catch (RemotingException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);

                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e1) {
                        }
                    } catch (InterruptedException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e1) {
                        }
                    } catch (MQClientException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                    } catch (MQBrokerException e) {
                        statsBenchmark.getReceiveResponseFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e1) {
                        }
                    }
                }
            }
        });
    }
}

From source file:iac.cnr.it.TestSearcher.java

public static void main(String[] args) throws IOException, ParseException {
    /** Command line parser and options */
    CommandLineParser parser = new PosixParser();

    Options options = new Options();
    options.addOption(OPT_INDEX, true, "Index path");
    options.addOption(OPT_QUERY, true, "The query");

    CommandLine cmd = null;/*from w  ww .ja va 2  s. c  om*/
    try {
        cmd = parser.parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        logger.fatal("Error while parsing command line arguments");
        System.exit(1);
    }

    /** Check for mandatory options */
    if (!cmd.hasOption(OPT_INDEX) || !cmd.hasOption(OPT_QUERY)) {
        usage();
        System.exit(0);
    }

    /** Read options */
    File casePath = new File(cmd.getOptionValue(OPT_INDEX));
    String query = cmd.getOptionValue(OPT_QUERY);

    /** Check correctness of the path containing an ISODAC case */
    if (!casePath.exists() || !casePath.isDirectory()) {
        logger.fatal("The case directory \"" + casePath.getAbsolutePath() + "\" is not valid");
        System.exit(1);
    }

    /** Check existance of the info.dat file */
    File infoFile = new File(casePath, INFO_FILENAME);
    if (!infoFile.exists()) {
        logger.fatal("Can't find " + INFO_FILENAME + " within the case directory (" + casePath + ")");
        System.exit(1);
    }

    /** Load the mapping image_uuid --> image_filename */
    imagesMap = new HashMap<Integer, String>();
    BufferedReader reader = new BufferedReader(new FileReader(infoFile));
    while (reader.ready()) {
        String line = reader.readLine();

        logger.info("Read the line: " + line);
        String currentID = line.split("\t")[0];
        String currentImgFile = line.split("\t")[1];
        imagesMap.put(Integer.parseInt(currentID), currentImgFile);
        logger.info("ID: " + currentID + " - IMG: " + currentImgFile + " added to the map");

    }
    reader.close();

    /** Load all the directories containing an index */
    ArrayList<String> indexesDirs = new ArrayList<String>();
    for (File f : casePath.listFiles()) {
        logger.info("Analyzing: " + f);
        if (f.isDirectory())
            indexesDirs.add(f.getAbsolutePath());
    }
    logger.info(indexesDirs.size() + " directories found!");

    /** Set-up the searcher */
    Searcher searcher = null;
    try {
        String[] array = indexesDirs.toArray(new String[indexesDirs.size()]);
        searcher = new Searcher(array);
        TopDocs results = searcher.search(query, Integer.MAX_VALUE);

        ScoreDoc[] hits = results.scoreDocs;
        int numTotalHits = results.totalHits;

        System.out.println(numTotalHits + " total matching documents");

        for (int i = 0; i < numTotalHits; i++) {
            Document doc = searcher.doc(hits[i].doc);

            String path = doc.get(FIELD_PATH);
            String filename = doc.get(FIELD_FILENAME);
            String image_uuid = doc.get(FIELD_IMAGE_ID);

            if (path != null) {
                //System.out.println((i + 1) + ". " + path + File.separator + filename + " - score: " + hits[i].score);
                //               System.out.println((i + 1) + ". " + path + File.separator + filename + " - image_file: " + image_uuid);
                System.out.println((i + 1) + ". " + path + File.separator + filename + " - image_file: "
                        + imagesMap.get(Integer.parseInt(image_uuid)));
            } else {
                System.out.println((i + 1) + ". " + "No path for this document");
            }
        }

    } catch (Exception e) {
        System.err.println("An error occurred: " + e.getMessage());
        e.printStackTrace();
    } finally {
        if (searcher != null)
            searcher.close();
    }
}

From source file:com.damon.rocketmq.example.benchmark.Producer.java

public static void main(String[] args) throws MQClientException, UnsupportedEncodingException {

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    CommandLine commandLine = ServerUtil.parseCmdLine("benchmarkProducer", args,
            buildCommandlineOptions(options), new PosixParser());
    if (null == commandLine) {
        System.exit(-1);//from   ww  w  .  j  a v  a2  s.com
    }

    final String topic = commandLine.hasOption('t') ? commandLine.getOptionValue('t').trim() : "BenchmarkTest";
    final int threadCount = commandLine.hasOption('w') ? Integer.parseInt(commandLine.getOptionValue('w')) : 64;
    final int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s'))
            : 128;
    final boolean keyEnable = commandLine.hasOption('k')
            && Boolean.parseBoolean(commandLine.getOptionValue('k'));

    System.out.printf("topic %s threadCount %d messageSize %d keyEnable %s%n", topic, threadCount, messageSize,
            keyEnable);

    final Logger log = ClientLogger.getLog();

    final Message msg = buildMessage(messageSize, topic);

    final ExecutorService sendThreadPool = Executors.newFixedThreadPool(threadCount);

    final StatsBenchmarkProducer statsBenchmark = new StatsBenchmarkProducer();

    final Timer timer = new Timer("BenchmarkTimerThread", true);

    final LinkedList<Long[]> snapshotList = new LinkedList<Long[]>();

    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            snapshotList.addLast(statsBenchmark.createSnapshot());
            if (snapshotList.size() > 10) {
                snapshotList.removeFirst();
            }
        }
    }, 1000, 1000);

    timer.scheduleAtFixedRate(new TimerTask() {
        private void printStats() {
            if (snapshotList.size() >= 10) {
                Long[] begin = snapshotList.getFirst();
                Long[] end = snapshotList.getLast();

                final long sendTps = (long) (((end[3] - begin[3]) / (double) (end[0] - begin[0])) * 1000L);
                final double averageRT = (end[5] - begin[5]) / (double) (end[3] - begin[3]);

                System.out.printf(
                        "Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d%n",
                        sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4]);
            }
        }

        @Override
        public void run() {
            try {
                this.printStats();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 10000, 10000);

    final DefaultMQProducer producer = new DefaultMQProducer("benchmark_producer");
    producer.setInstanceName(Long.toString(System.currentTimeMillis()));

    if (commandLine.hasOption('n')) {
        String ns = commandLine.getOptionValue('n');
        producer.setNamesrvAddr(ns);
    }

    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);

    producer.start();

    for (int i = 0; i < threadCount; i++) {
        sendThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        final long beginTimestamp = System.currentTimeMillis();
                        if (keyEnable) {
                            msg.setKeys(String.valueOf(beginTimestamp / 1000));
                        }
                        producer.send(msg);
                        statsBenchmark.getSendRequestSuccessCount().incrementAndGet();
                        statsBenchmark.getReceiveResponseSuccessCount().incrementAndGet();
                        final long currentRT = System.currentTimeMillis() - beginTimestamp;
                        statsBenchmark.getSendMessageSuccessTimeTotal().addAndGet(currentRT);
                        long prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        while (currentRT > prevMaxRT) {
                            boolean updated = statsBenchmark.getSendMessageMaxRT().compareAndSet(prevMaxRT,
                                    currentRT);
                            if (updated)
                                break;

                            prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        }
                    } catch (RemotingException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);

                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ignored) {
                        }
                    } catch (InterruptedException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e1) {
                        }
                    } catch (MQClientException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                    } catch (MQBrokerException e) {
                        statsBenchmark.getReceiveResponseFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ignored) {
                        }
                    }
                }
            }
        });
    }
}

From source file:edu.msu.cme.rdp.probematch.cli.SliceToPrimer.java

public static void main(String[] args) throws Exception {
    //args = "--fedit-dist 4 --redit-dist=4 -k --max-length=400 --min-length=280 -o java_sliced_edit4.fasta TGCGAYCCSAARGCBGACTC ATSGCCATCATYTCRCCGGA /scratch/fishjord/tae_kwon_primer_match/all_genomes.fasta".split(" ");
    PatternBitMask64[] fprimers;/*from  w ww.j a  v a  2  s .c  o  m*/
    String[] fprimerStrs, rprimerStrs;
    PatternBitMask64[] rprimers;

    FastaWriter seqOut;
    PrintStream statsOut;

    int fEdit = 3;
    int rEdit = 3;
    int minLength = Integer.MIN_VALUE;
    int maxLength = Integer.MAX_VALUE;
    boolean allowAmbiguities = true;
    boolean keepPrimers = false;

    SequenceReader inSeqs;

    try {

        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("edit-dist")) {
            fEdit = rEdit = Integer.parseInt(line.getOptionValue("edit-dist"));

            if (line.hasOption("redit-dist") || line.hasOption("fedit-dist")) {
                throw new Exception("edit-dist, [fedit-dist, redit-dist] are mutually exclusive");
            }
        }

        if (line.hasOption("fedit-dist")) {
            fEdit = Integer.parseInt(line.getOptionValue("fedit-dist"));
        }

        if (line.hasOption("no-ambiguities")) {
            allowAmbiguities = false;
        }

        if (line.hasOption("keep-primers")) {
            keepPrimers = true;
        }

        if (line.hasOption("redit-dist")) {
            rEdit = Integer.parseInt(line.getOptionValue("redit-dist"));
        }

        if (line.hasOption("seq-out")) {
            seqOut = new FastaWriter(new File(line.getOptionValue("seq-out")));
        } else {
            throw new Exception("Must specify seq-out");
        }

        if (line.hasOption("stats-out")) {
            statsOut = new PrintStream(new File(line.getOptionValue("stats-out")));
        } else {
            statsOut = System.out;
        }

        if (line.hasOption("min-length")) {
            minLength = Integer.parseInt(line.getOptionValue("min-length"));
        }

        if (line.hasOption("max-length")) {
            maxLength = Integer.parseInt(line.getOptionValue("max-length"));
        }

        args = line.getArgs();

        if (args.length != 3) {
            throw new Exception("Unexpected number of command line arguments");
        }

        fprimers = translateStringPrimers(args[0].split(","), allowAmbiguities, false);
        fprimerStrs = args[0].split(",");
        rprimers = translateStringPrimers(args[1].split(","), allowAmbiguities, true);
        rprimerStrs = args[1].split(",");
        inSeqs = new SequenceReader(new File(args[2]));

    } catch (Exception e) {
        new HelpFormatter().printHelp("SliceToPrimer [options] <f,p,r,i,m,e,r> <r,p,r,i,m,e,r> <in_seq_file>",
                options);
        System.err.println("ERROR: " + e.getMessage());
        return;
    }

    Sequence seq;

    statsOut.println(
            "orig_seqid\tsliced_seqid\tfprimer\tstart\tend\tscore\trprimer\tstart\tend\tscore\tlength");

    ScoringMatrix sccoringMatrix = ScoringMatrix.getDefaultNuclMatrix();

    DPMAligner[] faligners = new DPMAligner[fprimers.length];
    for (int index = 0; index < faligners.length; index++) {
        faligners[index] = new DPMAligner(fprimerStrs[index], Integer.MAX_VALUE);
    }

    try {
        while ((seq = inSeqs.readNextSequence()) != null) {
            Set<PrimerMatch> fprimerMatches = new HashSet();
            Set<PrimerMatch> rprimerMatches = new HashSet();

            for (int index = 0; index < fprimers.length; index++) {
                PatternBitMask64 primer = fprimers[index];

                for (BitVector64Match r : BitVector64.process(seq.getSeqString().toCharArray(), primer, fEdit)
                        .getResults()) {
                    PrimerMatch match = new PrimerMatch();
                    match.start = r.getPosition() - (primer.getPatternLength() + r.getScore());
                    match.end = r.getPosition();
                    match.score = r.getScore();
                    match.primerIndex = index;
                    fprimerMatches.add(match);
                }
            }

            for (int index = 0; index < rprimers.length; index++) {
                PatternBitMask64 primer = rprimers[index];

                for (BitVector64Match r : BitVector64.process(seq.getSeqString().toCharArray(), primer, rEdit)
                        .getResults()) {
                    PrimerMatch match = new PrimerMatch();
                    match.start = r.getPosition() - (primer.getPatternLength() + r.getScore());
                    match.end = r.getPosition();
                    match.score = r.getScore();
                    match.primerIndex = index;
                    rprimerMatches.add(match);
                }
            }

            if (fprimerMatches.isEmpty() || rprimerMatches.isEmpty()) {
                statsOut.println(seq.getSeqName() + "\tEither/or no forward/reverse primer hits");
                continue;
            }
            for (PrimerMatch fmatch : fprimerMatches) {
                PrimerMatch bestReverse = null;
                int bestScore = Integer.MAX_VALUE;
                for (PrimerMatch rmatch : rprimerMatches) {
                    if (rmatch.start > fmatch.end && rmatch.start - fmatch.end < bestScore) {
                        bestReverse = rmatch;
                        bestScore = rmatch.start - fmatch.end;
                    }
                }

                if (bestReverse == null) {
                    statsOut.println(seq.getSeqName() + "\tNo reverse primer before " + fmatch.end);
                    continue;
                }

                String slicedSeq = null;
                if (keepPrimers) {
                    slicedSeq = seq.getSeqString().substring(fmatch.start, bestReverse.end);
                } else {
                    slicedSeq = seq.getSeqString().substring(fmatch.end, bestReverse.start);
                }

                String seqid = seq.getSeqName() + "_" + fmatch.primerIndex + "_" + fmatch.start;
                if (slicedSeq.length() > minLength && slicedSeq.length() < maxLength) {
                    seqOut.writeSeq(seqid, "", slicedSeq);
                }

                DPMAlignment seqs = faligners[fmatch.primerIndex]
                        .align(seq.getSeqString().substring(fmatch.start, fmatch.end));
                System.err.println(">" + seqid);
                System.err.println(fprimerStrs[fmatch.primerIndex]);
                System.err.println(seq.getSeqString().substring(fmatch.start, fmatch.end));
                System.err.println();
                System.err.println(seqs.getAlignedMatchFragment());
                System.err.println(seqs.getAlignedProbe());

                System.err.println();

                statsOut.println(seq.getSeqName() + "\t" + seqid + "\t" + fmatch.primerIndex + "\t"
                        + fmatch.start + "\t" + fmatch.end + "\t" + fmatch.score + "\t"
                        + bestReverse.primerIndex + "\t" + bestReverse.start + "\t" + bestReverse.end + "\t"
                        + bestReverse.score + "\t" + slicedSeq.length());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        statsOut.close();
        seqOut.close();
    }
}

From source file:com.asakusafw.dmdl.thundergate.Main.java

/**
 * ???/*ww w . ja v  a2 s .co m*/
 * @param args ???????????
 */
public static void main(String... args) {
    GenerateTask task;
    try {
        Configuration conf = loadConfigurationFromArguments(args);
        task = new GenerateTask(conf);
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(Integer.MAX_VALUE);
        formatter.printHelp(MessageFormat.format("java -classpath ... {0}", Main.class.getName()), OPTIONS,
                true);
        e.printStackTrace(System.out);
        System.exit(1);
        return;
    }
    try {
        task.call();
    } catch (Exception e) {
        e.printStackTrace(System.out);
        System.exit(1);
        return;
    }
}