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);
}
}
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);
}
}
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;
}
Aggregations