use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class AbstractRecordTable method add.
@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) throws ConnectionUnavailableException {
List<Object[]> records = new ArrayList<>();
addingEventChunk.reset();
long timestamp = 0L;
while (addingEventChunk.hasNext()) {
StreamEvent event = addingEventChunk.next();
records.add(event.getOutputData());
timestamp = event.getTimestamp();
}
if (recordTableHandler != null) {
recordTableHandler.add(timestamp, records);
} else {
add(records);
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
if (outputExpectsExpiredEvents) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
this.storeExpiredEvents = true;
}
if (attributeExpressionExecutors.length >= 2 && attributeExpressionExecutors.length <= 5) {
if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be a" + " variable, but found " + attributeExpressionExecutors[0].getClass());
}
if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.LONG) {
throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be " + "type long, but found " + attributeExpressionExecutors[0].getReturnType());
}
timestampExpressionExecutor = (VariableExpressionExecutor) attributeExpressionExecutors[0];
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
timeToKeep = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
} else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
timeToKeep = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 2nd parameter windowTime " + "should be either int or long, but found " + attributeExpressionExecutors[1].getReturnType());
}
if (attributeExpressionExecutors.length >= 3) {
isStartTimeEnabled = true;
if ((attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.INT) {
startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
} else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter " + "startTime should either be a constant (of type int or long) or an attribute (of type" + " long), but found " + attributeExpressionExecutors[2].getReturnType());
}
} else if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.LONG) {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter startTime " + "should either be a constant (of type int or long) or an attribute (of type long), but " + "found " + attributeExpressionExecutors[2].getReturnType());
} else {
startTimeAsVariable = attributeExpressionExecutors[2];
}
}
if (attributeExpressionExecutors.length >= 4) {
if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.INT) {
schedulerTimeout = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
} else if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.LONG) {
schedulerTimeout = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 4th parameter timeout " + "should be either int or long, but found " + attributeExpressionExecutors[3].getReturnType());
}
}
if (attributeExpressionExecutors.length == 5) {
if (attributeExpressionExecutors[4].getReturnType() == Attribute.Type.BOOL) {
replaceTimestampWithBatchEndTime = Boolean.parseBoolean(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[4]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 5th parameter " + "replaceTimestampWithBatchEndTime should be bool, but found " + attributeExpressionExecutors[4].getReturnType());
}
}
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window should only have two to five " + "parameters (<long> timestamp, <int|long|time> windowTime, <long> startTime, <int|long|time> " + "timeout, <bool> replaceTimestampWithBatchEndTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
if (schedulerTimeout > 0) {
if (expiredEventChunk == null) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
}
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class LossyFrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
while (streamEvent != null) {
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
totalCount++;
if (totalCount != 1) {
currentBucketId = Math.ceil(totalCount / windowWidth);
}
String currentKey = generateKey(streamEvent);
StreamEvent oldEvent = map.put(currentKey, clonedEvent);
if (oldEvent != null) {
// this event is already in the store
countMap.put(currentKey, countMap.get(currentKey).incrementCount());
} else {
// This is a new event
LossyCount lCount;
lCount = new LossyCount(1, (int) currentBucketId - 1);
countMap.put(currentKey, lCount);
}
// calculating all the events in the system which match the
// requirement provided by the user
List<String> keys = new ArrayList<String>();
keys.addAll(countMap.keySet());
for (String key : keys) {
LossyCount lossyCount = countMap.get(key);
if (lossyCount.getCount() >= ((support - error) * totalCount)) {
// among the selected events, if the newly arrive event is there we mark it as an inEvent
if (key.equals(currentKey)) {
streamEventChunk.add(streamEvent);
}
}
}
if (totalCount % windowWidth == 0) {
// its time to run the data-structure prune code
keys = new ArrayList<String>();
keys.addAll(countMap.keySet());
for (String key : keys) {
LossyCount lossyCount = countMap.get(key);
if (lossyCount.getCount() + lossyCount.getBucketId() <= currentBucketId) {
log.info("Removing the Event: " + key + " from the window");
countMap.remove(key);
StreamEvent expirtedEvent = map.remove(key);
expirtedEvent.setTimestamp(currentTime);
streamEventChunk.add(expirtedEvent);
}
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class IndexEventHolder method add.
private void add(StreamEvent streamEvent) {
StreamEvent existingValue = null;
if (primaryKeyData != null) {
Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
existingValue = primaryKeyData.putIfAbsent(primaryKey, streamEvent);
if (existingValue != null) {
log.error("Siddhi App '" + siddhiAppName + "' table '" + tableName + "' drooping event : " + streamEvent + ", as there is already an event stored with primary key '" + primaryKey + "'");
}
}
if (indexData != null) {
for (Map.Entry<String, Integer> indexEntry : indexMetaData.entrySet()) {
TreeMap<Object, Set<StreamEvent>> indexMap = indexData.get(indexEntry.getKey());
Object key = streamEvent.getOutputData()[indexEntry.getValue()];
Set<StreamEvent> values = indexMap.get(key);
if (values == null) {
values = new HashSet<StreamEvent>();
values.add(streamEvent);
indexMap.put(streamEvent.getOutputData()[indexEntry.getValue()], values);
} else {
values.add(streamEvent);
}
}
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class AbsentStreamPostStateProcessor method process.
/**
* This method just mark the state changed but does not send the stateEvent to the next processors.
*
* @param stateEvent the state event
* @param complexEventChunk the ComplexEventChunk
*/
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
// Mark the state changed
thisStatePreProcessor.stateChanged();
// Update the timestamp
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setTimestamp(streamEvent.getTimestamp());
// This is the notification to AbsentStreamPreStateProcessor that this event has been processed
this.isEventReturned = true;
if (thisStatePreProcessor.isStartState) {
if (nextEveryStatePerProcessor != null && nextEveryStatePerProcessor == thisStatePreProcessor) {
// nextEveryStatePerProcessor refers the AbsentStreamPreStateProcessor
nextEveryStatePerProcessor.addEveryState(stateEvent);
}
}
((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Aggregations