Example usage for java.lang Integer toString

List of usage examples for java.lang Integer toString

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static String toString(int i) 

Source Link

Document

Returns a String object representing the specified integer.

Usage

From source file:eu.amidst.core.inference.MAPInferenceExperiments_Deliv1.java

/**
 * The class constructor.//www. j  a va 2s  .c  o m
 * @param args Array of options: "filename variable a b N useVMP" if variable is continuous or "filename variable w N useVMP" for discrete
 */
public static void main(String[] args) throws Exception { // args: seedNetwork numberGaussians numberDiscrete seedAlgorithms

    int seedNetwork = 234235125;
    int numberOfGaussians = 50;
    int numberOfMultinomials = 50;

    int seed = 125634;

    int parallelSamples = 50;
    int samplingMethodSize = 20000;

    int repetitions = 10;

    int numberOfIterations = 100;

    if (args.length != 8) {
        if (Main.VERBOSE)
            System.out.println("Invalid number of parameters. Using default values");
    } else {
        try {
            seedNetwork = Integer.parseInt(args[0]);
            numberOfGaussians = Integer.parseInt(args[1]);
            numberOfMultinomials = Integer.parseInt(args[2]);

            seed = Integer.parseInt(args[3]);

            parallelSamples = Integer.parseInt(args[4]);
            samplingMethodSize = Integer.parseInt(args[5]);

            repetitions = Integer.parseInt(args[6]);

            numberOfIterations = Integer.parseInt(args[7]);

        } catch (NumberFormatException ex) {
            if (Main.VERBOSE)
                System.out.println(
                        "Invalid parameters. Provide integers: seedNetwork numberGaussians numberDiscrete seedAlgorithms parallelSamples sampleSize repetitions");
            if (Main.VERBOSE)
                System.out.println("Using default parameters");
            if (Main.VERBOSE)
                System.out.println(ex.toString());
            System.exit(20);
        }
    }
    int numberOfLinks = (int) 1.3 * (numberOfGaussians + numberOfMultinomials);

    BayesianNetworkGenerator.setSeed(seedNetwork);
    BayesianNetworkGenerator.setNumberOfGaussianVars(numberOfGaussians);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(numberOfMultinomials, 2);
    BayesianNetworkGenerator.setNumberOfLinks(numberOfLinks);

    String filename = "./networks/simulated/RandomBN_" + Integer.toString(numberOfMultinomials) + "D_"
            + Integer.toString(numberOfGaussians) + "C_" + Integer.toString(seedNetwork) + "_Seed.bn";
    BayesianNetworkGenerator.generateBNtoFile(numberOfMultinomials, 2, numberOfGaussians, numberOfLinks,
            seedNetwork, filename);
    BayesianNetwork bn = BayesianNetworkGenerator.generateBayesianNetwork();

    //if (Main.VERBOSE) System.out.println(bn.getDAG());
    //if (Main.VERBOSE) System.out.println(bn.toString());

    MAPInference mapInference = new MAPInference();
    mapInference.setModel(bn);
    mapInference.setParallelMode(true);

    // Set also the list of variables of interest (or MAP variables).
    List<Variable> varsInterest = new ArrayList<>();

    Variable var1 = bn.getVariables().getVariableById(3);
    Variable var2 = bn.getVariables().getVariableById(7);
    Variable var3 = bn.getVariables().getVariableById(60);

    varsInterest.add(var1);
    varsInterest.add(var2);
    varsInterest.add(var3);
    mapInference.setMAPVariables(varsInterest);
    if (Main.VERBOSE)
        System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + ", "
                + var3.getName() + "\n");

    //if (Main.VERBOSE) System.out.println("CausalOrder: " + Arrays.toString(Utils.getCausalOrder(mapInference.getOriginalModel().getDAG()).stream().map(Variable::getName).toArray()));
    //List<Variable> modelVariables = Utils.getCausalOrder(bn.getDAG());
    if (Main.VERBOSE)
        System.out.println();

    // Including evidence:
    //double observedVariablesRate = 0.00;
    //Assignment evidence = randomEvidence(seed, observedVariablesRate, bn);
    //mapInference.setEvidence(evidence);

    mapInference.setNumberOfIterations(numberOfIterations);

    mapInference.setSampleSize(parallelSamples);
    mapInference.setSeed(seed);

    double[] SA_All_prob = new double[repetitions];
    double[] SA_Some_prob = new double[repetitions];
    double[] HC_All_prob = new double[repetitions];
    double[] HC_Some_prob = new double[repetitions];
    double[] sampling_prob = new double[repetitions];

    double[] SA_All_time = new double[repetitions];
    double[] SA_Some_time = new double[repetitions];
    double[] HC_All_time = new double[repetitions];
    double[] HC_Some_time = new double[repetitions];
    double[] sampling_time = new double[repetitions];

    long timeStart;
    long timeStop;
    double execTime;

    Assignment bestMpeEstimate = new HashMapAssignment(bn.getNumberOfVars());
    double bestMpeEstimateLogProb = -100000;
    int bestMpeEstimateMethod = -5;

    mapInference.setParallelMode(true);

    final double bestProbability = -93.40102227041749;
    //        BEST MAP ESTIMATE FOUND:
    //        {DiscreteVar3 = 1, DiscreteVar7 = 1, GaussianVar10 = 0,011}
    //        with method:2
    //        and log probability: -93.40102227041749
    //
    //        BEST MAP ESTIMATE FOUND:
    //        {DiscreteVar3 = 1, DiscreteVar7 = 0, GaussianVar10 = 14,672}
    //        with method:2
    //        and log probability: -93.84634767213683

    for (int k = 0; k < repetitions; k++) {

        mapInference.setSampleSize(parallelSamples);

        /***********************************************
         *        SIMULATED ANNEALING
         ************************************************/

        // MPE INFERENCE WITH SIMULATED ANNEALING, ALL VARIABLES
        //if (Main.VERBOSE) System.out.println();
        timeStart = System.nanoTime();
        mapInference.runInference(MAPInference.SearchAlgorithm.SA_GLOBAL);

        //mpeEstimate = mapInference.getEstimate();
        //if (Main.VERBOSE) System.out.println("MPE estimate (SA.All): " + mpeEstimate.outputString(modelVariables));   //toString(modelVariables)
        //if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
        //if (Main.VERBOSE) System.out.println();
        SA_All_prob[k] = mapInference.getLogProbabilityOfEstimate();
        SA_All_time[k] = execTime;

        if (mapInference.getLogProbabilityOfEstimate() > bestMpeEstimateLogProb) {
            bestMpeEstimate = mapInference.getEstimate();
            bestMpeEstimateLogProb = mapInference.getLogProbabilityOfEstimate();
            bestMpeEstimateMethod = 1;
        }

        // MPE INFERENCE WITH SIMULATED ANNEALING, SOME VARIABLES AT EACH TIME
        timeStart = System.nanoTime();
        mapInference.runInference(MAPInference.SearchAlgorithm.SA_LOCAL);

        //mpeEstimate = mapInference.getEstimate();
        //if (Main.VERBOSE) System.out.println("MPE estimate  (SA.Some): " + mpeEstimate.outputString(modelVariables));   //toString(modelVariables)
        //if (Main.VERBOSE) System.out.println("with probability: "+ Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
        //if (Main.VERBOSE) System.out.println();
        SA_Some_prob[k] = mapInference.getLogProbabilityOfEstimate();
        SA_Some_time[k] = execTime;

        if (mapInference.getLogProbabilityOfEstimate() > bestMpeEstimateLogProb) {
            bestMpeEstimate = mapInference.getEstimate();
            bestMpeEstimateLogProb = mapInference.getLogProbabilityOfEstimate();
            bestMpeEstimateMethod = 0;
        }

        /***********************************************
         *        HILL CLIMBING
         ************************************************/

        // MPE INFERENCE WITH HILL CLIMBING, ALL VARIABLES
        timeStart = System.nanoTime();
        mapInference.runInference(MAPInference.SearchAlgorithm.HC_GLOBAL);

        //mpeEstimate = mapInference.getEstimate();
        //modelVariables = mapInference.getOriginalModel().getVariables().getListOfVariables();
        //if (Main.VERBOSE) System.out.println("MPE estimate (HC.All): " + mpeEstimate.outputString(modelVariables));
        //if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        //if (Main.VERBOSE) System.out.println();
        HC_All_prob[k] = mapInference.getLogProbabilityOfEstimate();
        HC_All_time[k] = execTime;

        if (mapInference.getLogProbabilityOfEstimate() > bestMpeEstimateLogProb) {
            bestMpeEstimate = mapInference.getEstimate();
            bestMpeEstimateLogProb = mapInference.getLogProbabilityOfEstimate();
            bestMpeEstimateMethod = 3;
        }

        //  MPE INFERENCE WITH HILL CLIMBING, ONE VARIABLE AT EACH TIME
        timeStart = System.nanoTime();
        mapInference.runInference(MAPInference.SearchAlgorithm.HC_LOCAL);

        //mpeEstimate = mapInference.getEstimate();
        //if (Main.VERBOSE) System.out.println("MPE estimate  (HC.Some): " + mpeEstimate.outputString(modelVariables));   //toString(modelVariables)
        //if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        //if (Main.VERBOSE) System.out.println();
        HC_Some_prob[k] = mapInference.getLogProbabilityOfEstimate();
        HC_Some_time[k] = execTime;

        if (mapInference.getLogProbabilityOfEstimate() > bestMpeEstimateLogProb) {
            bestMpeEstimate = mapInference.getEstimate();
            bestMpeEstimateLogProb = mapInference.getLogProbabilityOfEstimate();
            bestMpeEstimateMethod = 2;
        }

        /***********************************************
         *        SAMPLING AND DETERMINISTIC
         ************************************************/

        // MPE INFERENCE WITH SIMULATION AND PICKING MAX

        mapInference.setSampleSize(samplingMethodSize);

        timeStart = System.nanoTime();
        mapInference.runInference(MAPInference.SearchAlgorithm.SAMPLING);

        //mpeEstimate = mapInference.getEstimate();
        //modelVariables = mapInference.getOriginalModel().getVariables().getListOfVariables();
        //if (Main.VERBOSE) System.out.println("MPE estimate (SAMPLING): " + mpeEstimate.outputString(modelVariables));
        //if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        //if (Main.VERBOSE) System.out.println();
        sampling_prob[k] = mapInference.getLogProbabilityOfEstimate();
        sampling_time[k] = execTime;

        if (mapInference.getLogProbabilityOfEstimate() > bestMpeEstimateLogProb) {
            bestMpeEstimate = mapInference.getEstimate();
            bestMpeEstimateLogProb = mapInference.getLogProbabilityOfEstimate();
            bestMpeEstimateMethod = -1;
        }
    }

    double determ_prob = 0;
    double determ_time = 0;

    //        if(bn.getNumberOfVars()<=50) {
    //
    //            // MPE INFERENCE, DETERMINISTIC
    //            timeStart = System.nanoTime();
    //            mapInference.runInference(-2);
    //
    //            //mpeEstimate = mapInference.getEstimate();
    //            //modelVariables = mapInference.getOriginalModel().getVariables().getListOfVariables();
    //            //if (Main.VERBOSE) System.out.println("MPE estimate (DETERM.): " + mpeEstimate.outputString(modelVariables));
    //            //if (Main.VERBOSE) System.out.println("with probability: " + Math.exp(mapInference.getLogProbabilityOfEstimate()) + ", logProb: " + mapInference.getLogProbabilityOfEstimate());
    //            timeStop = System.nanoTime();
    //            execTime = (double) (timeStop - timeStart) / 1000000000.0;
    //            //if (Main.VERBOSE) System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    //            //if (Main.VERBOSE) System.out.println();
    //            determ_prob = mapInference.getLogProbabilityOfEstimate();
    //            determ_time = execTime;
    //
    //        }
    //        else {
    //            if (Main.VERBOSE) System.out.println("Too many variables for deterministic method");
    //        }

    /***********************************************
     *        DISPLAY OF RESULTS
     ************************************************/

    if (Main.VERBOSE)
        System.out.println("*** RESULTS ***");

    if (Main.VERBOSE)
        System.out.println("SA_All log-probabilities");
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(SA_All_prob));
    if (Main.VERBOSE)
        System.out.println("SA_Some log-probabilities");
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(SA_Some_prob));
    if (Main.VERBOSE)
        System.out.println("HC_All log-probabilities");
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(HC_All_prob));
    if (Main.VERBOSE)
        System.out.println("HC_Some log-probabilities");
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(HC_Some_prob));
    if (Main.VERBOSE)
        System.out.println("Sampling log-probabilities");
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(sampling_prob));
    //        if(bn.getNumberOfVars()<=50) {
    //            if (Main.VERBOSE) System.out.println("Deterministic log-probability");
    //            if (Main.VERBOSE) System.out.println(Double.toString(determ_prob));
    //        }

    if (Main.VERBOSE)
        System.out.println("SA_All RMS probabilities");
    double SA_All_RMS = Math.sqrt(Arrays.stream(SA_All_prob).map(value -> Math.pow(value - bestProbability, 2))
            .average().getAsDouble());
    if (Main.VERBOSE)
        System.out.println(Double.toString(SA_All_RMS));
    if (Main.VERBOSE)
        System.out.println("SA_Some RMS probabilities");
    double SA_Some_RMS = Math.sqrt(Arrays.stream(SA_Some_prob)
            .map(value -> Math.pow(value - bestProbability, 2)).average().getAsDouble());
    if (Main.VERBOSE)
        System.out.println(Double.toString(SA_Some_RMS));
    if (Main.VERBOSE)
        System.out.println("HC_All RMS probabilities");
    double HC_All_RMS = Math.sqrt(Arrays.stream(HC_All_prob).map(value -> Math.pow(value - bestProbability, 2))
            .average().getAsDouble());
    if (Main.VERBOSE)
        System.out.println(Double.toString(HC_All_RMS));
    if (Main.VERBOSE)
        System.out.println("HC_Some RMS probabilities");
    double HC_Some_RMS = Math.sqrt(Arrays.stream(HC_Some_prob)
            .map(value -> Math.pow(value - bestProbability, 2)).average().getAsDouble());
    if (Main.VERBOSE)
        System.out.println(Double.toString(HC_Some_RMS));
    if (Main.VERBOSE)
        System.out.println("Sampling RMS probabilities");
    double sampling_RMS = Math.sqrt(Arrays.stream(sampling_prob)
            .map(value -> Math.pow(value - bestProbability, 2)).average().getAsDouble());
    if (Main.VERBOSE)
        System.out.println(Double.toString(sampling_RMS));
    double[] RMS_means = { SA_All_RMS, SA_Some_RMS, HC_All_RMS, HC_Some_RMS, sampling_RMS };
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(RMS_means));
    if (Main.VERBOSE)
        System.out.println();

    if (Main.VERBOSE)
        System.out.println("SA_All times");
    //if (Main.VERBOSE) System.out.println(Arrays.toString(SA_All_time));
    double SA_All_times_mean = Arrays.stream(SA_All_time).average().getAsDouble();
    if (Main.VERBOSE)
        System.out.println("Mean time: " + Double.toString(SA_All_times_mean));
    if (Main.VERBOSE)
        System.out.println("SA_Some times");
    //if (Main.VERBOSE) System.out.println(Arrays.toString(SA_Some_time));
    double SA_Some_times_mean = Arrays.stream(SA_Some_time).average().getAsDouble();
    if (Main.VERBOSE)
        System.out.println("Mean time: " + Double.toString(SA_Some_times_mean));
    if (Main.VERBOSE)
        System.out.println("HC_All times");
    //if (Main.VERBOSE) System.out.println(Arrays.toString(HC_All_time));
    double HC_All_times_mean = Arrays.stream(HC_All_time).average().getAsDouble();
    if (Main.VERBOSE)
        System.out.println("Mean time: " + Double.toString(HC_All_times_mean));
    if (Main.VERBOSE)
        System.out.println("HC_Some times");
    //if (Main.VERBOSE) System.out.println(Arrays.toString(HC_Some_time));
    double HC_Some_times_mean = Arrays.stream(HC_Some_time).average().getAsDouble();
    if (Main.VERBOSE)
        System.out.println("Mean time: " + Double.toString(HC_Some_times_mean));
    if (Main.VERBOSE)
        System.out.println("Sampling times");
    double sampling_times_mean = Arrays.stream(sampling_time).average().getAsDouble();
    //if (Main.VERBOSE) System.out.println(Arrays.toString(sampling_time));
    if (Main.VERBOSE)
        System.out.println("Mean time: " + Double.toString(sampling_times_mean));
    if (Main.VERBOSE)
        System.out.println("All means:");
    double[] time_means = { SA_All_times_mean, SA_Some_times_mean, HC_All_times_mean, HC_Some_times_mean,
            sampling_times_mean };
    if (Main.VERBOSE)
        System.out.println(Arrays.toString(time_means));
    if (Main.VERBOSE)
        System.out.println();
    //        if(bn.getNumberOfVars()<=50) {
    //            if (Main.VERBOSE) System.out.println("Deterministic time");
    //            if (Main.VERBOSE) System.out.println(Double.toString(determ_time));
    //        }

    if (Main.VERBOSE)
        System.out.println("BEST MAP ESTIMATE FOUND:");
    if (Main.VERBOSE)
        System.out.println(bestMpeEstimate.outputString(Utils.getTopologicalOrder(bn.getDAG())));
    if (Main.VERBOSE)
        System.out.println("with method:" + bestMpeEstimateMethod);
    if (Main.VERBOSE)
        System.out.println("and log probability: " + bestMpeEstimateLogProb);
}

