use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class StreamPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (withinStates.size() > 0) {
if (isExpired(stateEvent, streamEvent.getTimestamp())) {
iterator.remove();
continue;
}
}
// if (Math.abs(stateEvent.getTimestamp() - streamEvent.getTimestamp()) > withinStates) {
// iterator.remove();
// // switch (stateType) {
// // case PATTERN:
// // stateEvent.setEvent(stateId, null);
// // break;
// // case SEQUENCE:
// // stateEvent.setEvent(stateId, null);
// // iterator.remove();
// // if (thisStatePostProcessor.callbackPreStateProcessor != null) {
// // thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
// // }
// // break;
// // }
// continue;
// }
// }
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (stateChanged) {
iterator.remove();
} else {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, null);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, null);
iterator.remove();
if (thisStatePostProcessor.callbackPreStateProcessor != null) {
thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
}
break;
}
}
}
return returnEventChunk;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ConversionStreamEventChunk method convertAndAssign.
// @Override
// public void convertAndAssignFirst(StreamEvent streamEvent) {
// StreamEvent borrowedEvent = streamEventPool.borrowEvent();
// eventConverter.convertComplexEvent(streamEvent, borrowedEvent);
// first = borrowedEvent;
// last = first;
// }
public void convertAndAssign(Event[] events) {
StreamEvent firstEvent = streamEventPool.borrowEvent();
streamEventConverter.convertEvent(events[0], firstEvent);
StreamEvent currentEvent = firstEvent;
for (int i = 1, eventsLength = events.length; i < eventsLength; i++) {
StreamEvent nextEvent = streamEventPool.borrowEvent();
streamEventConverter.convertEvent(events[i], nextEvent);
currentEvent.setNext(nextEvent);
currentEvent = nextEvent;
}
first = firstEvent;
last = currentEvent;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ConversionStreamEventChunk method convertAndAssign.
public void convertAndAssign(long timestamp, Object[] data) {
StreamEvent borrowedEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(timestamp, data, borrowedEvent);
first = borrowedEvent;
last = first;
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ConversionStreamEventChunk method convertAndAdd.
public void convertAndAdd(Event event) {
StreamEvent borrowedEvent = streamEventPool.borrowEvent();
streamEventConverter.convertEvent(event, borrowedEvent);
if (first == null) {
first = borrowedEvent;
last = first;
} else {
last.setNext(borrowedEvent);
last = borrowedEvent;
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class StreamEventPopulaterFactory method constructEventPopulator.
/**
* Constructs StreamEventPopulater according to MetaStateEvent and to be mapped attributes
*
* @param metaStreamEvent info for populating the StreamEvent
* @param streamEventChainIndex StreamEvent chain index
* @param attributes mapped attributes
* @return StateEventPopulater
*/
public static ComplexEventPopulater constructEventPopulator(MetaStreamEvent metaStreamEvent, int streamEventChainIndex, List<Attribute> attributes) {
List<StreamMappingElement> streamMappingElements = new ArrayList<StreamMappingElement>();
for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) {
Attribute attribute = attributes.get(i);
StreamMappingElement streamMappingElement = new StreamMappingElement();
streamMappingElement.setFromPosition(i);
int index = metaStreamEvent.getOutputData().indexOf(attribute);
if (index > -1) {
streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, OUTPUT_DATA_INDEX, index });
} else {
index = metaStreamEvent.getOnAfterWindowData().indexOf(attribute);
if (index > -1) {
streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, ON_AFTER_WINDOW_DATA_INDEX, index });
} else {
index = metaStreamEvent.getBeforeWindowData().indexOf(attribute);
if (index > -1) {
streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, BEFORE_WINDOW_DATA_INDEX, index });
} else {
streamMappingElement.setToPosition(null);
}
}
}
streamMappingElements.add(streamMappingElement);
}
return new SelectiveComplexEventPopulater(streamMappingElements);
}
Aggregations