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);
}
}
}
}
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);
}
}
}
}
Aggregations