From source file:hdfs.MiniHDFS.java

public static void main(String[] args) throws Exception {
    if (args.length != 1 && args.length != 3) {
        throw new IllegalArgumentException(
                "Expected: MiniHDFS <baseDirectory> [<kerberosPrincipal> <kerberosKeytab>], " + "got: "
                        + Arrays.toString(args));
    }/*  w  w  w  . jav a  2 s  .  c o m*/
    boolean secure = args.length == 3;

    // configure Paths
    Path baseDir = Paths.get(args[0]);
    // hadoop-home/, so logs will not complain
    if (System.getenv("HADOOP_HOME") == null) {
        Path hadoopHome = baseDir.resolve("hadoop-home");
        Files.createDirectories(hadoopHome);
        System.setProperty("hadoop.home.dir", hadoopHome.toAbsolutePath().toString());
    }
    // hdfs-data/, where any data is going
    Path hdfsHome = baseDir.resolve("hdfs-data");

    // configure cluster
    Configuration cfg = new Configuration();
    cfg.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsHome.toAbsolutePath().toString());
    // lower default permission: TODO: needed?
    cfg.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_PERMISSION_KEY, "766");

    // optionally configure security
    if (secure) {
        String kerberosPrincipal = args[1];
        String keytabFile = args[2];

        cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, "true");
        cfg.set(DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY, keytabFile);
        cfg.set(DFSConfigKeys.DFS_DATANODE_KEYTAB_FILE_KEY, keytabFile);
        cfg.set(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, "true");
        cfg.set(DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, "true");
        cfg.set(DFSConfigKeys.IGNORE_SECURE_PORTS_FOR_TESTING_KEY, "true");
    }

    UserGroupInformation.setConfiguration(cfg);

    // TODO: remove hardcoded port!
    MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(cfg);
    if (secure) {
        builder.nameNodePort(9998);
    } else {
        builder.nameNodePort(9999);
    }
    MiniDFSCluster dfs = builder.build();

    // Configure contents of the filesystem
    org.apache.hadoop.fs.Path esUserPath = new org.apache.hadoop.fs.Path("/user/elasticsearch");
    try (FileSystem fs = dfs.getFileSystem()) {

        // Set the elasticsearch user directory up
        fs.mkdirs(esUserPath);
        if (UserGroupInformation.isSecurityEnabled()) {
            List<AclEntry> acls = new ArrayList<>();
            acls.add(new AclEntry.Builder().setType(AclEntryType.USER).setName("elasticsearch")
                    .setPermission(FsAction.ALL).build());
            fs.modifyAclEntries(esUserPath, acls);
        }

        // Install a pre-existing repository into HDFS
        String directoryName = "readonly-repository";
        String archiveName = directoryName + ".tar.gz";
        URL readOnlyRepositoryArchiveURL = MiniHDFS.class.getClassLoader().getResource(archiveName);
        if (readOnlyRepositoryArchiveURL != null) {
            Path tempDirectory = Files.createTempDirectory(MiniHDFS.class.getName());
            File readOnlyRepositoryArchive = tempDirectory.resolve(archiveName).toFile();
            FileUtils.copyURLToFile(readOnlyRepositoryArchiveURL, readOnlyRepositoryArchive);
            FileUtil.unTar(readOnlyRepositoryArchive, tempDirectory.toFile());

            fs.copyFromLocalFile(true, true,
                    new org.apache.hadoop.fs.Path(
                            tempDirectory.resolve(directoryName).toAbsolutePath().toUri()),
                    esUserPath.suffix("/existing/" + directoryName));

            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    }

    // write our PID file
    Path tmp = Files.createTempFile(baseDir, null, null);
    String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
    Files.write(tmp, pid.getBytes(StandardCharsets.UTF_8));
    Files.move(tmp, baseDir.resolve(PID_FILE_NAME), StandardCopyOption.ATOMIC_MOVE);

    // write our port file
    tmp = Files.createTempFile(baseDir, null, null);
    Files.write(tmp, Integer.toString(dfs.getNameNodePort()).getBytes(StandardCharsets.UTF_8));
    Files.move(tmp, baseDir.resolve(PORT_FILE_NAME), StandardCopyOption.ATOMIC_MOVE);
}

