use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(Event event, boolean endOfBatch) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertEvent(event, borrowedEvent);
streamEventChunk.add(borrowedEvent);
if (endOfBatch) {
ComplexEvent complexEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
receive(complexEvent);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(ComplexEvent complexEvent) {
if (partitionExecutors.size() == 0) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
send(borrowedEvent);
} else {
if (complexEvent.getNext() == null) {
for (PartitionExecutor partitionExecutor : partitionExecutors) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
String key = partitionExecutor.execute(borrowedEvent);
send(key, borrowedEvent);
}
} else {
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<ComplexEvent>(false);
complexEventChunk.add(complexEvent);
String currentKey = null;
while (complexEventChunk.hasNext()) {
ComplexEvent aEvent = complexEventChunk.next();
complexEventChunk.remove();
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(aEvent, borrowedEvent);
boolean currentEventMatchedPrevPartitionExecutor = false;
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(borrowedEvent);
if (key != null) {
if (currentKey == null) {
currentKey = key;
} else if (!currentKey.equals(key)) {
if (!currentEventMatchedPrevPartitionExecutor) {
ComplexEvent firstEvent = streamEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
streamEventChunk.clear();
} else {
ComplexEvent firstEvent = streamEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
streamEventChunk.clear();
StreamEvent cloneEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(aEvent, cloneEvent);
streamEventChunk.add(cloneEvent);
}
}
if (!currentEventMatchedPrevPartitionExecutor) {
streamEventChunk.add(borrowedEvent);
}
currentEventMatchedPrevPartitionExecutor = true;
}
}
}
send(currentKey, streamEventChunk.getFirst());
streamEventChunk.clear();
}
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class FirstPerEventOutputRateLimiter 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 == 0) {
complexEventChunk.remove();
ComplexEventChunk<ComplexEvent> firstPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
firstPerEventChunk.add(event);
outputEventChunks.add(firstPerEventChunk);
}
if (++counter == value) {
counter = 0;
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class LastGroupByPerEventOutputRateLimiter 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) {
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
if (++counter == value) {
counter = 0;
if (allGroupByKeyEvents.size() != 0) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
for (ComplexEvent complexEvent : allGroupByKeyEvents.values()) {
outputEventChunk.add(complexEvent);
}
allGroupByKeyEvents.clear();
outputEventChunks.add(outputEventChunk);
}
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
synchronized (this) {
complexEventChunk.reset();
String currentGroupByKey = null;
Map<Integer, Object> currentAggregateAttributeValueMap = null;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event);
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
currentGroupByKey = groupedComplexEvent.getGroupKey();
currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
if (currentAggregateAttributeValueMap == null) {
currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
}
}
if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
eventList.add(groupedComplexEvent);
for (Integer position : aggregateAttributePositionList) {
currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
for (Iterator<GroupedComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
GroupedComplexEvent currentEvent = iterator.next();
if (comparator.compare(currentEvent.getComplexEvent(), groupedComplexEvent.getComplexEvent()) == 0) {
iterator.remove();
for (Integer position : aggregateAttributePositionList) {
currentAggregateAttributeValueMap.put(position, groupedComplexEvent.getOutputData()[position]);
}
break;
}
}
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
eventList.clear();
groupByAggregateAttributeValueMap.clear();
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
Aggregations