use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class OutputRateLimiter method sendToCallBacks.
protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
if (siddhiAppContext.isStatsEnabled() && latencyTracker != null) {
latencyTracker.markOut();
}
if (lockWrapper != null) {
lockWrapper.unlock();
}
if (!queryCallbacks.isEmpty()) {
for (QueryCallback callback : queryCallbacks) {
callback.receiveStreamEvent(complexEventChunk);
}
}
if (outputCallback != null && complexEventChunk.getFirst() != null) {
complexEventChunk.reset();
int noOfEvents = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
noOfEvents++;
} else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
complexEventChunk.remove();
} else {
noOfEvents++;
}
}
if (complexEventChunk.getFirst() != null) {
outputCallback.send(complexEventChunk, noOfEvents);
}
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AllPerEventOutputRateLimiter 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();
allComplexEventChunk.add(event);
counter++;
if (counter == value) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
outputEventChunk.add(allComplexEventChunk.getFirst());
allComplexEventChunk.clear();
counter = 0;
outputEventChunks.add(outputEventChunk);
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class FirstGroupByPerEventOutputRateLimiter 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);
if (!groupByKeys.contains(groupedComplexEvent.getGroupKey())) {
groupByKeys.add(groupedComplexEvent.getGroupKey());
allComplexEventChunk.add(groupedComplexEvent.getComplexEvent());
}
if (++counter == value) {
if (allComplexEventChunk.getFirst() != null) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
outputEventChunk.add(allComplexEventChunk.getFirst());
outputEventChunks.add(outputEventChunk);
allComplexEventChunk.clear();
counter = 0;
groupByKeys.clear();
} else {
counter = 0;
groupByKeys.clear();
}
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class LogStreamProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
ComplexEvent complexEvent = streamEventChunk.next();
switch(attributeExpressionLength) {
case 0:
log.info(logPrefix + complexEvent);
break;
case 1:
if (isLogEventExpressionExecutor != null) {
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
log.info(logPrefix + complexEvent);
} else {
log.info(logPrefix + "Event Arrived");
}
} else {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
}
break;
case 2:
if (isLogEventExpressionExecutor != null) {
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
} else {
log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent));
}
} else {
LogPriority tempLogPriority = logPriority;
if (logPriorityExpressionExecutor != null) {
tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
}
String message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
logMessage(tempLogPriority, message);
}
break;
default:
String message;
if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
} else {
message = logPrefix + logMessageExpressionExecutor.execute(complexEvent);
}
LogPriority tempLogPriority = logPriority;
if (logPriorityExpressionExecutor != null) {
tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
}
logMessage(tempLogPriority, message);
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class StreamFunctionProcessor method processEventChunk.
@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
ComplexEvent complexEvent = streamEventChunk.next();
Object[] outputData;
switch(attributeExpressionLength) {
case 0:
outputData = process((Object) null);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
case 1:
outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
default:
Object[] inputData = new Object[attributeExpressionLength];
for (int i = 0; i < attributeExpressionLength; i++) {
inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
}
outputData = process(inputData);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
}
}
nextProcessor.process(streamEventChunk);
}
Aggregations