protected String getStatsTrace() {
   String n = peer.getManager().getDisplayName();
   String t = session_type == TYPE_DOWNLOAD ? "DOWNLOADING" : "SEEDING";
   String p = " : [" + peer.getClient() + "] " + peer.getIp() + " :" + peer.getPort();
   String s =
       " || (D: "
           + DisplayFormatters.formatByteCountToKiBEtcPerSec(peer.getStats().getDataReceiveRate())
           + ") (U: "
           + DisplayFormatters.formatByteCountToKiBEtcPerSec(peer.getStats().getDataSendRate())
           + ")";
   return "[" + n + "] " + t + p + s;
 }
예제 #2
0
 public void refresh(TableCell cell) {
   ClientStatsDataSource ds = (ClientStatsDataSource) cell.getDataSource();
   if (ds == null) {
     return;
   }
   float val = ds.count * 1000f / ds.overall.count;
   if (cell.setSortValue(val) || !cell.isValid()) {
     cell.setText(DisplayFormatters.formatPercentFromThousands((int) val));
   }
 }
예제 #3
0
  public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    long value = (dm == null) ? 0 : dm.getEffectiveUploadRateLimitBytesPerSecond();
    if (!cell.setSortValue(value) && cell.isValid()) return;

    if (value == -1) {
      cell.setText(MessageText.getString("MyTorrents.items.UpSpeedLimit.disabled"));
    } else if (value == 0) {
      cell.setText(Constants.INFINITY_STRING);
    } else {
      cell.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(value));
    }
  }
  public void refresh(TableCell cell) {
    int average = -1;

    DownloadManager dm = (DownloadManager) cell.getDataSource();

    if (dm != null) {
      PEPeerManager pm = dm.getPeerManager();

      if (pm != null) {
        average = pm.getAverageCompletionInThousandNotation();
      }
    }

    if (!cell.setSortValue(average) && cell.isValid()) {
      return;
    }

    if (average < 0) {
      cell.setText("");
    } else {
      cell.setText(DisplayFormatters.formatPercentFromThousands(average));
    }
  }
