use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class TimeLengthWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
expiredEventChunk.reset();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
long timeDiff = expiredEvent.getTimestamp() - currentTime + timeInMilliSeconds;
if (timeDiff <= 0) {
expiredEventChunk.remove();
count--;
expiredEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(expiredEvent);
} else {
break;
}
}
expiredEventChunk.reset();
if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
if (count < length) {
count++;
this.expiredEventChunk.add(clonedEvent);
} else {
StreamEvent firstEvent = this.expiredEventChunk.poll();
if (firstEvent != null) {
firstEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(firstEvent);
this.expiredEventChunk.add(clonedEvent);
}
}
scheduler.notifyAt(clonedEvent.getTimestamp() + timeInMilliSeconds);
} else {
streamEventChunk.remove();
}
}
}
streamEventChunk.reset();
if (streamEventChunk.hasNext()) {
nextProcessor.process(streamEventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class QuerySelector method orderEventChunk.
private void orderEventChunk(ComplexEventChunk complexEventChunk) {
ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk(complexEventChunk.isBatch());
List<ComplexEvent> eventList = new ArrayList<>();
ComplexEvent.Type currentEventType = null;
complexEventChunk.reset();
if (complexEventChunk.getFirst() != null) {
currentEventType = complexEventChunk.getFirst().getType();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
if (currentEventType == event.getType()) {
eventList.add(event);
} else {
currentEventType = event.getType();
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
eventList.clear();
eventList.add(event);
}
}
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
complexEventChunk.clear();
complexEventChunk.add(orderingComplexEventChunk.getFirst());
}
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class QuerySelector method processInBatchGroupBy.
private ComplexEventChunk processInBatchGroupBy(ComplexEventChunk complexEventChunk) {
Map<String, ComplexEvent> groupedEvents = new LinkedHashMap<String, ComplexEvent>();
complexEventChunk.reset();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
String groupByKey = groupByKeyGenerator.constructEventKey(event);
GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupByKey);
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
complexEventChunk.remove();
groupedEvents.put(groupByKey, event);
}
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (groupedEvents.size() != 0) {
complexEventChunk.clear();
for (Map.Entry<String, ComplexEvent> groupedEventEntry : groupedEvents.entrySet()) {
complexEventChunk.add(new GroupedComplexEvent(groupedEventEntry.getKey(), groupedEventEntry.getValue()));
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
complexEventChunk.reset();
return complexEventChunk;
}
return null;
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class QuerySelector method limitEventChunk.
private void limitEventChunk(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
int limitCount = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == StreamEvent.Type.CURRENT || event.getType() == StreamEvent.Type.EXPIRED) {
if ((limit > limitCount) && (event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
limitCount++;
} else {
complexEventChunk.remove();
}
}
}
}
use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class LastPerEventOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
if (++counter == value) {
complexEventChunk.remove();
ComplexEventChunk<ComplexEvent> lastPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
lastPerEventChunk.add(event);
counter = 0;
outputEventChunks.add(lastPerEventChunk);
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
Aggregations