View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  
17  package net.sf.ehcache;
18  
19  /***
20   * Default implementation of the element eviction data storage that just keeps
21   * all the data in instance fields in the heap.
22   * 
23   * @author Geert Bevin
24   * @version $Id: DefaultElementEvictionData.java 1219 2009-09-25 05:10:31Z
25   *          gbevin $
26   */
27  public class DefaultElementEvictionData implements ElementEvictionData {
28  
29      /***
30       * The creation time.
31       */
32      private long creationTime;
33      
34      /***
35       * The last access time.
36       */
37      private long lastAccessTime;
38  
39      /***
40       * Default constructor initializing the field to their empty values
41       */
42      public DefaultElementEvictionData(long creationTime) {
43          this.creationTime = creationTime;
44      }
45      
46      /***
47       * Constructor allowing custom values for the data fields.
48       * 
49       * @param lastAccessTime
50       */
51      public DefaultElementEvictionData(long creationTime, long lastAccessTime) {
52          this.creationTime = creationTime;
53          this.lastAccessTime = lastAccessTime;
54      }
55  
56      /***
57       * {@inheritDoc}
58       */
59      public void setCreationTime(long creationTime) {
60          this.creationTime = creationTime;        
61      }
62  
63      /***
64       * {@inheritDoc}
65       */
66      public long getCreationTime() {
67          return creationTime;        
68      }
69  
70      /***
71       * {@inheritDoc}
72       */
73      public long getLastAccessTime() {
74          return lastAccessTime;        
75      }
76  
77      /***
78       * {@inheritDoc}
79       */
80      public void updateLastAccessTime(long time, Element element) {
81          lastAccessTime = time;
82      }
83  
84      /***
85       * {@inheritDoc}
86       */
87      public void resetLastAccessTime(Element element) {
88          lastAccessTime = System.currentTimeMillis();
89      }
90  
91      /***
92       * {@inheritDoc}
93       */
94      @Override
95      public final ElementEvictionData clone() throws CloneNotSupportedException {
96          DefaultElementEvictionData result = (DefaultElementEvictionData)super.clone();
97          result.creationTime = this.creationTime;
98          result.lastAccessTime = this.lastAccessTime;
99          return result;
100     }
101 
102      /***
103       * {@inheritDoc}
104       */
105     public boolean canParticipateInSerialization() {
106         return true;
107     }
108 }