Example usage for java.rmi ConnectException printStackTrace

List of usage examples for java.rmi ConnectException printStackTrace

Introduction

In this page you can find the example usage for java.rmi ConnectException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:ComputeNode.java

public static void main(String[] argv) {

    String fileservername = "localhost";
    String id = null;/*  w w  w . jav  a2s  .  c o m*/
    Double underLoad = null;
    Double overLoad = null;
    Double failProb = null;
    Double constantload = null;
    Pair<Double, Double> gaussian = null;
    String fileName = null;

    ArgumentHandler cli = new ArgumentHandler(
            "FileServer [-h] [collector address] [-u underload] "
                    + "[-o overload] [-c constant_load|-g mean variance] " + "[-p fail_prob] [-f configfile]",
            "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("u", "underLoad", true, "Under load threshold");
    cli.addOption("o", "overLoad", true, "Over load threshold");
    cli.addOption("c", "constant", true, "Generate constant load");
    cli.addOption("p", "probability", true, "Fail Probability(0-100)");
    cli.addOption("f", "configfile", true,
            "The configuration file to read parameters from. " + "The default is " + defaultconf + ". "
                    + "Command line arguments will override config file " + "arguments.");
    cli.addOption(OptionBuilder.withLongOpt("gaussian").hasArgs(2)
            .withDescription("Generate a gaussian probability model for load "
                    + "simulation. The first parameter is the mean "
                    + "and the second parameter is the variance.")
            .create('g'));

    // parse command line
    CommandLine commandLine = cli.parse(argv);
    if (commandLine.hasOption('h')) {
        cli.usage("");
        System.exit(0);
    }

    if (commandLine.hasOption('u')) {
        // TODO : Ensure the number is within range
        underLoad = Double.parseDouble(commandLine.getOptionValue('u'));
    }

    if (commandLine.hasOption('o')) {
        // TODO : Ensure the number is within range
        overLoad = Double.parseDouble(commandLine.getOptionValue('o'));
    }

    if (commandLine.hasOption('p')) {
        // TODO : Ensure the number is within range
        failProb = Double.parseDouble(commandLine.getOptionValue('p'));
    }

    if (commandLine.hasOption('c')) {
        // TODO : Ensure the number is within range
        constantload = Double.parseDouble(commandLine.getOptionValue('c'));
    }

    if (commandLine.hasOption('g')) {
        // TODO : Ensure the number is within range
        gaussian = new Pair<Double, Double>(Double.parseDouble(commandLine.getOptionValues('g')[0]),
                Double.parseDouble(commandLine.getOptionValues('g')[1]));
    }

    // TODO: If these flags are no longer mutually exclusive this
    // code should be adjusted to account for whatever constraint are
    // needed.
    if ((constantload != null) && (gaussian != null)) {
        cli.usage("-g -c switches are mutually exclusive!\n");
        System.exit(1);
    }

    if (commandLine.hasOption('f')) {
        fileName = commandLine.getOptionValue('f');
    }

    if (commandLine.getArgs().length != 0)
        fileservername = commandLine.getArgs()[0];
    System.out.println(argv);
    try {
        ComputeNode node = new ComputeNode(fileservername, underLoad, overLoad, failProb, constantload,
                gaussian, fileName);

        Naming.rebind("ComputeNode" + Integer.toString(node.getID()), node);

        // Scheduling heart beat message handler
        Timer t = new Timer();
        HeartBeatHandler h = node.new HeartBeatHandler();
        t.schedule(h, 0, 1 * 1000);

    } catch (ConnectException ce) {
        //lg.log(Level.SEVERE, "Server is not alive");
        ce.printStackTrace();
    } catch (Exception e) {
        //lg.log(Level.SEVERE, "Exception in file server");
        e.printStackTrace();
    }
}

From source file:de.clusteval.serverclient.BackendClientCompleter.java

/**
 * @param clientId//from ww  w .  j a  v  a2s.  c  om
 *            The id of the client needed for communication between this
 *            completer and the server.
 * @param args
 *            The parameters of the client (e.g. server ip and port) for
 *            communication between this completer and the server.
 */
public BackendClientCompleter(final String clientId, final String[] args) {
    super();

    this.clientId = clientId;
    try {
        newArgs = ArraysExt.merge(args, new String[] { "-clientId", clientId });
        client = new BackendClient(newArgs);
    } catch (ConnectException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:edu.clemson.cs.nestbed.server.util.RemoteObservableImpl.java

public void notifyObservers(Serializable msg, Serializable arg) {
    List<RemoteObserver> deadObservers = new ArrayList<RemoteObserver>();

    String msgType = (msg != null) ? msg.getClass().getName() : "";
    String argType = (arg != null) ? arg.getClass().getName() : "";

    //        log.debug("Notifying observers\n"  +
    //                  "  message\n"  +
    //                  "    type:   " + msgType + "\n" +
    //                  "    value:  " + msg     + "\n" +
    //                  "  argument\n" +
    //                  "    type:   " + argType + "\n" +
    //                  "    value:  " + arg);

    for (RemoteObserver i : new ArrayList<RemoteObserver>(observers)) {
        try {/*from  ww w.ja v a 2s .com*/
            i.update(msg, arg);
        } catch (ConnectException e) {
            log.info("Dropping RemoteObserver:\n" + i);
            deadObservers.add(i);
        } catch (NoSuchObjectException e) {
            log.info("Dropping RemoteObserver:\n" + i);
            deadObservers.add(i);
        } catch (Exception e) {
            log.error("Exception occured while processing observers", e);
            e.printStackTrace();
        }
    }

    try {
        for (RemoteObserver i : deadObservers) {
            deleteRemoteObserver(i);
        }
    } catch (RemoteException e) {
        /* empty */ }
}

From source file:de.clusteval.serverclient.BackendClientCompleter.java

@SuppressWarnings("unused")
@Override/*  w ww. j a va  2  s .c o  m*/
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    SortedSet<String> strings = new TreeSet<String>();
    strings.add("performRun");
    strings.add("resumeRun");
    strings.add("terminateRun");
    strings.add("getRunStatus");
    strings.add("getOptRunStatus");
    strings.add("shutdown");
    strings.add("getRuns");
    strings.add("getQueue");
    strings.add("getRunResumes");
    strings.add("getDataSets");
    strings.add("getPrograms");
    strings.add("getRunResults");
    strings.add("generateDataSet");
    strings.add("randomizeDataConfig");
    strings.add("getActiveThreads");

    boolean exception = true;
    while (exception) {
        exception = false;
        try {
            if (buffer == null) {
                candidates.addAll(strings);
            } else if (buffer.equals("performRun ")) {
                this.updateRuns();
                candidates.addAll(runs);
                return buffer.length();
            } else if (buffer.equals("resumeRun ")) {
                this.updateRunResumes();
                candidates.addAll(runResumes);
                return buffer.length();
            } else if (buffer.equals("getRunResults ")) {
                this.updateRunResults();
                candidates.addAll(runResults);
                return buffer.length();
            } else if (buffer.equals("getRunResumes ")) {
                this.updateRunResumes();
                candidates.addAll(runResumes);
                return buffer.length();
            } else if (buffer.equals("terminateRun ") || buffer.equals("getRunStatus ")
                    || buffer.equals("getOptRunStatus ")) {
                this.updateRunningRuns();
                candidates.addAll(runningRuns);
                return buffer.length();
            } else if (buffer.startsWith("performRun ")) {
                updateRuns();
                int posSpace = buffer.indexOf(' ');
                for (String match : runs.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("resumeRun ")) {
                this.updateRunResumes();
                int posSpace = buffer.indexOf(' ');
                for (String match : runResumes.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("getRunResults ")) {
                this.updateRunResults();
                int posSpace = buffer.indexOf(' ');
                for (String match : runResults.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("getRunResumes ")) {
                this.updateRunResumes();
                int posSpace = buffer.indexOf(' ');
                for (String match : runResumes.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("generateDataSet ")) {
                this.updateDataSetGenerators();
                int posSpace = buffer.indexOf(' ');
                for (String match : dataSetGenerators.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("randomizeDataConfig ")) {
                this.updateDataRandomizers();
                int posSpace = buffer.indexOf(' ');
                for (String match : dataRandomizers.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else if (buffer.startsWith("generateDataSet ")) {
                this.updateDataSetGenerators();
                candidates.addAll(dataSetGenerators);
                return buffer.length();
            } else if (buffer.startsWith("terminateRun ") || buffer.startsWith("getRunStatus ")) {
                this.updateRunningRuns();
                int posSpace = buffer.indexOf(' ');
                for (String match : runningRuns.tailSet(buffer.substring(posSpace + 1))) {
                    if (!match.startsWith(buffer.substring(posSpace + 1))) {
                        break;
                    }

                    candidates.add(match);
                }

                return posSpace + 1;
            } else {
                for (String match : strings.tailSet(buffer)) {
                    if (!match.startsWith(buffer)) {
                        break;
                    }

                    candidates.add(match);
                }
            }
        } catch (RemoteException e) {
            exception = true;
            try {
                // client = new EvalClient(new String[]{"-clientId",
                // clientId});
                client = new BackendClient(newArgs);
            } catch (ConnectException e1) {
                // e1.printStackTrace();
            } catch (ParseException e1) {
                // e1.printStackTrace();
            }
            // return -1;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }

        if (candidates.size() == 1) {
            candidates.set(0, candidates.get(0) + " ");
        }
    }

    return candidates.isEmpty() ? -1 : 0;
}

From source file:de.clusteval.serverclient.BackendClient.java

@Override
public void run() {
    boolean checkForRunStatus = false;
    boolean checkForOptRunStatus = false;
    try {//w ww .  j a  va2  s . com
        if (params.hasOption("performRun")) {
            this.performRun(params.getOptionValue("performRun"));
        }
        if (params.hasOption("resumeRun")) {
            this.resumeRun(params.getOptionValue("resumeRun"));
        }
        if (params.hasOption("terminateRun")) {
            this.terminateRun(params.getOptionValue("terminateRun"));
        }
        if (params.hasOption("getRuns")) {
            System.out.println("Runs: " + this.getRuns());
        }
        if (params.hasOption("getRunResumes")) {
            System.out.println("RunResumes: " + this.getRunResumes());
        }
        if (params.hasOption("getQueue")) {
            System.out.println("Queue: " + this.getQueue());
        }
        if (params.hasOption("getActiveThreads")) {
            Map<String, Triple<String, Integer, Long>> activeThreads = this.server.getActiveThreads();
            if (activeThreads.isEmpty())
                System.out.println("No active threads");
            else {
                System.out.println("Active threads:");
                System.out.format("%10s%20s%50s%30s%40s%10s%20s\n", "Thread #", "Thread", "Run",
                        "ProgramConfig", "DataConfig", "Iteration", "Running time");
                List<String> threadNames = new ArrayList<String>(activeThreads.keySet());
                Collections.sort(threadNames);
                int i = 1;
                for (String t : threadNames) {
                    Triple<String, Integer, Long> value = activeThreads.get(t);
                    String[] split1 = value.getFirst().split(": ");
                    String[] split2 = split1[1].split(",");

                    switch (value.getSecond()) {
                    case -1:
                        System.out.format("%10d%20s%50s%30s%40s%10s%20s\n", i++, t, split1[0], split2[0],
                                split2[1], "isoMDS", Formatter.formatMsToDuration(
                                        System.currentTimeMillis() - value.getThird(), false));
                        break;
                    case -2:
                        System.out.format("%10d%20s%50s%30s%40s%10s%20s\n", i++, t, split1[0], split2[0],
                                split2[1], "PCA", Formatter.formatMsToDuration(
                                        System.currentTimeMillis() - value.getThird(), false));
                        break;
                    default:
                        System.out.format("%10d%20s%50s%30s%40s%10d%20s\n", i++, t, split1[0], split2[0],
                                split2[1], value.getSecond(), Formatter.formatMsToDuration(
                                        System.currentTimeMillis() - value.getThird(), false));
                    }
                }
            }
        }
        if (params.hasOption("getRunResults")) {
            Map<Pair<String, String>, Map<String, Double>> result = this
                    .getRunResults(params.getOptionValue("getRunResults"));
            boolean first = true;
            for (Pair<String, String> p : result.keySet()) {
                if (first) {
                    for (String m : result.get(p).keySet()) {
                        System.out.format("%-30s", "");
                        System.out.print("\t" + m);
                    }
                    System.out.println();
                }
                System.out.format("%-30s", "(" + p.getFirst() + "," + p.getSecond() + ")");
                for (String m : result.get(p).keySet()) {
                    System.out.println("\t" + result.get(p).get(m));
                }
                first = false;
            }
        }
        if (params.hasOption("getDataSets")) {
            System.out.println("DataSets: " + this.getDataSets());
        }
        if (params.hasOption("getPrograms")) {
            System.out.println("Programs: " + this.getPrograms());
        }
        if (params.hasOption("getRunStatus")) {
            checkForRunStatus = true;
        }
        if (params.hasOption("getOptRunStatus")) {
            checkForOptRunStatus = true;
        }
        if (params.hasOption("shutdown")) {
            this.shutdownFramework();
        }
        if (params.hasOption("generateDataSet")) {
            String generatorName = params.getOptionValue("generateDataSet");

            CommandLineParser parser = new PosixParser();
            Options options = getOptionsForDataSetGenerator(generatorName);

            try {
                parser.parse(options, this.args);
                this.server.generateDataSet(generatorName, this.args);
            } catch (ParseException e1) {
                try {
                    reader.println();
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.setOptionComparator(new MyOptionComparator());
                    formatter.printHelp("generateDataSet " + generatorName, options, true);
                    reader.println();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        if (params.hasOption("randomizeDataConfig")) {
            String randomizerName = params.getOptionValue("randomizeDataConfig");

            CommandLineParser parser = new PosixParser();
            Options options = getOptionsForDataRandomizer(randomizerName);

            try {
                parser.parse(options, this.args);
                this.server.randomizeDataConfig(randomizerName, this.args);
            } catch (ParseException e1) {
                try {
                    reader.println();
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.setOptionComparator(new MyOptionComparator());
                    formatter.printHelp("randomizeDataConfig " + randomizerName, options, true);
                    reader.println();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        if (checkForRunStatus) {
            try {
                String runName = params.getOptionValue("getRunStatus");

                Map<String, Pair<RUN_STATUS, Float>> status = null;
                if ((status = this.getMyRunStatus()) != null && status.size() > 0) {
                    RUN_STATUS newStatus;
                    Float percent;
                    if (!status.containsKey(runName)) {
                        log.info("No run with name " + runName + " running.");
                        return;
                    }
                    newStatus = status.get(runName).getFirst();
                    percent = status.get(runName).getSecond();
                    System.out.println();
                    System.out.print("\r" + newStatus + " " + percent + "%");
                }
                System.out.println();
            } catch (ConnectException e2) {
                this.log.warn("The server terminated the connection...");
            } catch (RemoteException e2) {
                e2.printStackTrace();
            }
        }

        if (checkForOptRunStatus) {
            try {

                String runName = params.getOptionValue("getOptRunStatus");

                // runId ->
                // ((Status,%),(ProgramConfig,DataConfig)->(QualityMeasure->(ParameterSet->Quality)))
                Map<String, Pair<Pair<RUN_STATUS, Float>, Map<Pair<String, String>, Map<String, Pair<Map<String, String>, String>>>>> optStatus = null;
                if ((optStatus = this.getMyOptimizationRunStatus()) != null && optStatus.size() > 0) {
                    RUN_STATUS newStatus;
                    Float percent;

                    if (!optStatus.containsKey(runName)) {
                        log.info("No run with name " + runName + " running.");
                        return;
                    }
                    newStatus = optStatus.get(runName).getFirst().getFirst();
                    percent = optStatus.get(runName).getFirst().getSecond();
                    System.out.println();
                    System.out.println("\r Status:\t" + newStatus + " " + percent + "%");
                    Map<Pair<String, String>, Map<String, Pair<Map<String, String>, String>>> qualities = optStatus
                            .get(runName).getSecond();

                    // print the quality measures; just take them from the
                    // first pair of programConfig and dataConfig (runnable)
                    String[] qualityMeasures = qualities.values().iterator().next().keySet()
                            .toArray(new String[0]);
                    Arrays.sort(qualityMeasures);
                    int pos = 0;
                    while (true) {
                        boolean foundMeasure = false;
                        for (String measure : qualityMeasures) {
                            if (pos < measure.length()) {
                                System.out.printf("\t%s", measure.charAt(pos));
                                foundMeasure = true;
                            } else
                                System.out.print("\t");
                        }
                        System.out.println();
                        if (!foundMeasure)
                            break;
                        pos++;
                    }

                    // 06.06.2014: added sets to keep order when printing
                    // the results
                    Set<String> programConfigs = new HashSet<String>();
                    Set<String> dataConfigs = new HashSet<String>();

                    for (Pair<String, String> pcDcPair : qualities.keySet()) {
                        programConfigs.add(pcDcPair.getFirst());
                        dataConfigs.add(pcDcPair.getSecond());
                    }

                    for (String programConfig : programConfigs) {
                        System.out.printf("%s:\n", programConfig);
                        for (String dataConfig : dataConfigs) {
                            System.out.printf("-- %s:\n", dataConfig);
                            Pair<String, String> pcDcPair = Pair.getPair(programConfig, dataConfig);
                            Map<String, Pair<Map<String, String>, String>> qualitiesPcDc = qualities
                                    .get(pcDcPair);
                            for (String measure : qualityMeasures) {
                                if (!qualitiesPcDc.containsKey(measure)) {
                                    System.out.print("\t");
                                    continue;
                                }
                                String quality = qualitiesPcDc.get(measure).getSecond();
                                if (quality.equals("NT"))
                                    System.out.print("\tNT");
                                else {
                                    double qualityDouble = Double.valueOf(quality);
                                    if (Double.isInfinite(qualityDouble))
                                        System.out.printf("\t%s%s", qualityDouble < 0 ? "-" : "", "Inf");
                                    else
                                        System.out.printf("\t%.4f", qualityDouble);
                                }
                            }
                            System.out.println();
                        }
                    }
                }
                System.out.println();
            } catch (ConnectException e2) {
                this.log.warn("The server terminated the connection...");
            } catch (RemoteException e2) {
                e2.printStackTrace();
            }
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:net.sqs2.omr.session.service.AbstractRemoteExecutorManager.java

private AbstractTaskTracker<T, D> createRemoteTaskTracker(String uriString, long remoteKey, long sessionID) {
    try {//from w  ww  .j av  a  2  s .  c o  m
        URI uri = new URI(uriString);
        Registry registry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort());
        Logger.getLogger(getClass().getName())
                .info("REGISTRY:\n" + StringUtil.join(registry.list(), "\n") + "\nLOOKUP:\n" + uri.getPath());
        RemoteSessionSourceServer remoteSessionService = (RemoteSessionSourceServer) registry
                .lookup(uri.getPath());
        long result = remoteSessionService.ping(remoteKey); // authentication
        if (AbstractTaskTracker.DEBUG_CLUSTER_MODE) {
            Logger.getLogger("executor").info("RemoteSessionService.URI=" + uri);
            Logger.getLogger("executor").info("Hello=" + result);
        }
        AbstractTaskTracker<T, D> remoteTaskTracker = createTaskTracker(this.taskTracker, remoteSessionService,
                remoteKey);

        this.remoteTaskTrackerMap.put(uriString, remoteTaskTracker);
        return remoteTaskTracker;
    } catch (ConnectException ex) {
        Logger.getLogger("executor").severe("ConnectException:" + uriString);
    } catch (RemoteException ex) {
        Logger.getLogger("executor").severe("RemoteException:" + uriString);
    } catch (NullPointerException ex) {
        Logger.getLogger("executor").severe("NullPointerException:" + uriString);
    } catch (NotBoundException ex) {
        ex.printStackTrace();
        Logger.getLogger("executor").severe("NotBoundException:" + uriString);
    } catch (URISyntaxException ex) {
        Logger.getLogger("executor").severe("URISyntaxException:" + ex.getMessage());
    }
    return null;
}