use of io.siddhi.core.event.stream.Operation in project siddhi by wso2.
the class SnapshotableStreamEventQueue method poll.
public StreamEvent poll() {
reset();
if (first != null) {
StreamEvent firstEvent = first;
first = first.getNext();
firstEvent.setNext(null);
if (!isFullSnapshot()) {
if (isOperationLogEnabled) {
operationChangeLog.add(new Operation(Operator.REMOVE));
}
operationChangeLogSize++;
} else {
operationChangeLog.clear();
operationChangeLogSize = 0;
forceFullSnapshot = true;
}
return firstEvent;
} else {
return null;
}
}
use of io.siddhi.core.event.stream.Operation in project siddhi by wso2.
the class SnapshotableStreamEventQueue method add.
public void add(StreamEvent events) {
if (!isFullSnapshot()) {
if (isOperationLogEnabled) {
operationChangeLog.add(new Operation(Operator.ADD, copyEvents(events)));
}
operationChangeLogSize++;
} else {
operationChangeLog.clear();
operationChangeLogSize = 0;
forceFullSnapshot = true;
}
if (first == null) {
first = events;
} else {
last.setNext(events);
}
last = getLastEvent(events);
}
use of io.siddhi.core.event.stream.Operation in project siddhi by wso2.
the class SnapshotableStreamEventQueue method overwrite.
public void overwrite(StreamEvent streamEvent) {
if (!isFullSnapshot()) {
if (isOperationLogEnabled) {
operationChangeLog.add(new Operation(Operator.OVERWRITE, new Object[] { eventIndex, eventClonerHolder.getStreamEventCloner().copyStreamEvent(streamEvent) }));
}
operationChangeLogSize++;
} else {
operationChangeLog.clear();
operationChangeLogSize = 0;
forceFullSnapshot = true;
}
if (previousToLastReturned != null) {
previousToLastReturned.setNext(streamEvent);
} else {
first = streamEvent;
}
StreamEvent next = lastReturned.getNext();
if (next != null) {
streamEvent.setNext(next);
} else {
last = streamEvent;
}
lastReturned = streamEvent;
}
use of io.siddhi.core.event.stream.Operation in project siddhi by wso2.
the class SnapshotableEventQueueTestCase method incrementalPersistenceTest3.
@Test
public void incrementalPersistenceTest3() throws InterruptedException, IOException, ClassNotFoundException {
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
for (int i = 0; i < 10; i++) {
streamEvent.getOutputData()[2] = i;
snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
}
HashMap<Long, String> snapshots = new HashMap<>();
Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
Assert.assertTrue(streamEvents != null);
snapshots.put(3L, toString(snapshot1));
snapshotableStreamEventQueue.next();
snapshotableStreamEventQueue.next();
snapshotableStreamEventQueue.next();
for (int i = 7; i < 10; i++) {
snapshotableStreamEventQueue.next();
snapshotableStreamEventQueue.remove();
}
Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
Assert.assertTrue(operationLog != null);
snapshots.put(4L, toString(snapshot2));
for (int i = 10; i < 15; i++) {
streamEvent.getOutputData()[2] = i;
snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
}
Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
operationLog = (ArrayList<Operation>) snapshot3.getState();
Assert.assertTrue(operationLog != null);
snapshots.put(5L, toString(snapshot3));
SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
SnapshotStateList snapshotStateList = new SnapshotStateList();
for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
}
snapshotableStreamEventQueue2.restore(snapshotStateList);
Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
use of io.siddhi.core.event.stream.Operation in project siddhi by wso2.
the class SnapshotableEventQueueTestCase method incrementalPersistenceTest5.
@Test
public void incrementalPersistenceTest5() throws InterruptedException, IOException, ClassNotFoundException {
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
for (int i = 0; i < 10; i++) {
streamEvent.getOutputData()[2] = i;
snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
}
HashMap<Long, String> snapshots = new HashMap<>();
Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
Assert.assertTrue(streamEvents != null);
snapshots.put(3L, toString(snapshot1));
snapshotableStreamEventQueue.next();
snapshotableStreamEventQueue.next();
snapshotableStreamEventQueue.next();
for (int i = 7; i < 10; i++) {
snapshotableStreamEventQueue.next();
streamEvent.getOutputData()[2] = i + 20;
snapshotableStreamEventQueue.overwrite(streamEventCloner.copyStreamEvent(streamEvent));
}
Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
Assert.assertTrue(operationLog != null);
snapshots.put(4L, toString(snapshot2));
for (int i = 10; i < 15; i++) {
streamEvent.getOutputData()[2] = i;
snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
}
Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
operationLog = (ArrayList<Operation>) snapshot3.getState();
Assert.assertTrue(operationLog != null);
snapshots.put(5L, toString(snapshot3));
SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
SnapshotStateList snapshotStateList = new SnapshotStateList();
for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
}
snapshotableStreamEventQueue2.restore(snapshotStateList);
Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
Aggregations