use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ExhaustiveCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
for (StreamEvent storeEvent : storeEvents) {
matchingEvent.setEvent(storeEventIndex, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
matchingEvent.setEvent(storeEventIndex, null);
}
return returnEventChunk.getFirst();
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ExhaustiveCollectionExecutor method findEvents.
public Collection<StreamEvent> findEvents(StateEvent matchingEvent, Collection<StreamEvent> preProcessedstoreEvents) {
HashSet<StreamEvent> streamEvents = new HashSet<StreamEvent>();
for (StreamEvent storeEvent : preProcessedstoreEvents) {
matchingEvent.setEvent(storeEventIndex, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
streamEvents.add(storeEvent);
}
matchingEvent.setEvent(storeEventIndex, null);
}
return streamEvents;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ExhaustiveCollectionExecutor method delete.
@Override
public void delete(StateEvent deletingEvent, IndexedEventHolder indexedEventHolder) {
Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
Set<StreamEvent> toDeleteEvents = new HashSet<StreamEvent>();
for (StreamEvent storeEvent : storeEvents) {
deletingEvent.setEvent(storeEventIndex, storeEvent);
if ((Boolean) expressionExecutor.execute(deletingEvent)) {
toDeleteEvents.add(storeEvent);
}
deletingEvent.setEvent(storeEventIndex, null);
}
indexedEventHolder.deleteAll(toDeleteEvents);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class OverwriteTableIndexOperator method tryUpdate.
@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
updatingOrAddingEventChunk.reset();
while (updatingOrAddingEventChunk.hasNext()) {
StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
}
return null;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class TestDebugger method testDebugger9.
@Test
public void testDebugger9() throws InterruptedException {
log.info("Siddi Debugger Test 9: Test state traversal in a simple query");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
final String query = "@info(name = 'query1')" + "from cseEventStream#window.length(3) " + "select symbol, price, sum(volume) as volume " + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
inEventCount.addAndGet(events.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {
@Override
public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
log.info("Query: " + queryName + ":" + queryTerminal);
log.info(event);
int count = debugEventCount.addAndGet(getCount(event));
if (count == 2) {
Map<String, Object> queryState = debugger.getQueryState(queryName);
log.info(queryState);
log.info(queryState.values().toArray()[0]);
StreamEvent streamEvent = null;
// Order of the query state items is unpredictable
for (Map.Entry<String, Object> entry : queryState.entrySet()) {
if (entry.getKey().startsWith("AbstractStreamProcessor")) {
streamEvent = (StreamEvent) ((Map<String, Object>) entry.getValue()).get("ExpiredEventChunk");
break;
}
}
AssertJUnit.assertArrayEquals(streamEvent.getOutputData(), new Object[] { "WSO2", 50.0f, null });
}
debugger.next();
}
});
inputHandler.send(new Object[] { "WSO2", 50f, 60 });
inputHandler.send(new Object[] { "WSO2", 70f, 40 });
Thread.sleep(100);
AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get());
AssertJUnit.assertEquals("Invalid number of debug events", 4, debugEventCount.get());
siddhiAppRuntime.shutdown();
}
Aggregations