use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class JoinStreamRuntime method clone.
@Override
public StreamRuntime clone(String key) {
JoinStreamRuntime joinStreamRuntime = new JoinStreamRuntime(siddhiAppContext, metaStateEvent);
for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
joinStreamRuntime.addRuntime((SingleStreamRuntime) singleStreamRuntime.clone(key));
}
SingleStreamRuntime leftSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(0);
SingleStreamRuntime rightSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(1);
Processor lastLeftProcessor = leftSingleStreamRuntime.getProcessorChain();
while (!(lastLeftProcessor instanceof JoinProcessor)) {
lastLeftProcessor = lastLeftProcessor.getNextProcessor();
}
JoinProcessor leftPreJoinProcessor = (JoinProcessor) lastLeftProcessor;
WindowProcessor leftWindowProcessor = (WindowProcessor) leftPreJoinProcessor.getNextProcessor();
JoinProcessor leftPostJoinProcessor = (JoinProcessor) leftWindowProcessor.getNextProcessor();
Processor lastRightProcessor = rightSingleStreamRuntime.getProcessorChain();
while (!(lastRightProcessor instanceof JoinProcessor)) {
lastRightProcessor = lastRightProcessor.getNextProcessor();
}
JoinProcessor rightPreJoinProcessor = (JoinProcessor) lastRightProcessor;
WindowProcessor rightWindowProcessor = (WindowProcessor) rightPreJoinProcessor.getNextProcessor();
JoinProcessor rightPostJoinProcessor = (JoinProcessor) rightWindowProcessor.getNextProcessor();
rightPostJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
rightPreJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
leftPreJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
leftPostJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
return joinStreamRuntime;
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class SingleStreamRuntime method clone.
@Override
public StreamRuntime clone(String key) {
ProcessStreamReceiver clonedProcessStreamReceiver = this.processStreamReceiver.clone(key);
EntryValveProcessor entryValveProcessor = null;
SchedulingProcessor schedulingProcessor;
Processor clonedProcessorChain = null;
if (processorChain != null) {
if (!(processorChain instanceof QuerySelector || processorChain instanceof OutputRateLimiter)) {
clonedProcessorChain = processorChain.cloneProcessor(key);
if (clonedProcessorChain instanceof EntryValveProcessor) {
entryValveProcessor = (EntryValveProcessor) clonedProcessorChain;
}
}
Processor processor = processorChain.getNextProcessor();
while (processor != null) {
if (!(processor instanceof QuerySelector || processor instanceof OutputRateLimiter)) {
Processor clonedProcessor = processor.cloneProcessor(key);
clonedProcessorChain.setToLast(clonedProcessor);
if (clonedProcessor instanceof EntryValveProcessor) {
entryValveProcessor = (EntryValveProcessor) clonedProcessor;
} else if (clonedProcessor instanceof SchedulingProcessor) {
schedulingProcessor = (SchedulingProcessor) clonedProcessor;
schedulingProcessor.setScheduler(((SchedulingProcessor) processor).getScheduler().clone(key, entryValveProcessor));
}
}
processor = processor.getNextProcessor();
}
}
return new SingleStreamRuntime(clonedProcessStreamReceiver, clonedProcessorChain, metaComplexEvent);
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class StreamInnerStateRuntime method clone.
@Override
public InnerStateRuntime clone(String key) {
StreamInnerStateRuntime streamInnerStateRuntime = new StreamInnerStateRuntime(stateType);
for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
streamInnerStateRuntime.singleStreamRuntimeList.add((SingleStreamRuntime) singleStreamRuntime.clone(key));
}
Processor processor = streamInnerStateRuntime.singleStreamRuntimeList.get(0).getProcessorChain();
streamInnerStateRuntime.firstProcessor = (StreamPreStateProcessor) processor;
while (processor != null) {
if (processor instanceof StreamPostStateProcessor) {
streamInnerStateRuntime.lastProcessor = (StreamPostStateProcessor) processor;
break;
} else {
processor = processor.getNextProcessor();
}
}
((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor).setThisStatePreProcessor((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisStatePostProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisLastProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
return streamInnerStateRuntime;
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class FrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEvent != null) {
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
String key = generateKey(streamEvent);
StreamEvent oldEvent = map.put(key, clonedEvent);
if (oldEvent != null) {
countMap.put(key, countMap.get(key) + 1);
streamEventChunk.add(streamEvent);
} else {
// This is a new event
if (map.size() > mostFrequentCount) {
List<String> keys = new ArrayList<String>(countMap.keySet());
for (int i = 0; i < mostFrequentCount; i++) {
int count = countMap.get(keys.get(i)) - 1;
if (count == 0) {
countMap.remove(keys.get(i));
StreamEvent expiredEvent = map.remove(keys.get(i));
expiredEvent.setTimestamp(currentTime);
streamEventChunk.add(expiredEvent);
} else {
countMap.put(keys.get(i), count);
}
}
// now we have tried to remove one for newly added item
if (map.size() > mostFrequentCount) {
// nothing happend by the attempt to remove one from the
// map so we are ignoring this event
map.remove(key);
// Here we do nothing just drop the message
} else {
// we got some space, event is already there in map object
// we just have to add it to the countMap
countMap.put(key, 1);
streamEventChunk.add(streamEvent);
}
} else {
countMap.put(generateKey(streamEvent), 1);
streamEventChunk.add(streamEvent);
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.
the class LengthBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
synchronized (this) {
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<StreamEvent>(true);
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
currentEventChunk.add(clonedStreamEvent);
count++;
if (count == length) {
if (outputExpectsExpiredEvents) {
if (expiredEventChunk.getFirst() != null) {
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
outputStreamEventChunk.add(expiredEventChunk.getFirst());
}
}
if (expiredEventChunk != null) {
expiredEventChunk.clear();
}
if (currentEventChunk.getFirst() != null) {
// add reset event in front of current events
outputStreamEventChunk.add(resetEvent);
resetEvent = null;
if (expiredEventChunk != null) {
currentEventChunk.reset();
while (currentEventChunk.hasNext()) {
StreamEvent currentEvent = currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
expiredEventChunk.add(toExpireEvent);
}
}
resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
resetEvent.setType(ComplexEvent.Type.RESET);
outputStreamEventChunk.add(currentEventChunk.getFirst());
}
currentEventChunk.clear();
count = 0;
if (outputStreamEventChunk.getFirst() != null) {
streamEventChunks.add(outputStreamEventChunk);
}
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
Aggregations