use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class StreamPostStateProcessor method process.
/**
* Process the handed StreamEvent
*
* @param complexEventChunk event chunk to be processed
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
if (complexEventChunk.hasNext()) {
// one one event will be coming
StateEvent stateEvent = (StateEvent) complexEventChunk.next();
process(stateEvent, complexEventChunk);
}
complexEventChunk.clear();
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class InsertIntoTableCallback method send.
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
if (convertToStreamEvent) {
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>(complexEventChunk.isBatch());
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
StreamEvent borrowEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(complexEvent.getTimestamp(), complexEvent.getOutputData(), complexEvent.getType(), borrowEvent);
streamEventChunk.add(borrowEvent);
}
table.addEvents(streamEventChunk, noOfEvents);
} else {
table.addEvents((ComplexEventChunk<StreamEvent>) complexEventChunk, noOfEvents);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class OutputCallback method constructMatchingStateEventChunk.
protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
while (matchingComplexEventChunk.hasNext()) {
ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
matchingComplexEventChunk.remove();
StateEvent stateEvent = stateEventPool.borrowEvent();
if (convertToStreamEvent) {
StreamEvent borrowEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
stateEvent.addEvent(matchingStreamIndex, borrowEvent);
} else {
stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
}
stateEventChunk.add(stateEvent);
}
return stateEventChunk;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class QueryCallback method receiveStreamEvent.
public void receiveStreamEvent(ComplexEventChunk complexEventChunk) {
Event[] currentEvents = null;
Event[] expiredEvents = null;
long timestamp = -1;
List<Event> currentEventBuffer = new ArrayList<Event>();
List<Event> expiredEventBuffer = new ArrayList<Event>();
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent streamEvent = complexEventChunk.next();
if (streamEvent.getType() == StreamEvent.Type.EXPIRED) {
bufferEvent(streamEvent, expiredEventBuffer);
} else if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
bufferEvent(streamEvent, currentEventBuffer);
}
timestamp = streamEvent.getTimestamp();
}
if (!currentEventBuffer.isEmpty()) {
currentEvents = currentEventBuffer.toArray(new Event[currentEventBuffer.size()]);
currentEventBuffer.clear();
}
if (!expiredEventBuffer.isEmpty()) {
expiredEvents = expiredEventBuffer.toArray(new Event[expiredEventBuffer.size()]);
expiredEventBuffer.clear();
}
send(timestamp, currentEvents, expiredEvents);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IndexEventHolder method findEvents.
@Override
public Collection<StreamEvent> findEvents(String attribute, Compare.Operator operator, Object value) {
if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
StreamEvent resultEvent;
HashSet<StreamEvent> resultEventSet;
switch(operator) {
case LESS_THAN:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values();
case GREATER_THAN:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values();
case LESS_THAN_EQUAL:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values();
case GREATER_THAN_EQUAL:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values();
case EQUAL:
resultEventSet = new HashSet<StreamEvent>();
resultEvent = primaryKeyData.get(value);
if (resultEvent != null) {
resultEventSet.add(resultEvent);
}
return resultEventSet;
case NOT_EQUAL:
if (primaryKeyData.size() > 0) {
resultEventSet = new HashSet<StreamEvent>(primaryKeyData.values());
} else {
return new HashSet<StreamEvent>();
}
resultEvent = primaryKeyData.get(value);
if (resultEvent != null) {
resultEventSet.remove(resultEvent);
}
return resultEventSet;
}
} else {
HashSet<StreamEvent> resultEventSet = new HashSet<StreamEvent>();
TreeMap<Object, Set<StreamEvent>> currentIndexedData = indexData.get(attribute);
Set<StreamEvent> resultEvents;
switch(operator) {
case LESS_THAN:
for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, false).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case GREATER_THAN:
for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, false).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case LESS_THAN_EQUAL:
for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, true).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case GREATER_THAN_EQUAL:
for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, true).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case EQUAL:
resultEvents = currentIndexedData.get(value);
if (resultEvents != null) {
resultEventSet.addAll(resultEvents);
}
return resultEventSet;
case NOT_EQUAL:
if (currentIndexedData.size() > 0) {
resultEventSet = new HashSet<StreamEvent>();
for (Set<StreamEvent> eventSet : currentIndexedData.values()) {
resultEventSet.addAll(eventSet);
}
} else {
resultEventSet = new HashSet<StreamEvent>();
}
resultEvents = currentIndexedData.get(value);
if (resultEvents != null) {
resultEventSet.removeAll(resultEvents);
}
return resultEventSet;
}
}
throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
Aggregations