1 package org.apache.commons.jcs3.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.jcs3.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 0 by default 64 * and is only updated when the element is serialized. 65 * <p> 66 * @param size The new size value 67 */ 68 void setSize( int size ); 69 70 /** 71 * Gets the size attribute of the IAttributes object 72 * <p> 73 * @return The size value 74 */ 75 int getSize(); 76 77 /** 78 * Gets the createTime attribute of the IAttributes object. 79 * <p> 80 * This should be the current time in milliseconds returned by the sysutem call when the element 81 * is put in the cache. 82 * <p> 83 * Putting an item in the cache overrides any existing items. 84 * @return The createTime value 85 */ 86 long getCreateTime(); 87 88 /** 89 * Gets the LastAccess attribute of the IAttributes object. 90 * <p> 91 * @return The LastAccess value. 92 */ 93 long getLastAccessTime(); 94 95 /** 96 * Sets the LastAccessTime as now of the IElementAttributes object 97 */ 98 void setLastAccessTimeNow(); 99 100 /** 101 * Gets the idleTime attribute of the IAttributes object 102 * @return The idleTime value 103 */ 104 long getIdleTime(); 105 106 /** 107 * Gets the time left to live of the IAttributes object. 108 * <p> 109 * This is the (max life + create time) - current time. 110 * @return The TimeToLiveSeconds value 111 */ 112 long getTimeToLiveSeconds(); 113 114 /** 115 * Can this item be spooled to disk 116 * <p> 117 * By default this is true. 118 * @return The spoolable value 119 */ 120 boolean getIsSpool(); 121 122 /** 123 * Sets the isSpool attribute of the IElementAttributes object 124 * <p> 125 * By default this is true. 126 * @param val The new isSpool value 127 */ 128 void setIsSpool( boolean val ); 129 130 /** 131 * Is this item laterally distributable. Can it be sent to auxiliaries of type lateral. 132 * <p> 133 * By default this is true. 134 * @return The isLateral value 135 */ 136 boolean getIsLateral(); 137 138 /** 139 * Sets the isLateral attribute of the IElementAttributes object 140 * <p> 141 * By default this is true. 142 * @param val The new isLateral value 143 */ 144 void setIsLateral( boolean val ); 145 146 /** 147 * Can this item be sent to the remote cache. 148 * <p> 149 * By default this is true. 150 * @return The isRemote value 151 */ 152 boolean getIsRemote(); 153 154 /** 155 * Sets the isRemote attribute of the IElementAttributes object. 156 * <p> 157 * By default this is true. 158 * @param val The new isRemote value 159 */ 160 void setIsRemote( boolean val ); 161 162 /** 163 * This turns off expiration if it is true. 164 * @return The IsEternal value 165 */ 166 boolean getIsEternal(); 167 168 /** 169 * Sets the isEternal attribute of the IElementAttributes object 170 * @param val The new isEternal value 171 */ 172 void setIsEternal( boolean val ); 173 174 /** 175 * Adds a ElementEventHandler. Handler's can be registered for multiple events. A registered 176 * handler will be called at every recognized event. 177 * @param eventHandler The feature to be added to the ElementEventHandler 178 */ 179 void addElementEventHandler( IElementEventHandler eventHandler ); 180 181 /** 182 * Gets the elementEventHandlers. 183 * <p> 184 * Event handlers are transient. The only events defined are in memory events. All handlers are 185 * lost if the item goes to disk. 186 * @return The elementEventHandlers value, null if there are none 187 */ 188 ArrayList<IElementEventHandler> getElementEventHandlers(); 189 190 /** 191 * Sets the eventHandlers of the IElementAttributes object 192 * @param eventHandlers value 193 */ 194 void addElementEventHandlers( List<IElementEventHandler> eventHandlers ); 195 196 long getTimeFactorForMilliseconds(); 197 198 void setTimeFactorForMilliseconds(long factor); 199 200 /** 201 * Clone object 202 */ 203 IElementAttributes clone(); 204 }