Search in sources :

Example 6 with IndexEventHolder

use of io.siddhi.core.table.holder.IndexEventHolder in project siddhi by wso2.

the class CacheTableFIFO method deleteEntriesUsingCachePolicy.

@Override
public void deleteEntriesUsingCachePolicy(int numRowsToDelete) {
    IndexEventHolder indexEventHolder = (IndexEventHolder) stateHolder.getState().getEventHolder();
    if (numRowsToDelete >= indexEventHolder.size()) {
        indexEventHolder.deleteAll();
    } else {
        Set<Object> keys = indexEventHolder.getAllPrimaryKeyValues();
        TreeMap<Long, Object> toDelete = new TreeMap<>();
        for (Object key : keys) {
            if (toDelete.size() < numRowsToDelete) {
                toDelete.put((Long) indexEventHolder.getEvent(key).getOutputData()[cachePolicyAttributePosition], key);
            } else {
                Long timestamp = (Long) indexEventHolder.getEvent(key).getOutputData()[cachePolicyAttributePosition];
                Long firstKey = toDelete.firstKey();
                if (timestamp < firstKey) {
                    toDelete.remove(firstKey);
                    toDelete.put(timestamp, key);
                }
            }
        }
        for (Object deleteKey : toDelete.values()) {
            if (deleteKey != null) {
                indexEventHolder.deleteEvent(deleteKey);
            }
        }
    }
}
Also used : IndexEventHolder(io.siddhi.core.table.holder.IndexEventHolder) TreeMap(java.util.TreeMap)

Example 7 with IndexEventHolder

use of io.siddhi.core.table.holder.IndexEventHolder in project siddhi by wso2.

the class CacheTableLRU method deleteEntriesUsingCachePolicy.

@Override
public void deleteEntriesUsingCachePolicy(int numRowsToDelete) {
    IndexEventHolder indexEventHolder = (IndexEventHolder) stateHolder.getState().getEventHolder();
    if (numRowsToDelete >= indexEventHolder.size()) {
        indexEventHolder.deleteAll();
    } else {
        Set<Object> keys = indexEventHolder.getAllPrimaryKeyValues();
        TreeMap<Long, Object> toDelete = new TreeMap<>();
        for (Object key : keys) {
            if (toDelete.size() < numRowsToDelete) {
                toDelete.put((Long) indexEventHolder.getEvent(key).getOutputData()[cachePolicyAttributePosition], key);
            } else {
                Long timestamp = (Long) indexEventHolder.getEvent(key).getOutputData()[cachePolicyAttributePosition];
                Long firstKey = toDelete.firstKey();
                if (timestamp < firstKey) {
                    toDelete.remove(firstKey);
                    toDelete.put(timestamp, key);
                }
            }
        }
        for (Object deleteKey : toDelete.values()) {
            if (deleteKey != null) {
                indexEventHolder.deleteEvent(deleteKey);
            }
        }
    }
}
Also used : IndexEventHolder(io.siddhi.core.table.holder.IndexEventHolder) TreeMap(java.util.TreeMap)

Aggregations

IndexEventHolder (io.siddhi.core.table.holder.IndexEventHolder)7 TreeMap (java.util.TreeMap)3 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)1 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 ZeroStreamEventConverter (io.siddhi.core.event.stream.converter.ZeroStreamEventConverter)1 StreamEventClonerHolder (io.siddhi.core.event.stream.holder.StreamEventClonerHolder)1 OperationNotSupportedException (io.siddhi.core.exception.OperationNotSupportedException)1 EventHolder (io.siddhi.core.table.holder.EventHolder)1 IndexEventHolderForCache (io.siddhi.core.table.holder.IndexEventHolderForCache)1 ListEventHolder (io.siddhi.core.table.holder.ListEventHolder)1 PrimaryKeyReferenceHolder (io.siddhi.core.table.holder.PrimaryKeyReferenceHolder)1 SiddhiConstants (io.siddhi.core.util.SiddhiConstants)1 Annotation (io.siddhi.query.api.annotation.Annotation)1 Element (io.siddhi.query.api.annotation.Element)1 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)1 Attribute (io.siddhi.query.api.definition.Attribute)1 SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)1 AnnotationHelper (io.siddhi.query.api.util.AnnotationHelper)1