Exemplo n.º 1
0
  public void listAll() {

    // Get directory listing
    String hostname = hostField.getText();
    int port = Integer.parseInt(portField.getText());
    String station = stationField.getText();
    String id = station + ".*-*";
    String chanList[] = null;

    // Get data
    msgBox.append("Connecting to host " + hostname + ":" + port + "\n");
    DirSocket getDirThread = new DirSocket(hostname, port, id, "*", "*");
    getDirThread.start();

    while (!getDirThread.Done() && getDirThread.isAlive()) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        msgBox.append("Error listAll(): Sleep failed waiting for DirSocket to end\n");
      }
    } // loop until data collection thread says it is done

    while (channelListModel.getSize() > 0) channelListModel.remove(0);

    if (getDirThread.GetErrMsg() != null) {
      msgBox.append(getDirThread.GetErrMsg() + "\n");
      return;
    }

    chanList = getDirThread.GetChannelList();
    if (chanList == null) {
      msgBox.append("No channels returned\n");
      return;
    }

    for (int i = 0; i < chanList.length; i++) {
      for (iSort = 0; iSort < channelListModel.getSize(); iSort++) {
        if (chanList[i].compareTo((String) channelListModel.getElementAt(iSort)) < 0) {
          break;
        }
      } // loop to sort channel into list
      channelListModel.add(iSort, chanList[i]);
    } // loop to add each new channel to list

    msgBox.append("Complete list of " + chanList.length + " channels finished.\n");
  } // listAll()
