Search in sources :

Example 1 with RetirementCallback

use of com.swiftmq.impl.streams.comp.memory.RetirementCallback 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 RetirementCallback

use of com.swiftmq.impl.streams.comp.memory.RetirementCallback 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)

Aggregations

HeapMemory (com.swiftmq.impl.streams.comp.memory.HeapMemory)2 Memory (com.swiftmq.impl.streams.comp.memory.Memory)2 RetirementCallback (com.swiftmq.impl.streams.comp.memory.RetirementCallback)2