From source file:RoucairolCarvahloBasicVersion.java

public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException {
    //For parsing the file and storing the information
    String line;//  www.  j ava2s.  c o  m
    String configurationFile = "configuration.txt";
    int lineCountInFile = 0;
    myProcessId = Integer.parseInt(args[0]);
    FileReader fileReader = new FileReader(configurationFile);
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    while ((line = bufferedReader.readLine()) != null) {
        if ((!(line.startsWith("#"))) && (!(line.isEmpty()))) {
            lineCountInFile = lineCountInFile + 1;
            String[] splitLine = line.split(" ");
            switch (lineCountInFile) {
            case 1:
                numberOfProcesses = Integer.parseInt(splitLine[0]);
                interRequestDelay = Integer.parseInt(splitLine[1]);
                csExecutionTime = Integer.parseInt(splitLine[2]);
                maxNumberOfRequest = Integer.parseInt(splitLine[3]);
                machineNames = new String[Integer.parseInt(splitLine[0])];
                portNumbers = new int[Integer.parseInt(splitLine[0])];
                break;
            default:
                machineNames[lineCountInFile - 2] = splitLine[1];
                portNumbers[lineCountInFile - 2] = Integer.parseInt(splitLine[2]);
                break;
            }
        }
    }
    //Initializing finish array
    finishFlagArray = new int[numberOfProcesses];
    //Initializing vector class
    VectorClass.initialize(numberOfProcesses);
    //Fill the arrays with zero false value
    for (int o = 0; o < numberOfProcesses; o++) {
        finishFlagArray[o] = 0;
    }
    //Initializing key array and inserting values
    keyArray = new int[numberOfProcesses];
    for (int q = 0; q < numberOfProcesses; q++) {
        if (q >= myProcessId) {
            keyArray[q] = 1;
        }
    }
    filename = filename + Integer.toString(myProcessId) + ".out";
    file = new File(filename);
    file.createNewFile();
    writer = new FileWriter(file);
    // Write clocks to file
    filenameClock = filenameClock + Integer.toString(myProcessId) + ".out";
    fileClock = new File(filenameClock);
    fileClock.createNewFile();
    //writerClock = new FileWriter(fileClock);
    fw = new FileWriter(fileClock);
    bw = new BufferedWriter(fw);
    //
    // Expo mean insert
    csExecutionExpoDelay = new ExponentialDistribution(csExecutionTime);
    interRequestExpoDelay = new ExponentialDistribution(interRequestDelay);
    //
    System.out.println("********************************************************");
    System.out.println("My process id : " + myProcessId);
    System.out.println("Number of processes : " + numberOfProcesses);
    System.out.println("Inter-request delay : " + interRequestDelay);
    System.out.println("Critical section execution time : " + csExecutionTime);
    System.out.println("Maximum number of request : " + maxNumberOfRequest);
    System.out.println(
            "My process name : " + machineNames[myProcessId] + " My port number : " + portNumbers[myProcessId]);
    for (int i = 0; i < numberOfProcesses; i++) {
        System.out.println("Process name : " + machineNames[i] + " Port number : " + portNumbers[i]);
    }
    System.out.println("********************************************************");
    for (int q = 0; q < numberOfProcesses; q++) {
        System.out.println("KeyArray" + q + " - " + keyArray[q]);
    }
    System.out.println("********************************************************");
    //For hosting server localhost
    SctpServerChannel sctpServerChannel = SctpServerChannel.open();
    InetSocketAddress serverAddr = new InetSocketAddress(portNumbers[myProcessId]);
    sctpServerChannel.bind(serverAddr);
    System.out.println("********************************************************");
    System.out.println("Local server hosted");
    System.out.println("********************************************************");
    //For creating neighbor SCTP channels
    Thread.sleep(30000);
    socketAddress = new SocketAddress[numberOfProcesses];
    sctpChannel = new SctpChannel[numberOfProcesses];
    System.out.println("********************************************************");
    System.out.println("Neighbor channels created");
    System.out.println("********************************************************");
    //Thread spanned for generating critical section request
    new Thread(new RoucairolCarvahloBasicVersion()).start();
    while (true) {
        try (SctpChannel sctpChannelFromClient = sctpServerChannel.accept()) {
            mutex.acquire();
            byteBufferFromNeighbor.clear();
            String receiveMessage;
            MessageInfo messageInfoFromNeighbor = sctpChannelFromClient.receive(byteBufferFromNeighbor, null,
                    null);
            //System.out.println("Raw Message : " + messageInfoFromNeighbor);
            receiveMessage = byteToString(byteBufferFromNeighbor, messageInfoFromNeighbor);
            System.out.println("Received Message : " + receiveMessage);
            if (receiveMessage.contains("Request")) {
                String[] parseMessage = receiveMessage.split("-");
                lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1;
                //vector clock update
                String[] stringNumericalTimestamp = parseMessage[4].split(",");
                int[] numericalTimestamp = new int[stringNumericalTimestamp.length];
                for (int d = 0; d < stringNumericalTimestamp.length; d++) {
                    numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]);
                }
                VectorClass.update(myProcessId, numericalTimestamp);
                //
                int requestMade = Integer.parseInt(parseMessage[3] + parseMessage[1]);
                if (outstandingRequest == 1) {
                    if (requestMade < currentRequestBeingServed) {
                        lamportClock++;
                        //Newly inserted for vector timesatmp
                        int[] vector = VectorClass.increment(myProcessId);
                        String vectorClockConstruction = "";
                        for (int g = 0; g < vector.length; g++) {
                            if (g == 0) {
                                vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]);
                            } else {
                                vectorClockConstruction = vectorClockConstruction + ","
                                        + Integer.toString(vector[g]);
                            }
                        }
                        //
                        keyArray[Integer.parseInt(parseMessage[1])] = 0;
                        try {
                            byteBufferToNeighbor.clear();
                            initializeChannels();
                            sctpChannel[Integer.parseInt(parseMessage[1])]
                                    .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                            String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                    + lamportClock + "-" + vectorClockConstruction;
                            System.out.println("Message sent is : " + sendMessage);
                            MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                            byteBufferToNeighbor.put(sendMessage.getBytes());
                            byteBufferToNeighbor.flip();
                            sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                    messageInfoToNeighbor);
                            totalMessageCount++;
                            sctpChannel[Integer.parseInt(parseMessage[1])].close();
                        } catch (IOException ex) {
                            Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE,
                                    null, ex);
                        }
                        //Include block for reverse request
                        lamportClock++;
                        //Newly inserted for vector timesatmp
                        int[] vector1 = VectorClass.increment(myProcessId);
                        String vectorClockConstruction1 = "";
                        for (int g = 0; g < vector1.length; g++) {
                            if (g == 0) {
                                vectorClockConstruction1 = vectorClockConstruction1
                                        + Integer.toString(vector1[g]);
                            } else {
                                vectorClockConstruction1 = vectorClockConstruction1 + ","
                                        + Integer.toString(vector1[g]);
                            }
                        }
                        //
                        try {
                            byteBufferToNeighbor.clear();
                            initializeChannels();
                            sctpChannel[Integer.parseInt(parseMessage[1])]
                                    .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                            String sendMessage = "ReverseSend from Process-" + myProcessId + "-"
                                    + currentRequestBeingServed + "-" + lamportClock + "-"
                                    + vectorClockConstruction1;
                            System.out.println("Message sent is : " + sendMessage);
                            MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                            byteBufferToNeighbor.put(sendMessage.getBytes());
                            byteBufferToNeighbor.flip();
                            sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                    messageInfoToNeighbor);
                            totalMessageCount++;
                            sctpChannel[Integer.parseInt(parseMessage[1])].close();
                        } catch (IOException ex) {
                            Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE,
                                    null, ex);
                        }
                    } else if (requestMade == currentRequestBeingServed) {
                        if (Integer.parseInt(parseMessage[1]) < myProcessId) {
                            lamportClock++;
                            //Newly inserted for vector timesatmp
                            int[] vector = VectorClass.increment(myProcessId);
                            String vectorClockConstruction = "";
                            for (int g = 0; g < vector.length; g++) {
                                if (g == 0) {
                                    vectorClockConstruction = vectorClockConstruction
                                            + Integer.toString(vector[g]);
                                } else {
                                    vectorClockConstruction = vectorClockConstruction + ","
                                            + Integer.toString(vector[g]);
                                }
                            }
                            //
                            keyArray[Integer.parseInt(parseMessage[1])] = 0;
                            try {
                                byteBufferToNeighbor.clear();
                                initializeChannels();
                                sctpChannel[Integer.parseInt(parseMessage[1])]
                                        .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                                String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                        + lamportClock + "-" + vectorClockConstruction;
                                System.out.println("Message sent is : " + sendMessage);
                                MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                                byteBufferToNeighbor.put(sendMessage.getBytes());
                                byteBufferToNeighbor.flip();
                                sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                        messageInfoToNeighbor);
                                totalMessageCount++;
                                sctpChannel[Integer.parseInt(parseMessage[1])].close();
                            } catch (IOException ex) {
                                Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                            //Include block for reverse request
                            lamportClock++;
                            //Newly inserted for vector timesatmp
                            int[] vector1 = VectorClass.increment(myProcessId);
                            String vectorClockConstruction1 = "";
                            for (int g = 0; g < vector1.length; g++) {
                                if (g == 0) {
                                    vectorClockConstruction1 = vectorClockConstruction1
                                            + Integer.toString(vector1[g]);
                                } else {
                                    vectorClockConstruction1 = vectorClockConstruction1 + ","
                                            + Integer.toString(vector1[g]);
                                }
                            }
                            //
                            try {
                                byteBufferToNeighbor.clear();
                                initializeChannels();
                                sctpChannel[Integer.parseInt(parseMessage[1])]
                                        .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                                String sendMessage = "ReverseSend from Process-" + myProcessId + "-"
                                        + currentRequestBeingServed + "-" + lamportClock + "-"
                                        + vectorClockConstruction1;
                                System.out.println("Message sent is : " + sendMessage);
                                MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                                byteBufferToNeighbor.put(sendMessage.getBytes());
                                byteBufferToNeighbor.flip();
                                sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                        messageInfoToNeighbor);
                                totalMessageCount++;
                                sctpChannel[Integer.parseInt(parseMessage[1])].close();
                            } catch (IOException ex) {
                                Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                        } else if (myProcessId < Integer.parseInt(parseMessage[1])) {
                            queue.add(requestMade);
                        }
                    } else if (requestMade > currentRequestBeingServed) {
                        queue.add(requestMade);
                    }
                } else if (outstandingRequest == 0) {
                    lamportClock++;
                    //Newly inserted for vector timesatmp
                    int[] vector = VectorClass.increment(myProcessId);
                    String vectorClockConstruction = "";
                    for (int g = 0; g < vector.length; g++) {
                        if (g == 0) {
                            vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]);
                        } else {
                            vectorClockConstruction = vectorClockConstruction + ","
                                    + Integer.toString(vector[g]);
                        }
                    }
                    //
                    keyArray[Integer.parseInt(parseMessage[1])] = 0;
                    try {
                        byteBufferToNeighbor.clear();
                        initializeChannels();
                        sctpChannel[Integer.parseInt(parseMessage[1])]
                                .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                        String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                + lamportClock + "-" + vectorClockConstruction;
                        System.out.println("Message sent is : " + sendMessage);
                        MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                        byteBufferToNeighbor.put(sendMessage.getBytes());
                        byteBufferToNeighbor.flip();
                        sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                messageInfoToNeighbor);
                        totalMessageCount++;
                        sctpChannel[Integer.parseInt(parseMessage[1])].close();
                    } catch (IOException ex) {
                        Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }
            } else if (receiveMessage.contains("Key")) {
                //receive check condition execute critical section block
                String[] parseMessage = receiveMessage.split("-");
                lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1;
                //vector clock update
                String[] stringNumericalTimestamp = parseMessage[4].split(",");
                int[] numericalTimestamp = new int[stringNumericalTimestamp.length];
                for (int d = 0; d < stringNumericalTimestamp.length; d++) {
                    numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]);
                }
                VectorClass.update(myProcessId, numericalTimestamp);
                //
                keyArray[Integer.parseInt(parseMessage[1])] = 1;
                int countOnes = 0;
                for (int y = 0; y < numberOfProcesses; y++) {
                    if (keyArray[y] == 1) {
                        countOnes = countOnes + 1;
                    }
                }
                if (countOnes == numberOfProcesses) {
                    outstandingRequest = 0;
                    currentRequestBeingServed = 0;
                    enterCriticalSectionExecution();
                    timestamp2 = new Timestamp(System.currentTimeMillis());
                    csExit();
                }
            } else if (receiveMessage.contains("ReverseSend")) {
                String[] parseMessage = receiveMessage.split("-");
                lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1;
                //vector clock update
                String[] stringNumericalTimestamp = parseMessage[4].split(",");
                int[] numericalTimestamp = new int[stringNumericalTimestamp.length];
                for (int d = 0; d < stringNumericalTimestamp.length; d++) {
                    numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]);
                }
                VectorClass.update(myProcessId, numericalTimestamp);
                //
                int requestMade = Integer.parseInt(parseMessage[2]);
                if (outstandingRequest == 1) {
                    if (requestMade < currentRequestBeingServed) {
                        lamportClock++;
                        //Newly inserted for vector timesatmp
                        int[] vector = VectorClass.increment(myProcessId);
                        String vectorClockConstruction = "";
                        for (int g = 0; g < vector.length; g++) {
                            if (g == 0) {
                                vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]);
                            } else {
                                vectorClockConstruction = vectorClockConstruction + ","
                                        + Integer.toString(vector[g]);
                            }
                        }
                        //
                        keyArray[Integer.parseInt(parseMessage[1])] = 0;
                        try {
                            byteBufferToNeighbor.clear();
                            initializeChannels();
                            sctpChannel[Integer.parseInt(parseMessage[1])]
                                    .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                            String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                    + lamportClock + "-" + vectorClockConstruction;
                            System.out.println("Message sent is : " + sendMessage);
                            MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                            byteBufferToNeighbor.put(sendMessage.getBytes());
                            byteBufferToNeighbor.flip();
                            sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                    messageInfoToNeighbor);
                            totalMessageCount++;
                            sctpChannel[Integer.parseInt(parseMessage[1])].close();
                        } catch (IOException ex) {
                            Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE,
                                    null, ex);
                        }
                        //Include block for reverse request
                        lamportClock++;
                        //Newly inserted for vector timesatmp
                        int[] vector1 = VectorClass.increment(myProcessId);
                        String vectorClockConstruction1 = "";
                        for (int g = 0; g < vector1.length; g++) {
                            if (g == 0) {
                                vectorClockConstruction1 = vectorClockConstruction1
                                        + Integer.toString(vector1[g]);
                            } else {
                                vectorClockConstruction1 = vectorClockConstruction1 + ","
                                        + Integer.toString(vector1[g]);
                            }
                        }
                        //
                        try {
                            byteBufferToNeighbor.clear();
                            initializeChannels();
                            sctpChannel[Integer.parseInt(parseMessage[1])]
                                    .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                            String sendMessage = "ReverseSend from Process-" + myProcessId + "-"
                                    + currentRequestBeingServed + "-" + lamportClock + "-"
                                    + vectorClockConstruction1;
                            System.out.println("Message sent is : " + sendMessage);
                            MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                            byteBufferToNeighbor.put(sendMessage.getBytes());
                            byteBufferToNeighbor.flip();
                            sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                    messageInfoToNeighbor);
                            totalMessageCount++;
                            sctpChannel[Integer.parseInt(parseMessage[1])].close();
                        } catch (IOException ex) {
                            Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE,
                                    null, ex);
                        }
                    } else if (requestMade == currentRequestBeingServed) {
                        if (Integer.parseInt(parseMessage[1]) < myProcessId) {
                            lamportClock++;
                            //Newly inserted for vector timesatmp
                            int[] vector = VectorClass.increment(myProcessId);
                            String vectorClockConstruction = "";
                            for (int g = 0; g < vector.length; g++) {
                                if (g == 0) {
                                    vectorClockConstruction = vectorClockConstruction
                                            + Integer.toString(vector[g]);
                                } else {
                                    vectorClockConstruction = vectorClockConstruction + ","
                                            + Integer.toString(vector[g]);
                                }
                            }
                            //
                            keyArray[Integer.parseInt(parseMessage[1])] = 0;
                            try {
                                byteBufferToNeighbor.clear();
                                initializeChannels();
                                sctpChannel[Integer.parseInt(parseMessage[1])]
                                        .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                                String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                        + lamportClock + "-" + vectorClockConstruction;
                                System.out.println("Message sent is : " + sendMessage);
                                MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                                byteBufferToNeighbor.put(sendMessage.getBytes());
                                byteBufferToNeighbor.flip();
                                sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                        messageInfoToNeighbor);
                                totalMessageCount++;
                                sctpChannel[Integer.parseInt(parseMessage[1])].close();
                            } catch (IOException ex) {
                                Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                            //Include block for reverse request
                            lamportClock++;
                            //Newly inserted for vector timesatmp
                            int[] vector1 = VectorClass.increment(myProcessId);
                            String vectorClockConstruction1 = "";
                            for (int g = 0; g < vector1.length; g++) {
                                if (g == 0) {
                                    vectorClockConstruction1 = vectorClockConstruction1
                                            + Integer.toString(vector1[g]);
                                } else {
                                    vectorClockConstruction1 = vectorClockConstruction1 + ","
                                            + Integer.toString(vector1[g]);
                                }
                            }
                            //
                            try {
                                byteBufferToNeighbor.clear();
                                initializeChannels();
                                sctpChannel[Integer.parseInt(parseMessage[1])]
                                        .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                                String sendMessage = "ReverseSend from Process-" + myProcessId + "-"
                                        + currentRequestBeingServed + "-" + lamportClock + "-"
                                        + vectorClockConstruction1;
                                System.out.println("Message sent is : " + sendMessage);
                                MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                                byteBufferToNeighbor.put(sendMessage.getBytes());
                                byteBufferToNeighbor.flip();
                                sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                        messageInfoToNeighbor);
                                totalMessageCount++;
                                sctpChannel[Integer.parseInt(parseMessage[1])].close();
                            } catch (IOException ex) {
                                Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                        } else if (myProcessId < Integer.parseInt(parseMessage[1])) {
                            queue.add(requestMade);
                        }
                    } else if (requestMade > currentRequestBeingServed) {
                        queue.add(requestMade);
                    }
                } else if (outstandingRequest == 0) {
                    lamportClock++;
                    //Newly inserted for vector timesatmp
                    int[] vector = VectorClass.increment(myProcessId);
                    String vectorClockConstruction = "";
                    for (int g = 0; g < vector.length; g++) {
                        if (g == 0) {
                            vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]);
                        } else {
                            vectorClockConstruction = vectorClockConstruction + ","
                                    + Integer.toString(vector[g]);
                        }
                    }
                    //
                    keyArray[Integer.parseInt(parseMessage[1])] = 0;
                    try {
                        byteBufferToNeighbor.clear();
                        initializeChannels();
                        sctpChannel[Integer.parseInt(parseMessage[1])]
                                .connect(socketAddress[Integer.parseInt(parseMessage[1])]);
                        String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-"
                                + lamportClock + "-" + vectorClockConstruction;
                        System.out.println("Message sent is : " + sendMessage);
                        MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0);
                        byteBufferToNeighbor.put(sendMessage.getBytes());
                        byteBufferToNeighbor.flip();
                        sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor,
                                messageInfoToNeighbor);
                        totalMessageCount++;
                        sctpChannel[Integer.parseInt(parseMessage[1])].close();
                    } catch (IOException ex) {
                        Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }
            } else if (receiveMessage.contains("Finish")) {
                String[] parseMessage = receiveMessage.split("-");
                lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1;
                //vector clock update
                String[] stringNumericalTimestamp = parseMessage[4].split(",");
                int[] numericalTimestamp = new int[stringNumericalTimestamp.length];
                for (int d = 0; d < stringNumericalTimestamp.length; d++) {
                    numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]);
                }
                VectorClass.update(myProcessId, numericalTimestamp);
                //
                finishFlagArray[Integer.parseInt(parseMessage[1])] = 1;
                int count = 0;
                for (int v = 0; v < numberOfProcesses; v++) {
                    if (finishFlagArray[v] == 1) {
                        count = count + 1;
                    }
                }
                if (count == numberOfProcesses) {
                    break;
                }
            }
        }
        mutex.release();
    }
}

