use of org.wso2.carbon.humantask.core.engine.commands.Remove 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;
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class IndexEventHolder method delete.
@Override
public void delete(String attribute, Compare.Operator operator, Object value) {
if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
switch(operator) {
case LESS_THAN:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case GREATER_THAN:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case LESS_THAN_EQUAL:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case GREATER_THAN_EQUAL:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case EQUAL:
StreamEvent deletedEvent = primaryKeyData.remove(value);
if (deletedEvent != null) {
deleteFromIndexes(deletedEvent);
}
return;
case NOT_EQUAL:
StreamEvent streamEvent = primaryKeyData.get(value);
deleteAll();
if (streamEvent != null) {
add(streamEvent);
}
return;
}
} else {
switch(operator) {
case LESS_THAN:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case GREATER_THAN:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case LESS_THAN_EQUAL:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case GREATER_THAN_EQUAL:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case EQUAL:
Set<StreamEvent> deletedEventSet = indexData.get(attribute).remove(value);
if (deletedEventSet != null && deletedEventSet.size() > 0) {
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
}
return;
case NOT_EQUAL:
Set<StreamEvent> matchingEventSet = indexData.get(attribute).get(value);
deleteAll();
for (StreamEvent matchingEvent : matchingEventSet) {
add(matchingEvent);
}
return;
}
}
throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class FrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEvent != null) {
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
String key = generateKey(streamEvent);
StreamEvent oldEvent = map.put(key, clonedEvent);
if (oldEvent != null) {
countMap.put(key, countMap.get(key) + 1);
streamEventChunk.add(streamEvent);
} else {
// This is a new event
if (map.size() > mostFrequentCount) {
List<String> keys = new ArrayList<String>(countMap.keySet());
for (int i = 0; i < mostFrequentCount; i++) {
int count = countMap.get(keys.get(i)) - 1;
if (count == 0) {
countMap.remove(keys.get(i));
StreamEvent expiredEvent = map.remove(keys.get(i));
expiredEvent.setTimestamp(currentTime);
streamEventChunk.add(expiredEvent);
} else {
countMap.put(keys.get(i), count);
}
}
// now we have tried to remove one for newly added item
if (map.size() > mostFrequentCount) {
// nothing happend by the attempt to remove one from the
// map so we are ignoring this event
map.remove(key);
// Here we do nothing just drop the message
} else {
// we got some space, event is already there in map object
// we just have to add it to the countMap
countMap.put(key, 1);
streamEventChunk.add(streamEvent);
}
} else {
countMap.put(generateKey(streamEvent), 1);
streamEventChunk.add(streamEvent);
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class QuerySelector method processGroupBy.
private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEventChunk<ComplexEvent> currentComplexEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
synchronized (this) {
int limitCount = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
String groupedByKey = groupByKeyGenerator.constructEventKey(event);
GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupedByKey);
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
complexEventChunk.remove();
if (limit == SiddhiConstants.UNKNOWN_STATE) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
} else {
if (limitCount < limit) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
limitCount++;
}
}
}
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
currentComplexEventChunk.reset();
if (currentComplexEventChunk.hasNext()) {
return currentComplexEventChunk;
}
return null;
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class PatternPartitionTestCase method testPatternPartitionQuery7.
@Test
public void testPatternPartitionQuery7() throws InterruptedException {
log.info("Partition - testPatternEvery7 - OUT 2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String partitionStart = "partition with (volume of Stream1,volume of Stream2) begin ";
String query = "" + "@info(name = 'query1') " + "from every ( e1=Stream1[price>20] -> e3=Stream1[price>20]) " + "select e1.price as price1, e3.price as price3 " + "insert into OutputStream ;";
String partitionEnd = "end";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd);
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
if (event.isExpired()) {
removeEventCount.incrementAndGet();
} else {
inEventCount.incrementAndGet();
switch(inEventCount.get()) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, 57.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { 54f, 53.6f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount.get());
}
}
eventArrived = true;
}
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
siddhiAppRuntime.start();
stream1.send(new Object[] { "MSFT", 55.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 54f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "WSO2", 53.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount.get());
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations