org.apache.jcs.engine
Class ElementAttributes

java.lang.Object
  extended by org.apache.jcs.engine.ElementAttributes
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, IElementAttributes

public class ElementAttributes
extends java.lang.Object
implements IElementAttributes, java.io.Serializable, java.lang.Cloneable

This it the element attribute descriptor class. Each element in the cache has an ElementAttribute object associated with it. An ElementAttributes object can be associated with an element in 3 ways:

  1. When the item is put into the cache, you can associate an element attributes object.
  2. If not attributes object is include when the element is put into the cache, then the default attributes for the region will be used.
  3. The element attributes can be reset. This effectively results in a retrieval followed by a put. Hence, this is the same as 1.

See Also:
Serialized Form

Field Summary
 long createTime
          The creation time.
 java.util.ArrayList eventHandlers
          The list of Event handlers to use.
 boolean IS_ETERNAL
          You can turn off expiration by setting this to true.
 boolean IS_LATERAL
          Is this item laterally distributable
 boolean IS_REMOTE
          Can this item be sent to the remote cache
 boolean IS_SPOOL
          Can this item be flushed to disk
 long lastAccessTime
          The last access time.
 long maxIdleTimeSeconds
          The maximum time an entry can be idle.
 long maxLifeSeconds
          Max life seconds
 int size
          The byte size of the field.
 
Constructor Summary
  ElementAttributes()
          Constructor for the IElementAttributes object
protected ElementAttributes(ElementAttributes attr)
          Constructor for the IElementAttributes object
 
Method Summary
 void addElementEventHandler(IElementEventHandler eventHandler)
          Adds a ElementEventHandler.
 void addElementEventHandlers(java.util.ArrayList eventHandlers)
          Sets the eventHandlers of the IElementAttributes object.
 java.lang.Object clone2()
          Deep clone the attributes.
 IElementAttributes copy()
          Copies the attributes, including references to event handlers.
 long getCreateTime()
          Gets the createTime attribute of the IAttributes object.
 java.util.ArrayList getElementEventHandlers()
          Gets the elementEventHandlers.
 long getIdleTime()
          Gets the idleTime attribute of the IAttributes object.
 boolean getIsEternal()
          You can turn off expiration by setting this to true.
 boolean getIsLateral()
          Is this item laterally distributable.
 boolean getIsRemote()
          Can this item be sent to the remote cache
 boolean getIsSpool()
          Can this item be spooled to disk
 long getLastAccessTime()
          Gets the LastAccess attribute of the IAttributes object.
 long getMaxLifeSeconds()
          Sets the maxLife attribute of the IAttributes object.
 int getSize()
          Gets the size attribute of the IAttributes object
 long getTimeToLiveSeconds()
          Gets the time left to live of the IAttributes object.
 void setCreateTime()
          Sets the createTime attribute of the IElementAttributes object
 void setIdleTime(long idle)
          Sets the idleTime attribute of the IAttributes object.
 void setIsEternal(boolean val)
          Sets the isEternal attribute of the ElementAttributes object.
 void setIsLateral(boolean val)
          Sets the isLateral attribute of the IElementAttributes object
 void setIsRemote(boolean val)
          Sets the isRemote attribute of the ElementAttributes object
 void setIsSpool(boolean val)
          Sets the isSpool attribute of the IElementAttributes object
 void setLastAccessTimeNow()
          Sets the LastAccessTime as now of the IElementAttributes object
 void setMaxLifeSeconds(long mls)
          Sets the maxLife attribute of the IAttributes object.
 void setSize(int size)
          Size in bytes.
 java.lang.String toString()
          For logging and debugging the element IElementAttributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IS_SPOOL

public boolean IS_SPOOL
Can this item be flushed to disk


IS_LATERAL

public boolean IS_LATERAL
Is this item laterally distributable


IS_REMOTE

public boolean IS_REMOTE
Can this item be sent to the remote cache


IS_ETERNAL

public boolean IS_ETERNAL
You can turn off expiration by setting this to true. This causes the cache to bypass both max life and idle time expiration.


maxLifeSeconds

public long maxLifeSeconds
Max life seconds


maxIdleTimeSeconds

public long maxIdleTimeSeconds
The maximum time an entry can be idle. Setting this to -1 causes the idle time check to be ignored.


size

public int size
The byte size of the field. Must be manually set.


createTime

public long createTime
The creation time. This is used to enforce the max life.


lastAccessTime

public long lastAccessTime
The last access time. This is used to enforce the max idel time.


eventHandlers

public transient java.util.ArrayList eventHandlers
The list of Event handlers to use. This is transient, since the event handlers cannot usually be serialized. This means that you cannot attach a post serialization event to an item.

TODO we need to check that when an item is passed to a non-local cache that if the local cache had a copy with event handlers, that those handlers are used.

Constructor Detail

ElementAttributes

public ElementAttributes()
Constructor for the IElementAttributes object


ElementAttributes

protected ElementAttributes(ElementAttributes attr)
Constructor for the IElementAttributes object

Parameters:
attr -
Method Detail

copy

public IElementAttributes copy()
Copies the attributes, including references to event handlers.

Specified by:
copy in interface IElementAttributes
Returns:
a copy of the Attributes

clone2

public java.lang.Object clone2()
Deep clone the attributes.

Returns:
a clone of these attributes

setMaxLifeSeconds

public void setMaxLifeSeconds(long mls)
Sets the maxLife attribute of the IAttributes object.

Specified by:
setMaxLifeSeconds in interface IElementAttributes
Parameters:
mls - The new MaxLifeSeconds value