From source file:com.twitter.heron.scheduler.RuntimeManagerMain.java

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
        InstantiationException, IOException, ParseException {

    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);//ww w  .  j ava 2s  .  c om
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }

    Boolean verbose = false;
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
        verbose = true;
    }

    // init log
    LoggingHelper.loggerInit(logLevel, false);

    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    String heronHome = cmd.getOptionValue("heron_home");
    String configPath = cmd.getOptionValue("config_path");
    String overrideConfigFile = cmd.getOptionValue("override_config_file");
    String releaseFile = cmd.getOptionValue("release_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String commandOption = cmd.getOptionValue("command");

    // Optional argument in the case of restart
    // TODO(karthik): convert into CLI
    String containerId = Integer.toString(-1);
    if (cmd.hasOption("container_id")) {
        containerId = cmd.getOptionValue("container_id");
    }

    Command command = Command.makeCommand(commandOption);

    // first load the defaults, then the config from files to override it
    Config.Builder defaultsConfig = Config.newBuilder().putAll(ClusterDefaults.getDefaults())
            .putAll(ClusterConfig.loadConfig(heronHome, configPath, releaseFile));

    // add config parameters from the command line
    Config.Builder commandLineConfig = Config.newBuilder().put(Keys.cluster(), cluster).put(Keys.role(), role)
            .put(Keys.environ(), environ).put(Keys.verbose(), verbose)
            .put(Keys.topologyContainerId(), containerId);

    Config.Builder topologyConfig = Config.newBuilder().put(Keys.topologyName(), topologyName);

    Config.Builder overrideConfig = Config.newBuilder()
            .putAll(ClusterConfig.loadOverrideConfig(overrideConfigFile));

    // build the final config by expanding all the variables
    Config config = Config
            .expand(Config.newBuilder().putAll(defaultsConfig.build()).putAll(overrideConfig.build())
                    .putAll(commandLineConfig.build()).putAll(topologyConfig.build()).build());

    LOG.fine("Static config loaded successfully ");
    LOG.fine(config.toString());

    // Create a new instance of RuntimeManagerMain
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, command);
    boolean isSuccessful = runtimeManagerMain.manageTopology();

    // Log the result and exit
    if (!isSuccessful) {
        throw new RuntimeException(String.format("Failed to %s topology %s", command, topologyName));
    } else {
        LOG.log(Level.FINE, "Topology {0} {1} successfully", new Object[] { topologyName, command });
    }
}

