use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class JoinProcessor method process.
/**
* Process the handed StreamEvent.
*
* @param complexEventChunk event chunk to be processed
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
if (trigger) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(true);
StateEvent joinStateEvent = new StateEvent(2, 0);
StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
complexEventChunk.clear();
while (nextEvent != null) {
StreamEvent streamEvent = nextEvent;
nextEvent = streamEvent.getNext();
streamEvent.setNext(null);
joinLockWrapper.lock();
try {
ComplexEvent.Type eventType = streamEvent.getType();
if (eventType == ComplexEvent.Type.TIMER) {
continue;
} else if (eventType == ComplexEvent.Type.RESET) {
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
}
} else {
joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
StreamEvent foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
joinStateEvent.setEvent(matchingStreamIndex, null);
if (foundStreamEvent == null) {
if (outerJoinProcessor && !leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
} else if (outerJoinProcessor && leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
}
} else {
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
foundStreamEvent.setNext(null);
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
}
foundStreamEvent = nextFoundStreamEvent;
}
}
}
} finally {
joinLockWrapper.unlock();
}
if (returnEventChunk.getFirst() != null) {
selector.process(returnEventChunk);
returnEventChunk.clear();
}
}
} else {
if (preJoinProcessor) {
joinLockWrapper.lock();
try {
nextProcessor.process(complexEventChunk);
} finally {
joinLockWrapper.unlock();
}
}
}
}
use of org.wso2.carbon.apimgt.core.models.Event 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.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(Event event) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertEvent(event, borrowedEvent);
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(borrowedEvent);
send(key, borrowedEvent);
}
if (partitionExecutors.size() == 0) {
send(borrowedEvent);
}
eventPool.returnEvents(borrowedEvent);
}
use of org.wso2.carbon.apimgt.core.models.Event 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.carbon.apimgt.core.models.Event 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);
}
}
Aggregations