use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method process.
/**
* Here an assumption is taken:
* Parameter: timestamp: The time which the window determines as current time and will act upon,
* the value of this parameter should be monotonically increasing.
* from https://docs.wso2.com/display/CEP400/Inbuilt+Windows#InbuiltWindows-externalTime
*/
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
// event incoming trigger process. No events means no action
if (streamEventChunk.getFirst() == null) {
return;
}
List<ComplexEventChunk<StreamEvent>> complexEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
synchronized (this) {
initTiming(streamEventChunk.getFirst());
StreamEvent nextStreamEvent = streamEventChunk.getFirst();
while (nextStreamEvent != null) {
StreamEvent currStreamEvent = nextStreamEvent;
nextStreamEvent = nextStreamEvent.getNext();
if (currStreamEvent.getType() == ComplexEvent.Type.TIMER) {
if (lastScheduledTime <= currStreamEvent.getTimestamp()) {
// implies that there have not been any more events after this schedule has been done.
if (!flushed) {
flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
flushed = true;
} else {
if (currentEventChunk.getFirst() != null) {
appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
}
}
// rescheduling to emit the current batch after expiring it if no further events arrive.
lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
scheduler.notifyAt(lastScheduledTime);
}
continue;
} else if (currStreamEvent.getType() != ComplexEvent.Type.CURRENT) {
continue;
}
long currentEventTime = (Long) timestampExpressionExecutor.execute(currStreamEvent);
if (lastCurrentEventTime < currentEventTime) {
lastCurrentEventTime = currentEventTime;
}
if (currentEventTime < endTime) {
cloneAppend(streamEventCloner, currStreamEvent);
} else {
if (flushed) {
appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
flushed = false;
} else {
flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
}
// update timestamp, call next processor
endTime = findEndTime(lastCurrentEventTime, startTime, timeToKeep);
cloneAppend(streamEventCloner, currStreamEvent);
// triggering the last batch expiration.
if (schedulerTimeout > 0) {
lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
scheduler.notifyAt(lastScheduledTime);
}
}
}
}
for (ComplexEventChunk<StreamEvent> complexEventChunk : complexEventChunks) {
nextProcessor.process(complexEventChunk);
}
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class InsertIntoWindowCallback method send.
/**
* Add the event into the {@link Window}
*
* @param complexEventChunk the event to add
* @param noOfEvents number of events
*/
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
// If events are inserted directly from another window, expired events can arrive
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
}
}
window.add(complexEventChunk);
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class TimeBatchWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
this.siddhiAppContext = siddhiAppContext;
if (outputExpectsExpiredEvents) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
}
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else if (attributeExpressionExecutors.length == 2) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
// start time
isStartTimeEnabled = true;
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
} else {
startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
}
} else {
throw new SiddhiAppValidationException("Time window should only have one or two parameters. " + "(<int|long|time> windowTime), but found " + attributeExpressionExecutors.length + " input " + "attributes");
}
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class TimeLengthWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (attributeExpressionExecutors.length == 2) {
length = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("TimeLength window's first parameter attribute should " + "be either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("TimeLength window should have constant parameter " + "attributes but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else {
throw new SiddhiAppValidationException("TimeLength window should only have two parameters (<int> " + "windowTime,<int> windowLength), but found " + attributeExpressionExecutors.length + " input " + "attributes");
}
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class TimeWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else {
throw new SiddhiAppValidationException("Time window should only have one parameter (<int|long|time> " + "windowTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
}
Aggregations