From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java

public static void main(final String[] arg) throws JSAPException, IOException {
    final SimpleJSAP jsap = new SimpleJSAP(URLMPHVirtualDocumentResolver.class.getName(),
            "Builds a URL document resolver from a sequence of URIs, extracted typically using ScanMetadata, using a suitable function. You can specify that the list is sorted, in which case it is possible to generate a resolver that occupies less space.",
            new Parameter[] {
                    new Switch("sorted", 's', "sorted",
                            "URIs are sorted: use a monotone minimal perfect hash function."),
                    new Switch("iso", 'i', "iso",
                            "Use ISO-8859-1 coding internally (i.e., just use the lower eight bits of each character)."),
                    new FlaggedOption("bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',
                            "buffer-size", "The size of the I/O buffer used to read terms."),
                    new FlaggedOption("class", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            'c', "class",
                            "A class used to create the function from URIs to their ranks; defaults to it.unimi.dsi.sux4j.mph.MHWCFunction for non-sorted inputs, and to it.unimi.dsi.sux4j.mph.TwoStepsLcpMonotoneMinimalPerfectHashFunction for sorted inputs."),
                    new FlaggedOption("width", JSAP.INTEGER_PARSER, Integer.toString(Long.SIZE),
                            JSAP.NOT_REQUIRED, 'w', "width",
                            "The width, in bits, of the signatures used to sign the function from URIs to their rank."),
                    new FlaggedOption("termFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o',
                            "offline",
                            "Read terms from this file (without loading them into core memory) instead of standard input."),
                    new FlaggedOption("uniqueUris", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            'U', "unique-uris",
                            "Force URIs to be unique by adding random garbage at the end of duplicates; the argument is an upper bound for the number of URIs that will be read, and will be used to create a Bloom filter."),
                    new UnflaggedOption("resolver", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED,
                            JSAP.NOT_GREEDY, "The filename for the resolver.") });

    JSAPResult jsapResult = jsap.parse(arg);
    if (jsap.messagePrinted())
        return;//  w w w  .  j a  v a  2 s .c  o m

    final int bufferSize = jsapResult.getInt("bufferSize");
    final String resolverName = jsapResult.getString("resolver");
    //final Class<?> tableClass = jsapResult.getClass( "class" );
    final boolean iso = jsapResult.getBoolean("iso");
    String termFile = jsapResult.getString("termFile");

    BloomFilter<Void> filter = null;
    final boolean uniqueURIs = jsapResult.userSpecified("uniqueUris");
    if (uniqueURIs)
        filter = BloomFilter.create(jsapResult.getInt("uniqueUris"));

    final Collection<? extends CharSequence> collection;
    if (termFile == null) {
        ArrayList<MutableString> termList = new ArrayList<MutableString>();
        final ProgressLogger pl = new ProgressLogger();
        pl.itemsName = "URIs";
        final LineIterator termIterator = new LineIterator(
                new FastBufferedReader(new InputStreamReader(System.in, "UTF-8"), bufferSize), pl);

        pl.start("Reading URIs...");
        MutableString uri;
        while (termIterator.hasNext()) {
            uri = termIterator.next();
            if (uniqueURIs)
                makeUnique(filter, uri);
            termList.add(uri.copy());
        }
        pl.done();

        collection = termList;
    } else {
        if (uniqueURIs) {
            // Create temporary file with unique URIs
            final ProgressLogger pl = new ProgressLogger();
            pl.itemsName = "URIs";
            pl.start("Copying URIs...");
            final LineIterator termIterator = new LineIterator(
                    new FastBufferedReader(new InputStreamReader(new FileInputStream(termFile)), bufferSize),
                    pl);
            File temp = File.createTempFile(URLMPHVirtualDocumentResolver.class.getName(), ".uniqueuris");
            temp.deleteOnExit();
            termFile = temp.toString();
            final FastBufferedOutputStream outputStream = new FastBufferedOutputStream(
                    new FileOutputStream(termFile), bufferSize);
            MutableString uri;
            while (termIterator.hasNext()) {
                uri = termIterator.next();
                makeUnique(filter, uri);
                uri.writeUTF8(outputStream);
                outputStream.write('\n');
            }
            pl.done();
            outputStream.close();
        }
        collection = new FileLinesCollection(termFile, "UTF-8");
    }
    LOGGER.debug("Building function...");
    final int width = jsapResult.getInt("width");
    if (jsapResult.getBoolean("sorted"))
        BinIO.storeObject(
                new URLMPHVirtualDocumentResolver(
                        new ShiftAddXorSignedStringMap(collection.iterator(),
                                new TwoStepsLcpMonotoneMinimalPerfectHashFunction<CharSequence>(collection,
                                        iso ? TransformationStrategies.prefixFreeIso()
                                                : TransformationStrategies.prefixFreeUtf16()),
                                width)),
                resolverName);
    else
        BinIO.storeObject(
                new URLMPHVirtualDocumentResolver(new ShiftAddXorSignedStringMap(collection.iterator(),
                        new MWHCFunction<CharSequence>(collection,
                                iso ? TransformationStrategies.iso() : TransformationStrategies.utf16()),
                        width)),
                resolverName);
    LOGGER.debug(" done.");
}

