Esempio n. 1
0
  public static Struct getMemoryUsageAsStruct(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    long used = 0, max = 0, init = 0;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if ((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP)
          || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
        used += usage.getUsed();
        max += usage.getMax();
        init += usage.getInit();
      }
    }
    Struct sct = new StructImpl();
    sct.setEL(KeyConstants._used, Caster.toDouble(used));
    sct.setEL(KeyConstants._max, Caster.toDouble(max));
    sct.setEL(KeyConstants._init, Caster.toDouble(init));
    sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
    return sct;
  }
Esempio n. 2
0
  public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {

    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    Query qry =
        new QueryImpl(
            new Collection.Key[] {
              KeyConstants._name,
              KeyConstants._type,
              KeyConstants._used,
              KeyConstants._max,
              KeyConstants._init
            },
            0,
            "memory");

    int row = 0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      row++;
      qry.addRow();
      qry.setAtEL(KeyConstants._name, row, bean.getName());
      qry.setAtEL(KeyConstants._type, row, _type.name());
      qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
      qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
      qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
    }
    return qry;
  }
Esempio n. 3
0
  public static lucee.runtime.type.Query toQuery(
      FTPFile[] files, String prefix, String directory, String hostName) throws PageException {

    String[] cols =
        new String[] {
          "name",
          "isdirectory",
          "lastmodified",
          "length",
          "mode",
          "path",
          "url",
          "type",
          "raw",
          "attributes"
        };
    String[] types =
        new String[] {
          "VARCHAR", "BOOLEAN", "DATE", "DOUBLE", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR",
          "VARCHAR", "VARCHAR"
        };

    lucee.runtime.type.Query query = new QueryImpl(cols, types, 0, "query");

    // translate directory path for display
    if (directory.length() == 0) directory = "/";
    else if (directory.startsWith("./")) directory = directory.substring(1);
    else if (directory.charAt(0) != '/') directory = '/' + directory;
    if (directory.charAt(directory.length() - 1) != '/') directory = directory + '/';

    int row;
    for (int i = 0; i < files.length; i++) {
      FTPFile file = files[i];
      if (file.getName().equals(".") || file.getName().equals("..")) continue;
      row = query.addRow();
      query.setAt("attributes", row, "");
      query.setAt("isdirectory", row, Caster.toBoolean(file.isDirectory()));
      query.setAt("lastmodified", row, new DateTimeImpl(file.getTimestamp()));
      query.setAt("length", row, Caster.toDouble(file.getSize()));
      query.setAt("mode", row, FTPConstant.getPermissionASInteger(file));
      query.setAt("type", row, FTPConstant.getTypeAsString(file.getType()));
      // query.setAt("permission",row,FTPConstant.getPermissionASInteger(file));
      query.setAt("raw", row, file.getRawListing());
      query.setAt("name", row, file.getName());
      query.setAt("path", row, directory + file.getName());
      query.setAt("url", row, prefix + "://" + hostName + "" + directory + file.getName());
    }
    return query;
  }
Esempio n. 4
0
  public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct = new StructImpl();
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
      sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
  }