Exemplo n.º 2
0
  public void Transfer() {
    //
    // First get a filtered directory listing for error checking
    //
    String hostname = hostField.getText();
    int port = Integer.parseInt(portField.getText());
    String station = stationField.getText();
    String channel = "*";
    String location = "*";
    String id;
    String startDate = startDateField.getText();
    String startTime = startTimeField.getText();
    String finishDate = finishDateField.getText();
    String finishTime = finishTimeField.getText();
    String chanList[] = null;
    String savedir = localSeedFileFrame.getCurrentDirectory().getAbsolutePath();
    String filename;
    int iCount;
    int expected;
    int duration;
    String selected;
    OutputStream outfile = null;
    final char hourChar[] = {
      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
      'T', 'U', 'V', 'W', 'X'
    };

    // Make user user has selected some channels
    Object[] list = channelListBox.getSelectedValues();
    if (list == null || list.length == 0) {
      msgBox.append("User must select channels to transfer.\n");
      return;
    }

    if (location.compareTo("  ") == 0) {
      id = station + '.' + channel;
    } // blank location
    else {
      id = station + '.' + location + '-' + channel;
    } // not blank location

    // Get data
    msgBox.append("Connecting to host " + hostname + ":" + port + "\n");
    DirSocket getDirThread =
        new DirSocket(
            hostname, port, id, startDate + ' ' + startTime, finishDate + ' ' + finishTime);
    getDirThread.start();

    while (!getDirThread.Done() && getDirThread.isAlive()) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        msgBox.append("Error Transfer: Sleep failed waiting for DirThread to end\n");
        return;
      }
    } // loop until data collection thread says it is done

    if (getDirThread.GetErrMsg() != null) {
      msgBox.append(getDirThread.GetErrMsg() + "\n");
      return;
    }

    chanList = getDirThread.GetChannelList();

    // Now loop through selection list
    // This first pass is for error checking only
    boolean okay = (list != null && chanList != null);
    if (!okay) {
      msgBox.append("User must select channels to transfer.\n");
      return;
    }
    iCount = 0;
    selected = "";
    for (int i = 0; okay && i < list.length; i++) {
      // Find matching entry in filtered list
      int j;
      for (j = 0; okay && j < chanList.length; j++) {
        selected = (String) list[i];
        if (selected.substring(0, 6).compareTo(chanList[j].substring(0, 6)) == 0) {
          // We found the entry in the filtered list
          iCount++;
          // Make sure that the number of records is acceptable
          int iMaxRecords = Integer.valueOf(maxRecordField.getText()).intValue();
          int iRecords =
              Integer.valueOf(chanList[j].substring(chanList[j].lastIndexOf(' ') + 1)).intValue();
          if (iRecords > iMaxRecords) {
            okay = false;
            msgBox.append(
                "Channel "
                    + selected.substring(0, 6)
                    + " has too many records, "
                    + iRecords
                    + " > "
                    + iMaxRecords
                    + '\n');
          }
          break;
        } // location/channel matches
      } // for each filtered item
      if (j == chanList.length && okay) {
        msgBox.append(
            "Channel "
                + selected.substring(0, 6)
                + " has no data for the given time span, skipping!\n");
      } // selected item not found
    } // for each selected item

    if (okay) {
      msgBox.append("Transfering " + iCount + " channels of 512 byte seed records.\n");

      for (int i = 0; okay && i < list.length; i++) {
        selected = (String) list[i];
        // Find matching entry in filtered list
        int j;
        for (j = 0; okay && j < chanList.length; j++) {
          if (selected.substring(0, 6).compareTo(chanList[j].substring(0, 6)) == 0) {
            if (bCancel) {
              msgBox.append("Transfer canceled\n");
              return;
            }

            location = selected.substring(0, 2);
            channel = selected.substring(3, 6);
            if (location.compareTo("  ") == 0) {
              id = station + '.' + channel;
            } // blank location
            else {
              id = station + '.' + location + '-' + channel;
            } // not blank location

            // Do some syntax checks on return string
            if (chanList[j].length() < 48) continue;
            if (chanList[j].charAt(2) != '/') continue;
            if (chanList[j].charAt(11) != '/') continue;
            if (chanList[j].charAt(14) != '/') continue;
            if (chanList[j].charAt(20) != ':') continue;
            if (chanList[j].charAt(23) != ':') continue;
            if (chanList[j].charAt(31) != '/') continue;
            if (chanList[j].charAt(34) != '/') continue;
            if (chanList[j].charAt(40) != ':') return;
            if (chanList[j].charAt(43) != ':') return;

            if (!Character.isDigit(chanList[j].charAt(47))) {
              return;
            }
            expected = Integer.valueOf(chanList[j].substring(47)).intValue();

            if (extendFilenameCheckBox.getSelectedObjects() == null) {
              // user wants new filename format
              if (location.charAt(0) != ' ')
                filename =
                    savedir
                        + File.separatorChar
                        + location
                        + channel
                        + startDate.substring(2, 4)
                        + startDate.substring(5, 7)
                        + startDate.substring(8, 10)
                        + startTime.substring(0, 2)
                        + startTime.substring(3, 5)
                        + '.'
                        + "seed";
              else
                filename =
                    savedir
                        + File.separatorChar
                        + channel
                        + startDate.substring(2, 4)
                        + startDate.substring(5, 7)
                        + startDate.substring(8, 10)
                        + startTime.substring(0, 2)
                        + startTime.substring(3, 5)
                        + '.'
                        + "seed";
            } // if extended filename
            else {
              // user wants old filename format
              int hour = Integer.valueOf(startTime.substring(0, 2)).intValue();
              filename =
                  savedir
                      + File.separatorChar
                      + 'C'
                      + channel.charAt(0)
                      + startDate.substring(2, 4)
                      + startDate.substring(5, 7)
                      + startDate.substring(8, 10)
                      + '.'
                      + hourChar[hour]
                      + startTime.substring(3, 5);
            } // old filename format

            try {
              outfile = new FileOutputStream(filename, true);
            } catch (FileNotFoundException e) {
              msgBox.append("Failed to open file " + savedir + ", aborting transfers!\n");
              return;
            }

            StdTime tFinish = new StdTime(finishDate, finishTime);
            StdTime tStart = new StdTime(startDate, startTime);
            DeltaTime tDelta = new DeltaTime(tFinish, tStart);
            if (tDelta.ExceedsMaxSeconds()) {
              // This case should be extremely difficult to reach
              msgBox.append(
                  "Duration exceeds limit of "
                      + DeltaTime.MaxDeltaInt
                      + " seconds for "
                      + location
                      + '/'
                      + channel
                      + "\n");
              duration = DeltaTime.MaxDeltaInt;
            } else duration = tDelta.toSeconds();
            if (duration < 1) duration = 1;

            // We found the entry in the filtered list
            msgBox.append(
                "Transfering data from channel "
                    + selected.substring(0, 6)
                    + " to file "
                    + filename
                    + "\n");
            EventQueue.invokeLater(
                new Runnable() {
                  public void run() {
                    msgBox.append("\r");
                    localSeedFileFrame.rescanCurrentDirectory();
                  }
                });

            // Get data for this channel and time period
            SeedSocket getSeedThread =
                new SeedSocket(hostname, port, id, startDate, startTime, duration, outfile);
            getSeedThread.start();

            while (!getSeedThread.Done() && getSeedThread.isAlive()) {
              try {
                Thread.sleep(1000);
                if (bCancel) getSeedThread.SetCancel(true);
              } catch (InterruptedException e) {
                msgBox.append("Error Transfer(): Sleep failed waiting for SeedThread\n");
                return;
              }
            } // loop until data collection thread says it is done

            if (expected != getSeedThread.GetRecordCount()) {
              msgBox.append(
                  "Collected "
                      + getSeedThread.GetRecordCount()
                      + " of "
                      + expected
                      + " expected records\n");
            }

            try {
              outfile.close();
            } catch (IOException e) {
              msgBox.append("Error closing seed data file.\n");
            }
            if (getSeedThread.GetRecordCount() < 1) {
              // No data so delete output file
              msgBox.append("Warning, empty seed output file " + filename + "\n");
            }
          } // location/channel matches
        } // for each filtered item
      } // for each selected item

      if (bCancel) {
        EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                msgBox.append("Transfer canceled\n");
              }
            });
        return;
      }
      EventQueue.invokeLater(
          new Runnable() {
            public void run() {
              msgBox.append("Transfer complete\n");
            }
          });
    } // if request did not have any errors
  } // Transfer()
