001package org.apache.commons.jcs.engine.behavior; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.Serializable; 023import java.util.ArrayList; 024import java.util.List; 025 026import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler; 027 028/** 029 * Interface for cache element attributes classes. Every item is the cache is associated with an 030 * element attributes object. It is used to track the life of the object as well as to restrict its 031 * behavior. By default, elements get a clone of the region's attributes. 032 */ 033public interface IElementAttributes extends Serializable, Cloneable 034{ 035 /** 036 * Sets the maxLife attribute of the IAttributes object. 037 * <p> 038 * @param mls The new MaxLifeSeconds value 039 */ 040 void setMaxLife(long mls); 041 042 /** 043 * Sets the maxLife attribute of the IAttributes object. How many seconds it can live after 044 * creation. 045 * <p> 046 * If this is exceeded the element will not be returned, instead it will be removed. It will be 047 * removed on retrieval, or removed actively if the memory shrinker is turned on. 048 * @return The MaxLifeSeconds value 049 */ 050 long getMaxLife(); 051 052 /** 053 * Sets the idleTime attribute of the IAttributes object. This is the maximum time the item can 054 * be idle in the cache, that is not accessed. 055 * <p> 056 * If this is exceeded the element will not be returned, instead it will be removed. It will be 057 * removed on retrieval, or removed actively if the memory shrinker is turned on. 058 * @param idle The new idleTime value 059 */ 060 void setIdleTime( long idle ); 061 062 /** 063 * Size in bytes. This is not used except in the admin pages. It will be -1 by default. 064 * <p> 065 * @param size The new size value 066 */ 067 void setSize( int size ); 068 069 /** 070 * Gets the size attribute of the IAttributes object 071 * <p> 072 * @return The size value 073 */ 074 int getSize(); 075 076 /** 077 * Gets the createTime attribute of the IAttributes object. 078 * <p> 079 * This should be the current time in milliseconds returned by the sysutem call when the element 080 * is put in the cache. 081 * <p> 082 * Putting an item in the cache overrides any existing items. 083 * @return The createTime value 084 */ 085 long getCreateTime(); 086 087 /** 088 * Gets the LastAccess attribute of the IAttributes object. 089 * <p> 090 * @return The LastAccess value. 091 */ 092 long getLastAccessTime(); 093 094 /** 095 * Sets the LastAccessTime as now of the IElementAttributes object 096 */ 097 void setLastAccessTimeNow(); 098 099 /** 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}