getMaxLifeSeconds

public long getMaxLifeSeconds()
Sets the maxLife attribute of the IAttributes object. How many seconds it can live after creation.

If this is exceeded the element will not be returned, instead it will be removed. It will be removed on retrieval, or removed actively if the memory shrinker is turned on.

Specified by:
getMaxLifeSeconds in interface IElementAttributes
Returns:
The MaxLifeSeconds value

setIdleTime

public void setIdleTime(long idle)
Sets the idleTime attribute of the IAttributes object. This is the maximum time the item can be idle in the cache, that is not accessed.

If this is exceeded the element will not be returned, instead it will be removed. It will be removed on retrieval, or removed actively if the memory shrinker is turned on.

Specified by:
setIdleTime in interface IElementAttributes
Parameters:
idle - The new idleTime value

setSize

public void setSize(int size)
Size in bytes. This is not used except in the admin pages. It will be -1 by default.

Specified by:
setSize in interface IElementAttributes
Parameters:
size - The new size value

getSize

public int getSize()
Gets the size attribute of the IAttributes object

Specified by:
getSize in interface IElementAttributes
Returns:
The size value

getCreateTime

public long getCreateTime()
Gets the createTime attribute of the IAttributes object.

This should be the current time in milliseconds returned by the sysutem call when the element is put in the cache.

Putting an item in the cache overrides any existing items.

Specified by:
getCreateTime in interface IElementAttributes
Returns:
The createTime value

setCreateTime

public void setCreateTime()
Sets the createTime attribute of the IElementAttributes object


getIdleTime

public long getIdleTime()
Gets the idleTime attribute of the IAttributes object.

Specified by:
getIdleTime in interface IElementAttributes
Returns:
The idleTime value

getTimeToLiveSeconds

public long getTimeToLiveSeconds()
Gets the time left to live of the IAttributes object.

This is the (max life + create time) - current time.

Specified by:
getTimeToLiveSeconds in interface IElementAttributes
Returns:
The TimeToLiveSeconds value

getLastAccessTime

public long getLastAccessTime()
Gets the LastAccess attribute of the IAttributes object.

Specified by:
getLastAccessTime in interface IElementAttributes
Returns:
The LastAccess value.

setLastAccessTimeNow

public void setLastAccessTimeNow()
Sets the LastAccessTime as now of the IElementAttributes object

Specified by:
setLastAccessTimeNow in interface IElementAttributes

getIsSpool

public boolean getIsSpool()
Can this item be spooled to disk

By default this is true.

Specified by:
getIsSpool in interface IElementAttributes
Returns:
The spoolable value

setIsSpool

public void setIsSpool(boolean val)
Sets the isSpool attribute of the IElementAttributes object

By default this is true.

Specified by:
setIsSpool in interface IElementAttributes
Parameters:
val - The new isSpool value

getIsLateral

public boolean getIsLateral()
Is this item laterally distributable. Can it be sent to auxiliaries of type lateral.

By default this is true.

Specified by:
getIsLateral in interface IElementAttributes
Returns:
The isLateral value

setIsLateral

public void setIsLateral(boolean val)
Sets the isLateral attribute of the IElementAttributes object

By default this is true.

Specified by:
setIsLateral in interface IElementAttributes
Parameters:
val - The new isLateral value

getIsRemote

public boolean getIsRemote()
Can this item be sent to the remote cache

Specified by:
getIsRemote in interface IElementAttributes
Returns:
true if the item can be sent to a remote auxiliary

setIsRemote

public void setIsRemote(boolean val)
Sets the isRemote attribute of the ElementAttributes object

Specified by:
setIsRemote in interface IElementAttributes
Parameters:
val - The new isRemote value

getIsEternal

public boolean getIsEternal()
You can turn off expiration by setting this to true. The max life value will be ignored.

Specified by:
getIsEternal in interface IElementAttributes
Returns:
true if the item cannot expire.

setIsEternal

public void setIsEternal(boolean val)
Sets the isEternal attribute of the ElementAttributes object. True means that the item should never expire. If can still be removed if it is the least recently used, and you are using the LRUMemory cache. it just will not be filtered for expiration by the cache hub.

Specified by:
setIsEternal in interface IElementAttributes
Parameters:
val - The new isEternal value

addElementEventHandler

public void addElementEventHandler(IElementEventHandler eventHandler)
Adds a ElementEventHandler. Handler's can be registered for multiple events. A registered handler will be called at every recognized event.

The alternative would be to register handlers for each event. Or maybe The handler interface should have a method to return whether it cares about certain events.

Specified by:
addElementEventHandler in interface IElementAttributes
Parameters:
eventHandler - The ElementEventHandler to be added to the list.

addElementEventHandlers

public void addElementEventHandlers(java.util.ArrayList eventHandlers)
Sets the eventHandlers of the IElementAttributes object.

This add the references to the local list. Subsequent changes in the caller's list will not be reflected.

Specified by:
addElementEventHandlers in interface IElementAttributes
Parameters:
eventHandlers - List of IElementEventHandler objects

getElementEventHandlers

public java.util.ArrayList getElementEventHandlers()
Gets the elementEventHandlers. Returns null if none exist. Makes checking easy.

Specified by:
getElementEventHandlers in interface IElementAttributes
Returns:
The elementEventHandlers List of IElementEventHandler objects

toString

public java.lang.String toString()
For logging and debugging the element IElementAttributes.

Overrides:
toString in class java.lang.Object
Returns:
String info about the values.


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.