Exemplo n.º 3
0
  public void listFiltered() {

    // Get directory listing
    String hostname = hostField.getText();
    int port = Integer.parseInt(portField.getText());
    String station = stationField.getText();
    String channel = channelField.getText();
    String location = locationField.getText();
    String id;
    String startDate = startDateField.getText();
    String startTime = startTimeField.getText();
    String finishDate = finishDateField.getText();
    String finishTime = finishTimeField.getText();
    String chanList[] = null;

    if (location.compareTo("  ") == 0) {
      id = station + '.' + channel;
    } // blank location
    else {
      id = station + '.' + location + '-' + channel;
    } // not blank location

    // Get data
    msgBox.append("Connecting to host " + hostname + ":" + port + "\n");

    DirSocket getDirThread =
        new DirSocket(
            hostname, port, id, startDate + ' ' + startTime, finishDate + ' ' + finishTime);
    getDirThread.start();

    while (!getDirThread.Done() && getDirThread.isAlive()) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        msgBox.append("Error listFiltered(): Sleep failed waiting for DirSocket to end\n");
        return;
      } catch (IllegalMonitorStateException e) {
        msgBox.append("Error listFiltered(): wait failed IllegalMonitorStateException\n");
        return;
      }
    } // loop until data collection thread says it is done

    while (channelListModel.getSize() > 0) channelListModel.remove(0);

    if (getDirThread.GetErrMsg() != null) {
      msgBox.append(getDirThread.GetErrMsg() + "\n");
      return;
    }

    chanList = getDirThread.GetChannelList();
    if (chanList == null) {
      msgBox.append("No channels match filter\n");
      return;
    }
    for (int i = 0; i < chanList.length; i++) {
      for (iSort = 0; iSort < channelListModel.getSize(); iSort++) {
        if (chanList[i].compareTo((String) channelListModel.getElementAt(iSort)) < 0) {
          break;
        }
      } // loop to sort channel into list
      channelListModel.add(iSort, chanList[i]);
    } // loop to add each new channel to list
    msgBox.append("Filtered list of " + chanList.length + " channels finished.\n");
  } // listFiltered()