예제 #5
0
  protected void report(String resource_key, long bytes) {
    if (progress_listeners.size() > 0) {

      report(resource_key, DisplayFormatters.formatByteCountToKiBEtc(bytes));
    }
  }
  private void buildOptions(
      final Composite parent, final PlatformManager platform, final Composite area, boolean rebuild)
      throws PlatformManagerException {
    if (rebuild) {

      Control[] kids = area.getChildren();

      for (Control k : kids) {
        k.dispose();
      }
    }

    String[] options = platform.getExplicitVMOptions();

    {
      // max mem

      long max_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xmx");

      final int MIN_MAX_JVM = 32 * 1024 * 1024;

      GridData gridData = new GridData();
      Label label = new Label(area, SWT.NULL);
      label.setLayoutData(gridData);
      Messages.setLanguageText(label, "jvm.max.mem", new String[] {encodeDisplayLong(MIN_MAX_JVM)});

      gridData = new GridData();
      gridData.widthHint = 125;
      final StringParameter max_vm = new StringParameter(area, "jvm.max.mem", "", false);
      max_vm.setLayoutData(gridData);

      max_vm.setValue(max_mem == -1 ? "" : encodeDisplayLong(max_mem));

      max_vm.addChangeListener(
          new ParameterChangeAdapter() {
            private String last_value;

            public void parameterChanged(Parameter p, boolean caused_internally) {
              if (max_vm.isDisposed()) {

                max_vm.removeChangeListener(this);

                return;
              }

              String val = max_vm.getValue();

              if (last_value != null && last_value.equals(val)) {

                return;
              }

              last_value = val;

              try {
                long max_mem = decodeDisplayLong(val);

                if (max_mem < MIN_MAX_JVM) {

                  throw (new Exception("Min=" + encodeDisplayLong(MIN_MAX_JVM)));
                }

                String[] options = platform.getExplicitVMOptions();

                options = AEMemoryMonitor.setJVMLongOption(options, "-Xmx", max_mem);

                long min_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xms");

                if (min_mem == -1 || min_mem > max_mem) {

                  options = AEMemoryMonitor.setJVMLongOption(options, "-Xms", max_mem);
                }

                platform.setExplicitVMOptions(options);

                buildOptions(parent, platform, area, true);

              } catch (Throwable e) {

                String param_name = MessageText.getString("jvm.max.mem");

                int pos = param_name.indexOf('[');

                if (pos != -1) {

                  param_name = param_name.substring(0, pos).trim();
                }

                MessageBoxShell mb =
                    new MessageBoxShell(
                        SWT.ICON_ERROR | SWT.OK,
                        MessageText.getString("ConfigView.section.invalid.value.title"),
                        MessageText.getString(
                            "ConfigView.section.invalid.value",
                            new String[] {val, param_name, Debug.getNestedExceptionMessage(e)}));

                mb.setParent(parent.getShell());
                mb.open(null);
              }
            }
          });

      label = new Label(area, SWT.NULL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      label.setLayoutData(gridData);

      Long max_heap_mb = AEMemoryMonitor.getMaxHeapMB();

      if (max_heap_mb > 0) {

        Messages.setLanguageText(
            label,
            "jvm.max.mem.current",
            new String[] {
              DisplayFormatters.formatByteCountToKiBEtc(max_heap_mb * 1024 * 1024, true)
            });
      }
    }

    {
      // min mem

      final int MIN_MIN_JVM = 8 * 1024 * 1024;

      long min_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xms");

      GridData gridData = new GridData();
      Label label = new Label(area, SWT.NULL);
      label.setLayoutData(gridData);
      Messages.setLanguageText(label, "jvm.min.mem", new String[] {encodeDisplayLong(MIN_MIN_JVM)});

      gridData = new GridData();
      gridData.widthHint = 125;
      final StringParameter min_vm = new StringParameter(area, "jvm.min.mem", "", false);
      min_vm.setLayoutData(gridData);

      min_vm.setValue(min_mem == -1 ? "" : encodeDisplayLong(min_mem));

      min_vm.addChangeListener(
          new ParameterChangeAdapter() {
            private String last_value;

            public void parameterChanged(Parameter p, boolean caused_internally) {
              if (min_vm.isDisposed()) {

                min_vm.removeChangeListener(this);

                return;
              }

              String val = min_vm.getValue();

              if (last_value != null && last_value.equals(val)) {

                return;
              }

              last_value = val;

              try {
                long min_mem = decodeDisplayLong(val);

                if (min_mem < MIN_MIN_JVM) {

                  throw (new Exception("Min=" + encodeDisplayLong(MIN_MIN_JVM)));
                }

                String[] options = platform.getExplicitVMOptions();

                options = AEMemoryMonitor.setJVMLongOption(options, "-Xms", min_mem);

                long max_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xmx");

                if (max_mem == -1 || max_mem < min_mem) {

                  options = AEMemoryMonitor.setJVMLongOption(options, "-Xmx", min_mem);
                }

                platform.setExplicitVMOptions(options);

                buildOptions(parent, platform, area, true);

              } catch (Throwable e) {

                String param_name = MessageText.getString("jvm.min.mem");

                int pos = param_name.indexOf('[');

                if (pos != -1) {

                  param_name = param_name.substring(0, pos).trim();
                }

                MessageBoxShell mb =
                    new MessageBoxShell(
                        SWT.ICON_ERROR | SWT.OK,
                        MessageText.getString("ConfigView.section.invalid.value.title"),
                        MessageText.getString(
                            "ConfigView.section.invalid.value",
                            new String[] {val, param_name, Debug.getNestedExceptionMessage(e)}));

                mb.setParent(parent.getShell());
                mb.open(null);
              }
            }
          });

      label = new Label(area, SWT.NULL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      label.setLayoutData(gridData);
    }

    {
      // max DIRECT mem

      final int MIN_DIRECT_JVM = 32 * 1024 * 1024;

      final String OPTION_KEY = "-XX:MaxDirectMemorySize=";

      long max_direct = AEMemoryMonitor.getJVMLongOption(options, OPTION_KEY);

      GridData gridData = new GridData();
      Label label = new Label(area, SWT.NULL);
      label.setLayoutData(gridData);
      Messages.setLanguageText(
          label, "jvm.max.direct.mem", new String[] {encodeDisplayLong(MIN_DIRECT_JVM)});

      gridData = new GridData();
      gridData.widthHint = 125;
      final StringParameter max_direct_vm =
          new StringParameter(area, "jvm.max.direct.mem", "", false);
      max_direct_vm.setLayoutData(gridData);

      max_direct_vm.setValue(max_direct == -1 ? "" : encodeDisplayLong(max_direct));

      max_direct_vm.addChangeListener(
          new ParameterChangeAdapter() {
            private String last_value;

            public void parameterChanged(Parameter p, boolean caused_internally) {
              if (max_direct_vm.isDisposed()) {

                max_direct_vm.removeChangeListener(this);

                return;
              }

              String val = max_direct_vm.getValue();

              if (last_value != null && last_value.equals(val)) {

                return;
              }

              last_value = val;

              try {
                long max_direct = decodeDisplayLong(val);

                if (max_direct < MIN_DIRECT_JVM) {

                  throw (new Exception("Min=" + encodeDisplayLong(MIN_DIRECT_JVM)));
                }

                String[] options = platform.getExplicitVMOptions();

                options = AEMemoryMonitor.setJVMLongOption(options, OPTION_KEY, max_direct);

                platform.setExplicitVMOptions(options);

                buildOptions(parent, platform, area, true);

              } catch (Throwable e) {

                String param_name = MessageText.getString("jvm.max.direct.mem");

                int pos = param_name.indexOf('[');

                if (pos != -1) {

                  param_name = param_name.substring(0, pos).trim();
                }

                MessageBoxShell mb =
                    new MessageBoxShell(
                        SWT.ICON_ERROR | SWT.OK,
                        MessageText.getString("ConfigView.section.invalid.value.title"),
                        MessageText.getString(
                            "ConfigView.section.invalid.value",
                            new String[] {val, param_name, Debug.getNestedExceptionMessage(e)}));

                mb.setParent(parent.getShell());
                mb.open(null);
              }
            }
          });

      label = new Label(area, SWT.NULL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      label.setLayoutData(gridData);
      Messages.setLanguageText(label, "jvm.max.direct.mem.info");
    }

    // all options

    Label label = new Label(area, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    label.setLayoutData(gridData);
    Messages.setLanguageText(label, "jvm.options.summary");

    for (String option : options) {

      label = new Label(area, SWT.NULL);
      label.setText(option);
      gridData = new GridData();
      gridData.horizontalSpan = 3;
      gridData.horizontalIndent = 20;
      label.setLayoutData(gridData);
    }

    if (rebuild) {

      parent.layout(true, true);
    }
  }