/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.cache.eviction;

import org.jboss.cache.Fqn;
import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.eviction.LRUPolicy;
import org.jboss.cache.eviction.Region;
import org.jboss.logging.Logger;

/**
 * Eviction policy based on the FIFO algorithm where users can specify the max
 * number of nodes and time-to-live for the nodes.
 * 
 * @author Morten Kvistgaard 2004-10
 */
public class FIFOPolicy extends LRUPolicy {

    public FIFOPolicy() {
        super();
        log_ = Logger.getLogger(FIFOPolicy.class);
    }
    
	protected EvictionAlgorithm getEvictionAlgorithm() {
        return new FIFOAlgorithm();
	}
    
	/* 
	 * @see org.jboss.cache..eviction.LRUPolicy#nodeModified(...)
	 */
	public void nodeModified(Fqn fqn) {
		if(log_.isTraceEnabled()) {
			log_.trace("nodeModified(): fqn- " +fqn);
		}
		Region region = regionManager_.getRegion(fqn.toString());
		// TODO May need to optimize to check if this fqn is already on the queue. No need to process it twice.
		region.setVisitedNode(fqn);
	}
    
	public void nodeVisited(Fqn fqn) {
        // visiting a node will not extend it's lifetime
        if(log_.isDebugEnabled()) {
            log_.debug("nodeVisited(): fqn- " +fqn);
        }
	}
}
