use of lucee.runtime.type.Query in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageAsQuery.
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;
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class Arch method sizeOf.
private static void sizeOf(Creation creator, Size size, Object obj, Set<Object> parents) throws PageException {
if (obj == null)
return;
Object raw = obj;
// TODO this is just a patch solution, find a better way to handle this kind of situation (Wrapper classes)
if (isInstaneOf(obj.getClass(), "lucee.runtime.text.xml.struct.XMLStruct")) {
try {
Method toNode = raw.getClass().getMethod("toNode", new Class[0]);
raw = toNode.invoke(obj, new Object[0]);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
if (parents.contains(raw))
return;
parents.add(raw);
try {
if (obj instanceof Collection) {
if (obj instanceof Query)
sizeOf(creator, size, (Query) obj, parents);
else
sizeOf(creator, size, ((Collection) obj).valueIterator(), parents);
return;
} else // Map
if (obj instanceof Map) {
sizeOf(creator, size, ((Map) obj).values().iterator(), parents);
return;
} else // List
if (obj instanceof List) {
sizeOf(creator, size, ((List) obj).iterator(), parents);
return;
} else // String
if (obj instanceof String) {
size.size += (CHAR_SIZE * ((String) obj).length()) + REF_SIZE;
} else // Number
if (obj instanceof Number) {
if (obj instanceof Double)
size.size += DOUBLE_SIZE + REF_SIZE;
else if (obj instanceof Float)
size.size += FLOAT_SIZE + REF_SIZE;
else if (obj instanceof Long)
size.size += LONG_SIZE + REF_SIZE;
else if (obj instanceof Integer)
size.size += INT_SIZE + REF_SIZE;
else if (obj instanceof Short)
size.size += SHORT_SIZE + REF_SIZE;
else if (obj instanceof Byte)
size.size += BYTE_SIZE + REF_SIZE;
} else if (obj instanceof Boolean)
size.size += REF_SIZE + BOOLEAN_SIZE;
else if (obj instanceof Character)
size.size += REF_SIZE + CHAR_SIZE;
else
size.size += _sizeOf(obj);
size.count++;
} finally {
// parents.remove(raw);// TODO should we not remove, to see if sister is me.
}
}
Aggregations