From source file:SuperPeer.java

/**
 * The good stuff.//from   w  w w . j  ava 2s  . c  o  m
 */
public static void main(String[] argv) {
    int mbits = 5;
    ArgumentHandler cli = new ArgumentHandler("SuperPeer [-h]",
            "Run a DHT SuperPeer and attached to the specified superpeer.",
            "Bala Subrahmanyam Kambala, Daniel William DaCosta - GPLv3 (http://www.gnu.org/copyleft/gpl.html)");
    cli.addOption("h", "help", false, "Print this usage information.");
    cli.addOption("m", "mbits", true,
            "The maximum number of unique keys in terms of 2^m (Default is " + Integer.toString(mbits) + ").");

    CommandLine commandLine = cli.parse(argv);
    if (commandLine.hasOption('h')) {
        cli.usage("");
        System.exit(0);
    }
    if (commandLine.hasOption('m')) {
        //XXX:uncaught exception!
        mbits = Integer.parseInt((commandLine.getOptionValue('m')));
    }
    try {
        Naming.rebind("SuperPeer", new SuperPeer(mbits));
    } catch (Exception e) {
        System.out.println("SuperPeer failed: " + e);
    }
}

From source file:eu.fbk.dkm.sectionextractor.WikipediaBirthDeathDateExtractor.java

public static void main(String args[]) throws IOException {

    CommandLineWithLogger commandLineWithLogger = new CommandLineWithLogger();
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump").create("d"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("output file")
            .isRequired().withLongOpt("output-file").create("o"));

    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription(//w  ww  .  ja  va2 s .c  om
                    "number of threads (default " + AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER + ")")
            .withLongOpt("num-threads").create("t"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("number of pages to process (default all)").withLongOpt("num-pages").create("p"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("receive notification every n pages (default "
                    + AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT + ")")
            .withLongOpt("notification-point").create("b"));

    CommandLine commandLine = null;
    try {
        commandLine = commandLineWithLogger.getCommandLine(args);
        PropertyConfigurator.configure(commandLineWithLogger.getLoggerProps());
    } catch (Exception e) {
        System.exit(1);
    }

    int numThreads = Integer.parseInt(commandLine.getOptionValue("num-threads",
            Integer.toString(AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER)));
    int numPages = Integer.parseInt(commandLine.getOptionValue("num-pages",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NUM_PAGES)));
    int notificationPoint = Integer.parseInt(commandLine.getOptionValue("notification-point",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT)));

    File outputFile = new File(commandLine.getOptionValue("output-file"));
    ExtractorParameters extractorParameters = new ExtractorParameters(
            commandLine.getOptionValue("wikipedia-dump"), outputFile.getAbsolutePath());

    WikipediaExtractor wikipediaPageParser = new WikipediaBirthDeathDateExtractor(numThreads, numPages,
            extractorParameters.getLocale(), outputFile);
    wikipediaPageParser.setNotificationPoint(notificationPoint);
    wikipediaPageParser.start(extractorParameters);

    logger.info("extraction ended " + new Date());

}

