use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater in project carbon-apimgt by wso2.
the class AsyncAPIThrottleStreamProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
synchronized (this) {
long currentTime = executionPlanContext.getTimestampGenerator().currentTime();
if (expireEventTime == -1) {
if (startTime != -1) {
expireEventTime = addTimeShift(currentTime);
} else {
expireEventTime = executionPlanContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
}
scheduler.notifyAt(expireEventTime);
}
if (currentTime >= expireEventTime) {
expireEventTime += timeInMilliSeconds;
scheduler.notifyAt(expireEventTime);
throttledStateMap.clear();
}
while (streamEventChunk.hasNext()) {
String throttleKey;
long eventCount;
StreamEvent streamEvent = streamEventChunk.next();
if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
continue;
}
if (streamEvent.getOutputData()[0] != null) {
throttleKey = streamEvent.getOutputData()[0].toString();
if (throttledStateMap.containsKey(throttleKey)) {
eventCount = throttledStateMap.get(throttleKey).incrementAndGet();
if (eventCount > maxEventCount) {
complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime, true });
} else {
complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime, false });
}
} else {
throttledStateMap.put(throttleKey, new AtomicLong(1));
complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime, false });
}
} else {
complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime, false });
}
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedStreamEvent.setType(StreamEvent.Type.EXPIRED);
clonedStreamEvent.setTimestamp(expireEventTime);
expiredEventChunk.add(clonedStreamEvent);
}
expiredEventChunk.reset();
if (expiredEventChunk.getFirst() != null) {
streamEventChunk.add(expiredEventChunk.getFirst());
}
expiredEventChunk.clear();
}
if (streamEventChunk.getFirst() != null) {
streamEventChunk.setBatch(true);
nextProcessor.process(streamEventChunk);
streamEventChunk.setBatch(false);
}
}
use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater in project carbon-apimgt by wso2.
the class ThrottleStreamProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
synchronized (this) {
if (expireEventTime == -1) {
long currentTime = executionPlanContext.getTimestampGenerator().currentTime();
if (startTime != -1) {
expireEventTime = addTimeShift(currentTime);
} else {
expireEventTime = executionPlanContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
}
scheduler.notifyAt(expireEventTime);
}
long currentTime = executionPlanContext.getTimestampGenerator().currentTime();
boolean sendEvents;
if (currentTime >= expireEventTime) {
expireEventTime += timeInMilliSeconds;
scheduler.notifyAt(expireEventTime);
sendEvents = true;
} else {
sendEvents = false;
}
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
continue;
}
complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime });
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedStreamEvent.setType(StreamEvent.Type.EXPIRED);
clonedStreamEvent.setTimestamp(expireEventTime);
expiredEventChunk.add(clonedStreamEvent);
}
if (sendEvents) {
expiredEventChunk.reset();
if (expiredEventChunk.getFirst() != null) {
streamEventChunk.add(expiredEventChunk.getFirst());
}
expiredEventChunk.clear();
}
}
if (streamEventChunk.getFirst() != null) {
streamEventChunk.setBatch(true);
nextProcessor.process(streamEventChunk);
streamEventChunk.setBatch(false);
}
}
Aggregations