Search in sources :

Example 1 with HeapMemory

use of com.swiftmq.impl.streams.comp.memory.HeapMemory in project swiftmq-ce by iitsoftware.

the class CountLimit method checkTumbling.

private void checkTumbling() {
    try {
        if (memory.size() >= n) {
            Memory retired = null;
            RetirementCallback callback = memory.retirementCallback();
            if (callback != null) {
                retired = new HeapMemory(ctx);
                retired.orderBy(memory.orderBy());
                for (int i = 0; i < n; i++) {
                    retired.add(memory.at(i));
                }
            }
            for (int i = 0; i < n; i++) {
                memory.remove(0);
            }
            if (callback != null)
                callback.execute(retired);
        }
    } catch (Exception e) {
        ctx.logStackTrace(e);
    }
}
Also used : Memory(com.swiftmq.impl.streams.comp.memory.Memory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) RetirementCallback(com.swiftmq.impl.streams.comp.memory.RetirementCallback)

Example 2 with HeapMemory

use of com.swiftmq.impl.streams.comp.memory.HeapMemory in project swiftmq-ce by iitsoftware.

the class CountLimit method checkSlidingLimit.

private void checkSlidingLimit() {
    try {
        if (memory.size() >= n) {
            int toRemove = memory.size() + 1 - n;
            Memory retired = null;
            RetirementCallback callback = memory.retirementCallback();
            if (callback != null) {
                retired = new HeapMemory(ctx);
                retired.orderBy(memory.orderBy());
                for (int i = 0; i < toRemove; i++) {
                    retired.add(memory.at(i));
                }
            }
            for (int i = 0; i < toRemove; i++) {
                memory.remove(0);
            }
            if (callback != null)
                callback.execute(retired);
        }
    } catch (Exception e) {
        ctx.logStackTrace(e);
    }
}
Also used : Memory(com.swiftmq.impl.streams.comp.memory.Memory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) RetirementCallback(com.swiftmq.impl.streams.comp.memory.RetirementCallback)

Example 3 with HeapMemory

use of com.swiftmq.impl.streams.comp.memory.HeapMemory in project swiftmq-ce by iitsoftware.

the class Util method query.

public static Memory query(Stream stream, Connection connection, String sql) throws Exception {
    Memory resultMemory = new HeapMemory(stream.getStreamCtx());
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(sql);
    ResultSetMetaData metaData = resultSet.getMetaData();
    while (resultSet.next()) {
        Message message = stream.create().message().message();
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            String name = metaData.getColumnName(i);
            Object value = resultSet.getObject(i);
            if (value instanceof BigDecimal)
                value = ((BigDecimal) value).doubleValue();
            message.property(name).set(value);
        }
        resultMemory.add(message);
    }
    resultSet.close();
    statement.close();
    return resultMemory;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Message(com.swiftmq.impl.streams.comp.message.Message) Memory(com.swiftmq.impl.streams.comp.memory.Memory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) HeapMemory(com.swiftmq.impl.streams.comp.memory.HeapMemory) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) BigDecimal(java.math.BigDecimal)

Aggregations

HeapMemory (com.swiftmq.impl.streams.comp.memory.HeapMemory)3 Memory (com.swiftmq.impl.streams.comp.memory.Memory)3 RetirementCallback (com.swiftmq.impl.streams.comp.memory.RetirementCallback)2 Message (com.swiftmq.impl.streams.comp.message.Message)1 BigDecimal (java.math.BigDecimal)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1