1 package org.apache.commons.jcs.engine.behavior;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
27
28 /**
29 * Interface for cache element attributes classes. Every item is the cache is associated with an
30 * element attributes object. It is used to track the life of the object as well as to restrict its
31 * behavior. By default, elements get a clone of the region's attributes.
32 */
33 public interface IElementAttributes extends Serializable, Cloneable
34 {
35 /**
36 * Sets the maxLife attribute of the IAttributes object.
37 * <p>
38 * @param mls The new MaxLifeSeconds value
39 */
40 void setMaxLife(long mls);
41
42 /**
43 * Sets the maxLife attribute of the IAttributes object. How many seconds it can live after
44 * creation.
45 * <p>
46 * If this is exceeded the element will not be returned, instead it will be removed. It will be
47 * removed on retrieval, or removed actively if the memory shrinker is turned on.
48 * @return The MaxLifeSeconds value
49 */
50 long getMaxLife();
51
52 /**
53 * Sets the idleTime attribute of the IAttributes object. This is the maximum time the item can
54 * be idle in the cache, that is not accessed.
55 * <p>
56 * If this is exceeded the element will not be returned, instead it will be removed. It will be
57 * removed on retrieval, or removed actively if the memory shrinker is turned on.
58 * @param idle The new idleTime value
59 */
60 void setIdleTime( long idle );
61
62 /**
63 * Size in bytes. This is not used except in the admin pages. It will be -1 by default.
64 * <p>
65 * @param size The new size value
66 */
67 void setSize( int size );
68
69 /**
70 * Gets the size attribute of the IAttributes object
71 * <p>
72 * @return The size value
73 */
74 int getSize();
75
76 /**
77 * Gets the createTime attribute of the IAttributes object.
78 * <p>
79 * This should be the current time in milliseconds returned by the sysutem call when the element
80 * is put in the cache.
81 * <p>
82 * Putting an item in the cache overrides any existing items.
83 * @return The createTime value
84 */
85 long getCreateTime();
86
87 /**
88 * Gets the LastAccess attribute of the IAttributes object.
89 * <p>
90 * @return The LastAccess value.
91 */
92 long getLastAccessTime();
93
94 /**
95 * Sets the LastAccessTime as now of the IElementAttributes object
96 */
97 void setLastAccessTimeNow();
98
99 /**
100 * Gets the idleTime attribute of the IAttributes object
101 * @return The idleTime value
102 */
103 long getIdleTime();
104
105 /**
106 * Gets the time left to live of the IAttributes object.
107 * <p>
108 * This is the (max life + create time) - current time.
109 * @return The TimeToLiveSeconds value
110 */
111 long getTimeToLiveSeconds();
112
113 /**
114 * Can this item be spooled to disk
115 * <p>
116 * By default this is true.
117 * @return The spoolable value
118 */
119 boolean getIsSpool();
120
121 /**
122 * Sets the isSpool attribute of the IElementAttributes object
123 * <p>
124 * By default this is true.
125 * @param val The new isSpool value
126 */
127 void setIsSpool( boolean val );
128
129 /**
130 * Is this item laterally distributable. Can it be sent to auxiliaries of type lateral.
131 * <p>
132 * By default this is true.
133 * @return The isLateral value
134 */
135 boolean getIsLateral();
136
137 /**
138 * Sets the isLateral attribute of the IElementAttributes object
139 * <p>
140 * By default this is true.
141 * @param val The new isLateral value
142 */
143 void setIsLateral( boolean val );
144
145 /**
146 * Can this item be sent to the remote cache.
147 * <p>
148 * By default this is true.
149 * @return The isRemote value
150 */
151 boolean getIsRemote();
152
153 /**
154 * Sets the isRemote attribute of the IElementAttributes object.
155 * <p>
156 * By default this is true.
157 * @param val The new isRemote value
158 */
159 void setIsRemote( boolean val );
160
161 /**
162 * This turns off expiration if it is true.
163 * @return The IsEternal value
164 */
165 boolean getIsEternal();
166
167 /**
168 * Sets the isEternal attribute of the IElementAttributes object
169 * @param val The new isEternal value
170 */
171 void setIsEternal( boolean val );
172
173 /**
174 * Adds a ElementEventHandler. Handler's can be registered for multiple events. A registered
175 * handler will be called at every recognized event.
176 * @param eventHandler The feature to be added to the ElementEventHandler
177 */
178 void addElementEventHandler( IElementEventHandler eventHandler );
179
180 /**
181 * Gets the elementEventHandlers.
182 * <p>
183 * Event handlers are transient. The only events defined are in memory events. All handlers are
184 * lost if the item goes to disk.
185 * @return The elementEventHandlers value, null if there are none
186 */
187 ArrayList<IElementEventHandler> getElementEventHandlers();
188
189 /**
190 * Sets the eventHandlers of the IElementAttributes object
191 * @param eventHandlers value
192 */
193 void addElementEventHandlers( List<IElementEventHandler> eventHandlers );
194
195 long getTimeFactorForMilliseconds();
196
197 void setTimeFactorForMilliseconds(long factor);
198
199 /**
200 * Clone object
201 */
202 IElementAttributes clone();
203 }