com.github.arnabk.App.java Source code

Java tutorial

Introduction

Here is the source code for com.github.arnabk.App.java

Source

/*
 * Copyright 2014 arnab.
 *
 * 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 com.github.arnabk;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * @author arnab
 */
public class App {

    public static void main(String[] args) {

        if (checkParams(args)) {

            final int frequency = Integer.parseInt(StringUtils.trimToEmpty(args[0])); //in minutes
            final BlockingChecker blockingChecker = new BlockingChecker();
            blockingChecker.execute(frequency, args);

        }

    }

    private static boolean checkParams(String args[]) {
        boolean ret = false;
        if (args.length < 2) {
            printUsage();
        } else {
            if (NumberUtils.isNumber(args[0])) {
                ret = true;
            } else {
                printUsage();
            }
        }
        return ret;
    }

    private static void printUsage() {
        System.out.println("mvn exec:java -Dexec.args=\"<frequency in minutes> <site1> <site2> <site3> ....\"");
        System.out.println("For example, mvn exec:java -Dexec.args=\"1 www.google.com www.bing.com\"");
    }

}