use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater 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);
}
use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater 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.stream.populater.ComplexEventPopulater 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);
}
use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater in project siddhi by wso2.
the class TableWindowProcessor method cloneProcessor.
@Override
public Processor cloneProcessor(String key) {
try {
TableWindowProcessor streamProcessor = new TableWindowProcessor(table);
streamProcessor.inputDefinition = inputDefinition;
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
for (int i = 0; i < attributeExpressionLength; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
}
streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
streamProcessor.attributeExpressionLength = attributeExpressionLength;
streamProcessor.additionalAttributes = additionalAttributes;
streamProcessor.complexEventPopulater = complexEventPopulater;
streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
streamProcessor.start();
return streamProcessor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater in project siddhi by wso2.
the class WindowWindowProcessor method cloneProcessor.
@Override
public Processor cloneProcessor(String key) {
try {
WindowWindowProcessor streamProcessor = new WindowWindowProcessor(window);
streamProcessor.inputDefinition = inputDefinition;
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
for (int i = 0; i < attributeExpressionLength; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
}
streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
streamProcessor.attributeExpressionLength = attributeExpressionLength;
streamProcessor.additionalAttributes = additionalAttributes;
streamProcessor.complexEventPopulater = complexEventPopulater;
streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
streamProcessor.start();
return streamProcessor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
Aggregations