示例#1
0
  /**
   * Main
   *
   * @param args
   */
  public static void main(String[] args) {

    boolean sameoutput = false;

    int copies = DFLT_COPIES;
    int maxDepots = DFLT_MAX_DEPOTS;
    int duration = DFLT_DURATION;
    int transferSize = DFLT_TRANSFERSIZE;
    int connections = DFLT_CONNECTIONS;
    String location = DFLT_LOCATION;

    String outputfilename = "";
    String inputfilename = "";

    String str = "";

    if (args.length == 0) {
      usage();
      System.exit(0);
    }

    for (int i = 0; i < args.length; i++) {
      String arg = args[i];
      if ((char) arg.charAt(0) == '-') {
        switch ((char) arg.charAt(1)) {
          case 'f':
            sameoutput = true;
            break;
          case 'H':
            i++;
            break;
          case 'c':
            copies = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'o':
            outputfilename = args[i + 1];
            i++;
            break;
          case 'm':
            maxDepots = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'n':
            break;
          case 'l':
            location = args[i + 1] + " " + args[i + 2];
            i += 2;
            break;
          case 'h':
            break;
          case 's':
            break;
          case 't':
            connections = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'T':
            i++;
            break;
          case 'd':
            try {
              str = args[i + 1].toLowerCase();
              int p = str.length();
              if (str.endsWith("m")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 60;
              } else if (str.endsWith("h")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 3660;
              } else if (str.endsWith("d")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 86400;
              } else {
                duration = Integer.parseInt(str);
              }
            } catch (Exception e) {
              System.out.println("Bad number: " + str);
            }
            i++;
            break;
          case 'b':
            try {
              str = args[i + 1].toLowerCase();
              int p = str.length();
              if (str.endsWith("k")) {
                transferSize = Integer.parseInt(str.substring(0, p - 1)) * 1024;
              } else if (str.endsWith("m")) {
                transferSize = Integer.parseInt(str.substring(0, p - 1)) * 1024 * 1024;
              } else {
                transferSize = Integer.parseInt(str);
              }
              i++;
            } catch (Exception e) {
              System.out.println("Bad number: " + str);
            }
        }
      } else {
        inputfilename = args[i];
      }
    }

    File inputfile = new File(inputfilename);
    if (!inputfile.exists() || !inputfile.isFile()) {
      System.out.println("Can not read " + inputfilename);
      System.exit(1);
    }

    if (sameoutput || outputfilename.equals("")) {
      outputfilename = inputfilename + ".xnd";
    }

    if (VERBOSE > 0) {
      String info =
          ""
              + "File to upload:\t\t"
              + inputfilename
              + "\n"
              + "Output file:\t\t"
              + outputfilename
              + "\n"
              + "Number of copies:\t"
              + copies
              + "\n"
              + "Max depots requested:\t"
              + maxDepots
              + "\n"
              + "Duration:\t\t"
              + duration
              + " sec.\n"
              + "Transfer size:\t\t"
              + transferSize
              + " bytes\n"
              + "Number of connections:\t"
              + connections
              + "\n"
              + "Location:\t\t"
              + location
              + "\n";

      System.out.println(info);
    }

    LogisticalUpload lu = new LogisticalUpload();
    lu.fill_LBoneServerList("", 0);
    lu.upload(
        inputfile,
        outputfilename,
        copies,
        maxDepots,
        duration,
        transferSize,
        connections,
        location);
  }
示例#2
0
  /**
   * Upload
   *
   * @param inputfile
   * @param outputfilename
   * @param copies
   * @param maxDepots
   * @param duration
   * @param transferSize
   * @param connections
   * @param location
   */
  public void upload(
      File inputfile,
      String outputfilename,
      int copies,
      int maxDepots,
      int duration,
      int transferSize,
      int connections,
      String location) {
    final String functionName = null;
    final int length = (int) (inputfile.length() * copies / maxDepots / 1024 / 1024 + 1);

    final int maxDepots_f = maxDepots;
    final int duration_f = duration;
    final String location_f = location;
    final File inputfile_f = inputfile;
    final String outputfilename_f = outputfilename;
    final int transferSize_f = transferSize;
    final int connections_f = connections;
    final int copies_f = copies;

    exnode = new Exnode();

    Thread t =
        new Thread(
            new Runnable() {
              public void run() {

                try {
                  boolean done = false;

                  // ======================================================

                  Depot[] depots = null;
                  for (int i = 0; i < servers.length && done == false; i++) {
                    try {
                      depots =
                          servers[i].getDepots(
                              maxDepots_f,
                              length, // hard
                              0, // soft
                              duration_f,
                              location_f,
                              120);
                      done = true;
                    } catch (Exception ignored) {
                      System.err.println("upload: " + ignored);
                    }
                  }
                  if (done == false) {
                    throw (new Exception("Unable to contact L-Bone"));
                  }

                  DepotList list = new DepotList();
                  list.add(depots);
                  list.randomizeNext(); // Avoid to start always on the same
                  // depot especially if user always
                  // use the same location.

                  if (VERBOSE > 0) {
                    System.out.println("Response from the L-Bone:");
                    System.out.println(list.toString());
                  }

                  // ======================================================

                  System.out.println("Uploading " + inputfile_f.getCanonicalPath() + "...");

                  exnode.write(
                      inputfile_f.getCanonicalPath(),
                      transferSize_f,
                      connections_f,
                      duration_f,
                      copies_f,
                      list,
                      functionName);

                  // ======================================================

                  System.out.print("Building " + outputfilename_f + "... ");

                  exnode.addMetadata(
                      new StringMetadata(
                          "filename",
                          outputfilename_f.substring(
                              outputfilename_f.lastIndexOf('/') + 1,
                              outputfilename_f.length() - 4)));

                  // SIZE_ESTIMATE
                  // -------------
                  // "original_filesize" should be named "size_estimate"
                  exnode.addMetadata(
                      new IntegerMetadata("original_filesize", inputfile_f.length()));

                  exnode.addMetadata(new IntegerMetadata("number_of_copies", copies_f));

                  exnode.addMetadata(new DoubleMetadata("lorsversion", 0.82));

                  Metadata type = new ListMetadata("Type");
                  type.add(new StringMetadata("Name", "logistical_file"));
                  type.add(new StringMetadata("Version", "1.0"));
                  exnode.addMetadata(type);

                  Metadata tool = new ListMetadata("Authoring Tool");
                  tool.add(new StringMetadata("Name", "LoDN"));
                  tool.add(new StringMetadata("Version", "0.7"));
                  exnode.addMetadata(tool);

                  System.out.println("done.");

                  // ======================================================

                  System.out.print("Writing " + outputfilename_f + "... ");

                  FileOutputStream fos = new FileOutputStream(outputfilename_f);
                  fos.write(exnode.toXML().getBytes());
                  fos.close();

                  System.out.println("done.");

                } catch (Exception e) {
                  e.printStackTrace();
                  exnode.setError(e);
                  exnode.setCancel(true);
                }
              }
            });
    t.start();

    while (exnode.getProgress() == null) {
      try {
        this.wait(1000);
        System.out.println("Progress object not yet initailized... Please wait...");
      } catch (Exception ignored) {
      }
    }
  }