View Javadoc

1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.util;
17  
18  import org.apache.commons.collections.map.LRUMap;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.kns.service.impl.SessionDocumentServiceImpl;
21  
22  /**
23   * Override LRUMap removeEntity method
24   * 
25   * 
26   */
27  public class KualiLRUMap extends LRUMap {
28  
29  	/** Serialization version */
30  	private static final long serialVersionUID = 1L;
31  
32  	public KualiLRUMap() {
33  		super();
34  	}
35  
36  	public KualiLRUMap(int maxSize) {
37  		super(maxSize);
38  	}
39  
40  	protected void removeEntry(HashEntry entry, int hashIndex, HashEntry previous) {
41  
42  		// It is for session document cache enhancement.
43  		// To control the size of cache. When the LRUMap reach the maxsize.
44  		// It will remove session document entries from the in-memory user
45  		// session objects.
46  		try {
47  			SessionDocumentServiceImpl.CachedObject cachedObject 
48  					= (SessionDocumentServiceImpl.CachedObject)this.entryValue(entry);
49  			cachedObject.getUserSession().removeObject(cachedObject.getFormKey());
50  		} catch (Exception ex) {
51  			Logger.getLogger(getClass()).warn( "Problem purging old entry from the user session when removing from the map: ", ex);
52  		}
53  
54  		super.removeEntry(entry, hashIndex, previous);
55  	}
56  
57  }