/* $Id: BaseDescription.java 988245 2010-08-23 18:39:35Z kwright $ */

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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 org.apache.manifoldcf.core.cachemanager;

import org.apache.manifoldcf.core.interfaces.*;
import java.util.*;

/** This is the base class for cache object descriptions.
* The base class sets up LRU behavior based on parameters
* in a configuration file, and also bases expiration on the
* same class picture.
*/
public abstract class BaseDescription implements ICacheDescription
{
  public static final String _rcsid = "@(#)$Id: BaseDescription.java 988245 2010-08-23 18:39:35Z kwright $";

  protected ICacheClass cacheClass = null;

  protected final static Integer max_value = new Integer(Integer.MAX_VALUE);

  public BaseDescription(String objectClassName)
  {
    if (objectClassName != null)
      cacheClass = new LocalCacheClass(objectClassName);
  }

  public BaseDescription(String objectClassName, int maxLRUCount)
  {
    if (objectClassName != null)
      cacheClass = new LocalCacheClass(objectClassName,maxLRUCount);
  }

  /** Get the object class for an object.  The object class is used to determine
  * the group of objects treated in the same LRU manner.
  * @return the newly created object's object class, or null if there is no
  * such class, and LRU behavior is not desired.
  */
  public ICacheClass getObjectClass()
  {
    return cacheClass;
  }

  /** Obtain an expiration time for an object, in milliseconds since epoch.
  * The cache manager will call this method for all objects that are being operated on,
  * so that their expiration timestamps get properly updated to a new time.
  * @return a time in milliseconds for the object to expire, or -1 if there is no expiration
  * desired.
  */
  public long getObjectExpirationTime(long currentTime)
  {
    return -1;
  }

  /** This is a cache class implementation that gets expiration and LRU info
  * from .ini variables.
  */
  protected class LocalCacheClass implements ICacheClass
  {
    protected String objectClassName;
    protected Integer maxLRUCount = null;

    public LocalCacheClass(String objectClassName)
    {
      this(objectClassName,-1);
    }
    
    public LocalCacheClass(String objectClassName, int maxLRUCount)
    {
      this.objectClassName = objectClassName;
      if (maxLRUCount != -1)
        this.maxLRUCount = new Integer(maxLRUCount);
    }

    /** Get the name of the object class.
    * This determines the set of objects that are treated in the same
    * LRU pool.
    *@return the class name.
    */
    public String getClassName()
    {
      return objectClassName;
    }

    /** Get the maximum LRU count of the object class.
    *@return the maximum number of the objects of the particular class
    * allowed.
    */
    public int getMaxLRUCount()
    {
      if (maxLRUCount == null)
      {
        try
        {
          String x = null; // JSKW.getProperty("cache."+objectClassName+".lrusize");
          if (x == null)
            maxLRUCount = max_value;
          else
            maxLRUCount = new Integer(x);
        }
        catch (Exception e)
        {
          maxLRUCount = max_value;
        }
      }
      return maxLRUCount.intValue();
    }
  }
}

@@ -1418,40 +1418,24 @@
 tic 
-Integer max_value = new Integer(
+int MAX_VALUE = 
 Inte
@@ -1447,17 +1447,16 @@
 AX_VALUE
-)
 ;%0A%0A  pub
@@ -1598,16 +1598,250 @@
 );%0A  %7D%0A%0A
+  public BaseDescription(String objectClassName, IThreadContext threadContext)%0A    throws ManifoldCFException%0A  %7B%0A    if (objectClassName != null) %7B%0A      cacheClass = new LocalCacheClass(objectClassName, threadContext);%0A    %7D%0A  %7D%0A  %0A
   public
@@ -1990,16 +1990,17 @@
 assName,
+ 
 maxLRUCo
@@ -3081,113 +3081,400 @@
 Name
-)%0A    %7B%0A      this(objectClassName,-1);%0A    %7D%0A    %0A    public LocalCacheClass(String objectClassName, int
+, IThreadContext threadContext)%0A      throws ManifoldCFException%0A    %7B%0A      this(objectClassName, new Integer(LockManagerFactory.getIntProperty(threadContext, %22cache.%22+objectClassName+%22.lrusize%22, MAX_VALUE)));%0A    %7D%0A    %0A    public LocalCacheClass(String objectClassName)%0A    %7B%0A      this(objectClassName, (Integer)null);%0A    %7D%0A    %0A    public LocalCacheClass(String objectClassName, Integer
  max
@@ -3539,39 +3539,8 @@
 me;%0A
-      if (maxLRUCount != -1)%0A  
     
@@ -3560,28 +3560,16 @@
 Count = 
-new Integer(
 maxLRUCo
@@ -3567,25 +3567,24 @@
  maxLRUCount
-)
 ;%0A    %7D%0A%0A   
@@ -3736,32 +3736,46 @@
 ss name.%0A    */%0A
+    @Override%0A
     public Strin
@@ -3978,24 +3978,38 @@
 wed.%0A    */%0A
+    @Override%0A
     public i
@@ -4085,318 +4085,25 @@
     
-try%0A        %7B%0A          String x = null; // JSKW.getProperty(%22cache.%22+objectClassName+%22.lrusize%22);%0A          if (x == null)%0A            maxLRUCount = max_value;%0A          else%0A            maxLRUCount = new Integer(x);%0A        %7D%0A        catch (Exception e)%0A        %7B%0A          maxLRUCount = max_value;%0A        %7D
+return MAX_VALUE;
 %0A   
@@ -4135,19 +4135,8 @@
 ount
-.intValue()
 ;%0A  

Improve caching infrastructure to allow BaseDescription property control of maximum LRU size