use of org.wso2.carbon.databridge.commons.Event in project siddhi by wso2.
the class TimeBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
if (nextEmitTime == -1) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
if (isStartTimeEnabled) {
nextEmitTime = getNextEmitTime(currentTime);
} else {
nextEmitTime = siddhiAppContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
}
scheduler.notifyAt(nextEmitTime);
}
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
boolean sendEvents;
if (currentTime >= nextEmitTime) {
nextEmitTime += timeInMilliSeconds;
scheduler.notifyAt(nextEmitTime);
sendEvents = true;
} else {
sendEvents = false;
}
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
continue;
}
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
currentEventChunk.add(clonedStreamEvent);
}
streamEventChunk.clear();
if (sendEvents) {
if (outputExpectsExpiredEvents) {
if (expiredEventChunk.getFirst() != null) {
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
streamEventChunk.add(expiredEventChunk.getFirst());
}
}
if (expiredEventChunk != null) {
expiredEventChunk.clear();
}
if (currentEventChunk.getFirst() != null) {
// add reset event in front of current events
streamEventChunk.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);
streamEventChunk.add(currentEventChunk.getFirst());
}
currentEventChunk.clear();
}
}
if (streamEventChunk.getFirst() != null) {
streamEventChunk.setBatch(true);
nextProcessor.process(streamEventChunk);
streamEventChunk.setBatch(false);
}
}
use of org.wso2.carbon.databridge.commons.Event in project siddhi by wso2.
the class StreamJunction method sendData.
private void sendData(long timeStamp, Object[] data) {
// Set timestamp to system if Siddhi is in playback mode
if (siddhiAppContext.isPlayback()) {
((EventTimeBasedMillisTimestampGenerator) this.siddhiAppContext.getTimestampGenerator()).setCurrentTimestamp(timeStamp);
}
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
throughputTracker.eventIn();
}
if (disruptor != null) {
long sequenceNo = ringBuffer.next();
try {
Event existingEvent = ringBuffer.get(sequenceNo);
existingEvent.setTimestamp(timeStamp);
existingEvent.setIsExpired(false);
System.arraycopy(data, 0, existingEvent.getData(), 0, data.length);
} finally {
ringBuffer.publish(sequenceNo);
}
} else {
for (Receiver receiver : receivers) {
receiver.receive(timeStamp, data);
}
}
}
use of org.wso2.carbon.databridge.commons.Event in project siddhi by wso2.
the class StreamJunction method sendEvent.
public void sendEvent(ComplexEvent complexEvent) {
if (isTraceEnabled) {
log.trace("Event is received by streamJunction " + this);
}
ComplexEvent complexEventList = complexEvent;
if (disruptor != null) {
while (complexEventList != null) {
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
throughputTracker.eventIn();
}
long sequenceNo = ringBuffer.next();
try {
Event existingEvent = ringBuffer.get(sequenceNo);
existingEvent.copyFrom(complexEventList);
} finally {
ringBuffer.publish(sequenceNo);
}
complexEventList = complexEventList.getNext();
}
} else {
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
int messageCount = 0;
while (complexEventList != null) {
messageCount++;
complexEventList = complexEventList.getNext();
}
throughputTracker.eventsIn(messageCount);
}
for (Receiver receiver : receivers) {
receiver.receive(complexEvent);
}
}
}
use of org.wso2.carbon.databridge.commons.Event in project siddhi by wso2.
the class StreamJunction method sendEvent.
public void sendEvent(Event event) {
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
throughputTracker.eventIn();
}
if (isTraceEnabled) {
log.trace(event + " event is received by streamJunction " + this);
}
if (disruptor != null) {
long sequenceNo = ringBuffer.next();
try {
Event existingEvent = ringBuffer.get(sequenceNo);
existingEvent.copyFrom(event);
} finally {
ringBuffer.publish(sequenceNo);
}
} else {
for (Receiver receiver : receivers) {
receiver.receive(event);
}
}
}
use of org.wso2.carbon.databridge.commons.Event in project siddhi by wso2.
the class StreamJunction method sendEvent.
private void sendEvent(Event[] events) {
if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
throughputTracker.eventsIn(events.length);
}
if (isTraceEnabled) {
log.trace("Event is received by streamJunction " + this);
}
if (disruptor != null) {
for (Event event : events) {
// Todo : optimize for arrays
long sequenceNo = ringBuffer.next();
try {
Event existingEvent = ringBuffer.get(sequenceNo);
existingEvent.copyFrom(event);
} finally {
ringBuffer.publish(sequenceNo);
}
}
} else {
for (Receiver receiver : receivers) {
receiver.receive(events);
}
}
}
Aggregations