Search in sources :

Example 81 with Query

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;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Collection(lucee.runtime.type.Collection) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType)

Example 82 with Query

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.
    }
}
Also used : Query(lucee.runtime.type.Query) Method(java.lang.reflect.Method) PageException(lucee.runtime.exp.PageException) Collection(lucee.runtime.type.Collection) List(java.util.List) Map(java.util.Map)

Aggregations

Query (lucee.runtime.type.Query)82 QueryImpl (lucee.runtime.type.QueryImpl)52 Struct (lucee.runtime.type.Struct)19 Array (lucee.runtime.type.Array)16 Collection (lucee.runtime.type.Collection)14 Iterator (java.util.Iterator)13 PageException (lucee.runtime.exp.PageException)12 Map (java.util.Map)11 StructImpl (lucee.runtime.type.StructImpl)11 ApplicationException (lucee.runtime.exp.ApplicationException)10 Stopwatch (lucee.runtime.timer.Stopwatch)10 Key (lucee.runtime.type.Collection.Key)9 List (java.util.List)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 QueryColumn (lucee.runtime.type.QueryColumn)7 Enumeration (java.util.Enumeration)6 Entry (java.util.Map.Entry)6 FunctionException (lucee.runtime.exp.FunctionException)6