From source file:com.jug.MotherMachine.java

/**
 * PROJECT MAIN/*from w  ww  .  j a va2s.  co  m*/
 * ============
 *
 * @param args
 *            muh!
 */
public static void main(final String[] args) {
    try {

        final MotherMachine main = new MotherMachine();
        guiFrame = new JFrame("Interactive MotherMachine");
        main.initMainWindow(guiFrame);

        props = main.loadParams();
        BGREM_TEMPLATE_XMIN = Integer
                .parseInt(props.getProperty("BGREM_TEMPLATE_XMIN", Integer.toString(BGREM_TEMPLATE_XMIN)));
        BGREM_TEMPLATE_XMAX = Integer
                .parseInt(props.getProperty("BGREM_TEMPLATE_XMAX", Integer.toString(BGREM_TEMPLATE_XMAX)));
        BGREM_X_OFFSET = Integer
                .parseInt(props.getProperty("BGREM_X_OFFSET", Integer.toString(BGREM_X_OFFSET)));
        GL_OFFSET_BOTTOM = Integer
                .parseInt(props.getProperty("GL_OFFSET_BOTTOM", Integer.toString(GL_OFFSET_BOTTOM)));
        GL_OFFSET_TOP = Integer.parseInt(props.getProperty("GL_OFFSET_TOP", Integer.toString(GL_OFFSET_TOP)));
        GL_OFFSET_LATERAL = Integer
                .parseInt(props.getProperty("GL_OFFSET_LATERAL", Integer.toString(GL_OFFSET_LATERAL)));
        MIN_CELL_LENGTH = Integer
                .parseInt(props.getProperty("MIN_CELL_LENGTH", Integer.toString(MIN_CELL_LENGTH)));
        MIN_GAP_CONTRAST = Double
                .parseDouble(props.getProperty("MIN_GAP_CONTRAST", Double.toString(MIN_GAP_CONTRAST)));
        SIGMA_PRE_SEGMENTATION_X = Double.parseDouble(
                props.getProperty("SIGMA_PRE_SEGMENTATION_X", Double.toString(SIGMA_PRE_SEGMENTATION_X)));
        SIGMA_PRE_SEGMENTATION_Y = Double.parseDouble(
                props.getProperty("SIGMA_PRE_SEGMENTATION_Y", Double.toString(SIGMA_PRE_SEGMENTATION_Y)));
        SIGMA_GL_DETECTION_X = Double
                .parseDouble(props.getProperty("SIGMA_GL_DETECTION_X", Double.toString(SIGMA_GL_DETECTION_X)));
        SIGMA_GL_DETECTION_Y = Double
                .parseDouble(props.getProperty("SIGMA_GL_DETECTION_Y", Double.toString(SIGMA_GL_DETECTION_Y)));
        DEFAULT_PATH = props.getProperty("DEFAULT_PATH", DEFAULT_PATH);

        GUI_POS_X = Integer.parseInt(props.getProperty("GUI_POS_X", Integer.toString(DEFAULT_GUI_POS_X)));
        GUI_POS_Y = Integer.parseInt(props.getProperty("GUI_POS_Y", Integer.toString(DEFAULT_GUI_POS_X)));
        GUI_WIDTH = Integer.parseInt(props.getProperty("GUI_WIDTH", Integer.toString(GUI_WIDTH)));
        GUI_HEIGHT = Integer.parseInt(props.getProperty("GUI_HEIGHT", Integer.toString(GUI_HEIGHT)));
        GUI_CONSOLE_WIDTH = Integer
                .parseInt(props.getProperty("GUI_CONSOLE_WIDTH", Integer.toString(GUI_CONSOLE_WIDTH)));
        // Iterate over all currently attached monitors and check if sceen position is actually possible,
        // otherwise fall back to the DEFAULT values and ignore the ones coming from the properties-file.
        boolean pos_ok = false;
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice[] gs = ge.getScreenDevices();
        for (int i = 0; i < gs.length; i++) {
            final DisplayMode dm = gs[i].getDisplayMode();
            if (gs[i].getDefaultConfiguration().getBounds()
                    .contains(new java.awt.Point(GUI_POS_X, GUI_POS_Y))) {
                pos_ok = true;
            }
        }
        // None of the screens contained the top-left window coordinates --> fall back onto default values...
        if (!pos_ok) {
            GUI_POS_X = DEFAULT_GUI_POS_X;
            GUI_POS_Y = DEFAULT_GUI_POS_Y;
        }

        String path = props.getProperty("import_path", System.getProperty("user.home"));
        final File fPath = main.showStartupDialog(guiFrame, path);
        path = fPath.getAbsolutePath();
        props.setProperty("import_path", fPath.getAbsolutePath());

        // Setting up console window and window snapper...
        main.initConsoleWindow();
        main.showConsoleWindow();
        final JFrameSnapper snapper = new JFrameSnapper();
        snapper.addFrame(main.frameConsoleWindow);
        snapper.addFrame(guiFrame);

        // ---------------------------------------------------
        main.processDataFromFolder(path);
        // ---------------------------------------------------

        System.out.print("Build and show GUI...");
        // show loaded and annotated data
        ImageJFunctions.show(main.imgRaw, "Rotated & cropped raw data");
        ImageJFunctions.show(main.imgTemp, "Temporary");
        ImageJFunctions.show(main.imgAnnotated, "Annotated ARGB data");

        final MotherMachineGui gui = new MotherMachineGui(new MotherMachineModel(main));
        gui.setVisible(true);

        main.ij = new ImageJ();
        guiFrame.add(gui);
        guiFrame.setSize(GUI_WIDTH, GUI_HEIGHT);
        guiFrame.setLocation(GUI_POS_X, GUI_POS_Y);
        guiFrame.setVisible(true);

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                snapper.snapFrames(main.frameConsoleWindow, guiFrame, JFrameSnapper.EAST);
            }
        });

        System.out.println(" done!");
    } catch (final UnsatisfiedLinkError ulr) {
        JOptionPane.showMessageDialog(MotherMachine.guiFrame,
                "Could initialize Gurobi.\n"
                        + "You might not have installed Gurobi properly or you miss a valid license.\n"
                        + "Please visit 'www.gurobi.com' for further information.\n\n" + ulr.getMessage(),
                "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.artistech.tuio.mouse.MouseDriver.java

/**
 * Main: can take a port value as an argument.
 *
 * @param args/*from   w w w.  jav a2s. c om*/
 */
public static void main(String args[]) {
    int tuio_port = 3333;

    Options options = new Options();
    options.addOption("t", "tuio-port", true, "TUIO Port to listen on. (Default = 3333)");
    options.addOption("h", "help", false, "Show this message.");
    HelpFormatter formatter = new HelpFormatter();

    try {
        CommandLineParser parser = new org.apache.commons.cli.BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            formatter.printHelp("tuio-mouse-driver", options);
            return;
        } else {
            if (cmd.hasOption("t") || cmd.hasOption("tuio-port")) {
                tuio_port = Integer.parseInt(cmd.getOptionValue("t"));
            }
        }
    } catch (ParseException | NumberFormatException ex) {
        System.err.println("Error Processing Command Options:");
        formatter.printHelp("tuio-mouse-driver", options);
        return;
    }

    try {
        MouseDriver mouse = new MouseDriver();
        TuioClient client = new TuioClient(tuio_port);

        logger.info(
                MessageFormat.format("Listening to TUIO message at port: {0}", Integer.toString(tuio_port)));
        client.addTuioListener(mouse);
        client.connect();
    } catch (AWTException e) {
        logger.fatal(null, e);
    }
}

From source file:com.bah.applefox.main.Ingest.java

public static void main(String[] args) throws Exception {

    if (args.length == 1 && args[0].equals("--help")) {
        System.out.println("Not enough arguments");
        System.out.println("Arguments should be in the format <properties file> <command>");
        System.out.println("Valid commands:");
        System.out.println("\tpr: Calculates Page Rank");
        System.out.println("\timageload: Loads Images from URLs");
        System.out.println("\tload: Loads Full Text Data");
        System.out.println("\tingest: Ingests URLs from given seed");
        System.out.println("\tftsample: Creates a Full Text Index Sample HashMap");
        System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap");
    }// w  w  w.ja v a 2 s  . c o m
    if (args.length > 2) {
        System.out.println("2 Arguments expected, " + args.length + " given.");
    }

    if (args.length < 2) {
        System.out.println("Not enough arguments");
        System.out.println("Arguments should be in the format <properties file> <command>");
        System.out.println("Valid commands:");
        System.out.println("\tpr: Calculates Page Rank");
        System.out.println("\timageload: Loads Images from URLs");
        System.out.println("\tload: Loads Full Text Data");
        System.out.println("\tingest: Ingests URLs from given seed");
        System.out.println("\tftsample: Creates a Full Text Index Sample HashMap");
        System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap");
    }
    injector = Guice.createInjector(new IngesterModule());

    // The properties object to read from the configuration file
    Properties properties = new Properties();

    try {
        // Load configuration file from the command line
        properties.load(new FileInputStream(args[0]));
    } catch (Exception e) {
        log.error("ABORT: File not found or could not read from file ->" + e.getMessage());
        log.error("Enter the location of the configuration file");
        System.exit(1);
    }

    // Initialize variables from configuration file

    // Accumulo Variables
    INSTANCE_NAME = properties.getProperty("INSTANCE_NAME");
    ZK_SERVERS = properties.getProperty("ZK_SERVERS");
    USERNAME = properties.getProperty("USERNAME");
    PASSWORD = properties.getProperty("PASSWORD");
    SPLIT_SIZE = properties.getProperty("SPLIT_SIZE");
    NUM_ITERATIONS = Integer.parseInt(properties.getProperty("NUM_ITERATIONS"));
    NUM_NODES = Integer.parseInt(properties.getProperty("NUM_NODES"));

    // General Search Variables
    MAX_NGRAMS = Integer.parseInt(properties.getProperty("MAX_NGRAMS"));
    GENERAL_STOP = properties.getProperty("GENERAL_STOP");

    // Full Text Variables
    FT_DATA_TABLE = properties.getProperty("FT_DATA_TABLE");
    FT_SAMPLE = properties.getProperty("FT_SAMPLE");
    FT_CHECKED_TABLE = properties.getProperty("FT_CHECKED_TABLE");
    FT_DIVS_FILE = properties.getProperty("FT_DIVS_FILE");
    FT_SPLIT_SIZE = properties.getProperty("FT_SPLIT_SIZE");

    // Web Crawler Variables
    URL_TABLE = properties.getProperty("URL_TABLE");
    SEED = properties.getProperty("SEED");
    USER_AGENT = properties.getProperty("USER_AGENT");
    URL_SPLIT_SIZE = properties.getProperty("URL_SPLIT_SIZE");

    // Page Rank Variables
    PR_TABLE_PREFIX = properties.getProperty("PR_TABLE_PREFIX");
    PR_URL_MAP_TABLE_PREFIX = properties.getProperty("PR_URL_MAP_TABLE_PREFIX");
    PR_OUT_LINKS_COUNT_TABLE = properties.getProperty("PR_OUT_LINKS_COUNT_TABLE");
    PR_FILE = properties.getProperty("PR_FILE");
    PR_DAMPENING_FACTOR = Double.parseDouble(properties.getProperty("PR_DAMPENING_FACTOR"));
    PR_ITERATIONS = Integer.parseInt(properties.getProperty("PR_ITERATIONS"));
    PR_SPLIT_SIZE = properties.getProperty("PR_SPLIT_SIZE");

    // Image Variables
    IMG_HASH_TABLE = properties.getProperty("IMG_HASH_TABLE");
    IMG_CHECKED_TABLE = properties.getProperty("IMG_CHECKED_TABLE");
    IMG_TAG_TABLE = properties.getProperty("IMG_TAG_TABLE");
    IMG_HASH_SAMPLE_TABLE = properties.getProperty("IMG_HASH_SAMPLE_TABLE");
    IMG_TAG_SAMPLE_TABLE = properties.getProperty("IMG_TAG_SAMPLE_TABLE");
    IMG_SPLIT_SIZE = properties.getProperty("IMG_SPLIT_SIZE");

    // Future Use:
    // Work Directory in HDFS
    WORK_DIR = properties.getProperty("WORK_DIR");

    // Initialize variable from command line
    RUN = args[1].toLowerCase();

    // Set the instance information for AccumuloUtils
    AccumuloUtils.setInstanceName(INSTANCE_NAME);
    AccumuloUtils.setInstancePassword(PASSWORD);
    AccumuloUtils.setUser(USERNAME);
    AccumuloUtils.setZooserver(ZK_SERVERS);
    AccumuloUtils.setSplitSize(SPLIT_SIZE);

    String[] temp = new String[25];

    // Accumulo Variables
    temp[0] = INSTANCE_NAME;
    temp[1] = ZK_SERVERS;
    temp[2] = USERNAME;
    temp[3] = PASSWORD;

    // Number of Map Tasks
    temp[4] = Integer.toString((int) Math.ceil(1.75 * NUM_NODES * 2));

    // Web Crawler Variables
    temp[5] = URL_TABLE;
    temp[6] = USER_AGENT;

    // Future Use
    temp[7] = WORK_DIR;

    // General Search
    temp[8] = GENERAL_STOP;
    temp[9] = Integer.toString(MAX_NGRAMS);

    // Full Text Variables
    temp[10] = FT_DATA_TABLE;
    temp[11] = FT_CHECKED_TABLE;

    // Page Rank Variables
    temp[12] = PR_URL_MAP_TABLE_PREFIX;
    temp[13] = PR_TABLE_PREFIX;
    temp[14] = Double.toString(PR_DAMPENING_FACTOR);
    temp[15] = PR_OUT_LINKS_COUNT_TABLE;
    temp[16] = PR_FILE;

    // Image Variables
    temp[17] = IMG_HASH_TABLE;
    temp[18] = IMG_CHECKED_TABLE;
    temp[19] = IMG_TAG_TABLE;

    temp[20] = FT_DIVS_FILE;

    // Table Split Sizes
    temp[21] = FT_SPLIT_SIZE;
    temp[22] = IMG_SPLIT_SIZE;
    temp[23] = URL_SPLIT_SIZE;
    temp[24] = PR_SPLIT_SIZE;

    if (RUN.equals("pr")) {
        // Run PR_ITERATIONS number of iterations for page ranking
        PageRank.createPageRank(temp, PR_ITERATIONS, URL_SPLIT_SIZE);
    } else if (RUN.equals("imageload")) {
        // Load image index
        AccumuloUtils.setSplitSize(URL_SPLIT_SIZE);
        ToolRunner.run(new ImageLoader(), temp);
    } else if (RUN.equals("ingest")) {
        // Ingest
        System.out.println("Ingesting");
        // Set table split size
        AccumuloUtils.setSplitSize(URL_SPLIT_SIZE);
        // Write the seed value to the table
        BatchWriter w;
        Value v = new Value();
        v.set("0".getBytes());
        Mutation m = new Mutation(SEED);
        m.put("0", "0", v);
        w = AccumuloUtils.connectBatchWrite(URL_TABLE);
        w.addMutation(m);

        for (int i = 0; i < NUM_ITERATIONS; i++) {
            // Run the ToolRunner for NUM_ITERATIONS iterations
            ToolRunner.run(CachedConfiguration.getInstance(), injector.getInstance(Ingester.class), temp);
        }
    } else if (RUN.equals("load")) {
        // Parse the URLs and add to the data table
        AccumuloUtils.setSplitSize(URL_SPLIT_SIZE);
        BatchWriter w = AccumuloUtils.connectBatchWrite(FT_CHECKED_TABLE);
        w.close();

        AccumuloUtils.setSplitSize(FT_SPLIT_SIZE);
        w = AccumuloUtils.connectBatchWrite(FT_DATA_TABLE);
        w.close();
        ToolRunner.run(CachedConfiguration.getInstance(), injector.getInstance(Loader.class), temp);
    } else if (RUN.equals("ftsample")) {
        // Create a sample table for full text index
        FTAccumuloSampler ftSampler = new FTAccumuloSampler(FT_SAMPLE, FT_DATA_TABLE, FT_CHECKED_TABLE);
        ftSampler.createSample();

    } else if (RUN.equals("imagesample")) {
        // Create a sample table for images
        ImageAccumuloSampler imgHashSampler = new ImageAccumuloSampler(IMG_HASH_SAMPLE_TABLE, IMG_HASH_TABLE,
                IMG_CHECKED_TABLE);
        imgHashSampler.createSample();

        ImageAccumuloSampler imgTagSampler = new ImageAccumuloSampler(IMG_TAG_SAMPLE_TABLE, IMG_TAG_TABLE,
                IMG_CHECKED_TABLE);
        imgTagSampler.createSample();
    } else {
        System.out.println("Invalid argument " + RUN + ".");
        System.out.println("Valid Arguments:");
        System.out.println("\tpr: Calculates Page Rank");
        System.out.println("\timageload: Loads Images from URLs");
        System.out.println("\tload: Loads Full Text Data");
        System.out.println("\tingest: Ingests URLs from given seed");
        System.out.println("\tftsample: Creates a Full Text Index Sample HashMap");
        System.out.println("\timagesample: Creates an Image Hash and Image Tag Sample HashMap");
    }

}