use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(Event event, boolean endOfBatch) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertEvent(event, borrowedEvent);
streamEventChunk.add(borrowedEvent);
if (endOfBatch) {
ComplexEvent complexEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
receive(complexEvent);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(long timestamp, Object[] data) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertData(timestamp, data, borrowedEvent);
if (partitionExecutors.size() == 0) {
send(borrowedEvent);
} else {
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(borrowedEvent);
send(key, borrowedEvent);
}
}
eventPool.returnEvents(borrowedEvent);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(ComplexEvent complexEvent) {
if (partitionExecutors.size() == 0) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
send(borrowedEvent);
} else {
if (complexEvent.getNext() == null) {
for (PartitionExecutor partitionExecutor : partitionExecutors) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
String key = partitionExecutor.execute(borrowedEvent);
send(key, borrowedEvent);
}
} else {
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<ComplexEvent>(false);
complexEventChunk.add(complexEvent);
String currentKey = null;
while (complexEventChunk.hasNext()) {
ComplexEvent aEvent = complexEventChunk.next();
complexEventChunk.remove();
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(aEvent, borrowedEvent);
boolean currentEventMatchedPrevPartitionExecutor = false;
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(borrowedEvent);
if (key != null) {
if (currentKey == null) {
currentKey = key;
} else if (!currentKey.equals(key)) {
if (!currentEventMatchedPrevPartitionExecutor) {
ComplexEvent firstEvent = streamEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
streamEventChunk.clear();
} else {
ComplexEvent firstEvent = streamEventChunk.getFirst();
send(currentKey, firstEvent);
currentKey = key;
streamEventChunk.clear();
StreamEvent cloneEvent = eventPool.borrowEvent();
streamEventConverter.convertComplexEvent(aEvent, cloneEvent);
streamEventChunk.add(cloneEvent);
}
}
if (!currentEventMatchedPrevPartitionExecutor) {
streamEventChunk.add(borrowedEvent);
}
currentEventMatchedPrevPartitionExecutor = true;
}
}
}
send(currentKey, streamEventChunk.getFirst());
streamEventChunk.clear();
}
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class PartitionStreamReceiver method receive.
@Override
public void receive(Event event) {
StreamEvent borrowedEvent = eventPool.borrowEvent();
streamEventConverter.convertEvent(event, borrowedEvent);
for (PartitionExecutor partitionExecutor : partitionExecutors) {
String key = partitionExecutor.execute(borrowedEvent);
send(key, borrowedEvent);
}
if (partitionExecutors.size() == 0) {
send(borrowedEvent);
}
eventPool.returnEvents(borrowedEvent);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class AbsentLogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>(false);
if (!this.active) {
return returnEventChunk;
}
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
this.lock.lock();
try {
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (withinStates.size() > 0) {
if (isExpired(stateEvent, streamEvent.getTimestamp())) {
iterator.remove();
continue;
}
}
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePerProcessor != null)) {
// Reset to the original state after processing
stateEvent.setEvent(stateId, currentStreamEvent);
}
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
// The event has passed the filter condition. So remove from being an absent candidate.
iterator.remove();
if (stateType == StateInputStream.Type.SEQUENCE) {
partnerStatePreProcessor.pendingStateEventList.remove(stateEvent);
}
}
if (!stateChanged) {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, currentStreamEvent);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, currentStreamEvent);
iterator.remove();
break;
}
}
}
} finally {
this.lock.unlock();
}
return returnEventChunk;
}
Aggregations