
io.siddhi.core.table.CacheTableLFU Maven / Gradle / Ivy
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.siddhi.core.table;
import io.siddhi.core.config.SiddhiAppContext;
import io.siddhi.core.event.ComplexEvent;
import io.siddhi.core.event.stream.StreamEvent;
import io.siddhi.core.table.holder.IndexEventHolder;
import io.siddhi.query.api.definition.Attribute;
import io.siddhi.query.api.definition.TableDefinition;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Set;
import java.util.TreeMap;
import static io.siddhi.core.util.SiddhiConstants.CACHE_TABLE_COUNT_LFU;
import static io.siddhi.core.util.SiddhiConstants.CACHE_TABLE_TIMESTAMP_ADDED;
/**
* cache table with FIFO entry removal
*/
public class CacheTableLFU extends CacheTable {
private static final Logger log = LogManager.getLogger(CacheTableLFU.class);
private int cachePolicyAttributePosition;
private int numColumns;
private int expiryAttributePosition;
@Override
void addRequiredFieldsToCacheTableDefinition(TableDefinition cacheTableDefinition, boolean cacheExpiryEnabled) {
if (cacheExpiryEnabled) {
cacheTableDefinition.attribute(CACHE_TABLE_TIMESTAMP_ADDED, Attribute.Type.LONG);
cacheTableDefinition.attribute(CACHE_TABLE_COUNT_LFU, Attribute.Type.INT);
expiryAttributePosition = cacheTableDefinition.getAttributeList().size() - 2;
} else {
cacheTableDefinition.attribute(CACHE_TABLE_COUNT_LFU, Attribute.Type.INT);
}
cachePolicyAttributePosition = cacheTableDefinition.getAttributeList().size() - 1;
numColumns = cachePolicyAttributePosition + 1;
}
@Override
public void deleteOneEntryUsingCachePolicy() {
IndexEventHolder indexEventHolder = (IndexEventHolder) stateHolder.getState().getEventHolder();
Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy