org.fjank.jcache
Class AttributesImpl

java.lang.Object
  extended by org.fjank.jcache.AttributesImpl
All Implemented Interfaces:
Serializable, Cloneable, Attributes

public final class AttributesImpl
extends Object
implements Cloneable, Serializable, Attributes

This class defines the attributes an object in the cache can have.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.util.jcache.Attributes
DISTRIBUTE, GROUP_TTL_DESTROY, INVALIDATE_EVENT, NOFLUSH, ORIGINAL, REPLY, SPOOL, SYNCHRONIZE
 
Constructor Summary
AttributesImpl()
          Creates new Attributes
AttributesImpl(Attributes attributes)
           
 
Method Summary
 void applyAttributes(Attributes attributes)
           
 boolean equals(Object arg0)
           
 long getCreateTime()
          returns the time the object was loaded into the cache.
 long getDefaultTimeToLive()
           
 long getIdleTime()
          returns the current value for the idle time interval.
 CacheEventListener getListener()
          Gets the CacheEventListener.
 CacheLoader getLoader()
          returns the CacheLoaderattribute.
 int getSize()
          returns the size of the object.
 long getTimeToLive()
          returns the current value for the time to live interval.
 long getVersion()
          returns the current value of version.
 boolean isSet(long theFlags)
          Checks wether the flags are set or not.
 void reset()
          resets the Attributes to its default values.
 void setCreateTime(long aCreateTime)
          Sets the createTime.
 void setDefaultTimeToLive(long ttl)
          Will set the maximum time the associated cache object will stay in the cache before it is invalidated.
 void setFlags(long theFlags)
          Is used to specify wich attributes should be set in the attributes object.
 void setIdleTime(long idle)
          sets the maximum time the associated cache object will remain in the cache without being referenced before it is invalidated.
 void setListener(int event, CacheEventListener aListener)
          Register an event listener object to be executed when the specified event occurs with relationship to the associated object.
 void setLoader(CacheLoader aLoader)
          Will associate a loader object with this object.
 void setSize(int aSize)
          Is used to specify the size in bytes of the object being cached.
 void setTimeToLive(long ttl)
          Will set the maximum time the associated cache object will stay in the cache before it is invalidated.
 void setVersion(long aVersion)
          Sets the version attribute.
 long timeToSeconds(int days, int hours, int minutes, int seconds)
          Will convert the time specified into seconds.
 String toString()
          returns these Attributes as a String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributesImpl

public AttributesImpl()
Creates new Attributes


AttributesImpl

public AttributesImpl(Attributes attributes)
Method Detail

applyAttributes

public void applyAttributes(Attributes attributes)
Specified by:
applyAttributes in interface Attributes

equals

public boolean equals(Object arg0)
Overrides:
equals in class Object

getCreateTime

public long getCreateTime()
returns the time the object was loaded into the cache. The time is the number of milliseconds since midnight, January 1, 1970 (UTC).

Specified by:
getCreateTime in interface Attributes
Returns:
the time the object was loaded into the cache. The time is the number of milliseconds since midnight, January 1, 1970 (UTC).

getDefaultTimeToLive

public long getDefaultTimeToLive()
Specified by:
getDefaultTimeToLive in interface Attributes

getIdleTime

public long getIdleTime()
returns the current value for the idle time interval.

Specified by:
getIdleTime in interface Attributes
Returns:
the current value for the idle time interval.

getListener

public CacheEventListener getListener()
Gets the CacheEventListener.

Specified by:
getListener in interface Attributes
Returns:
The CacheEventListener.

getLoader

public CacheLoader getLoader()
returns the CacheLoaderattribute.

Specified by:
getLoader in interface Attributes
Returns:
the CacheLoaderattribute.

getSize

public int getSize()
returns the size of the object. this size is set by the setSize(int) method, or in the case of StreamAccess objects, the size is calculated by the cache.

Specified by:
getSize in interface Attributes
Returns:
the size of the object, or 0 if the size has not been set.

getTimeToLive

public long getTimeToLive()
returns the current value for the time to live interval.

Specified by:
getTimeToLive in interface Attributes
Returns:
the current value for the time to live interval.

getVersion

public long getVersion()
returns the current value of version.

Specified by:
getVersion in interface Attributes
Returns:
the current value of version.

isSet

public boolean isSet(long theFlags)
Checks wether the flags are set or not.

Specified by:
isSet in interface Attributes
Parameters:
theFlags - the flags to be checked. may be OR-ed together, for wich this method will return true only if all flags are set.
Returns:
true if the specified attribute is set, false otherwise.

reset

public void reset()
resets the Attributes to its default values. The attributes wich are reset are expiration time attributes, time to live, default time to live, idle time and event handlers.

Specified by:
reset in interface Attributes

setCreateTime

public void setCreateTime(long aCreateTime)
Sets the createTime.

Specified by:
setCreateTime in interface Attributes
Parameters:
aCreateTime - The createTime to set

setDefaultTimeToLive

public void setDefaultTimeToLive(long ttl)
                          throws InvalidArgumentException
Will set the maximum time the associated cache object will stay in the cache before it is invalidated. For regions and groups, this will establish a default time to live that is applied individually to each member in the group or region. It will not cause the entire group or region to time out as a whole. For individual objects, the default time to live is equivalent with time to live. If both are set the default time to live is ignored. The time starts when the object is loaded into the cache(by the CacheLoaderobjector put by the CacheAccess#replace(Object, Object)) or when the time to live attribute is set by the CacheLoader.setAttributes(Object,Attributes) method.

Specified by:
setDefaultTimeToLive in interface Attributes
Parameters:
ttl - the time to live in seconds. The timeToSeconds(int, int, int, int) can be used to convert days, hours, minutes to secounds.
Throws:
InvalidArgumentException - if a negative value for ttl is supplied.

setFlags

public void setFlags(long theFlags)
Is used to specify wich attributes should be set in the attributes object. The different attributes wich is valid is defined as public static variables in the Attributesclass.

Specified by:
setFlags in interface Attributes
Parameters:
theFlags - The attributes to set. the attributes may be OR-ed together. I.e. Attributes.DISTRIBUTE | Attributes.SYNCHRONIZE Invalid flags are silently ignored. To reset all flags you use 0 as a parameter. I.e. setFlags(0)

setIdleTime

public void setIdleTime(long idle)
                 throws InvalidArgumentException
sets the maximum time the associated cache object will remain in the cache without being referenced before it is invalidated.

Specified by:
setIdleTime in interface Attributes
Parameters:
idle - is in seconds. The timeToSeconds(int, int, int,int) can be used to convert days, hours, minutes to secounds.
Throws:
InvalidArgumentException - if a negative value for idle is supplied.

setListener

public void setListener(int event,
                        CacheEventListener aListener)
Register an event listener object to be executed when the specified event occurs with relationship to the associated object. Currently the only invalidate event being monitored is Attributes.INVALIDATE_EVENT. If invalid parameters are passed such as invalid events, or null as listener, this method silently returns without doing any changes to this object.

Specified by:
setListener in interface Attributes
Parameters:
event - The event to listen for.
aListener - the listener to fire when the event occurs.

setLoader

public void setLoader(CacheLoader aLoader)
Will associate a loader object with this object.

Specified by:
setLoader in interface Attributes
Parameters:
aLoader - The loader to set. This parameter can be null.

setSize

public void setSize(int aSize)
Is used to specify the size in bytes of the object being cached. This is used to determine when the cache capacity is reached. If the cache is not using object size to determine the capacity (It can also use object counts) this value is ignored.

Specified by:
setSize in interface Attributes
Parameters:
aSize - the size to be set. if this parameter is smaller than zero, this method silently returns.

setTimeToLive

public void setTimeToLive(long ttl)
                   throws InvalidArgumentException
Will set the maximum time the associated cache object will stay in the cache before it is invalidated. The time starts when the object is loaded into the cache(by the CacheLoaderobject or put by the CacheAccess#replace(Object, Object)) or when the time to live attribute is set by the CacheLoader.setAttributes(Object, Attributes) method.

Specified by:
setTimeToLive in interface Attributes
Parameters:
ttl - the time to live in seconds. The timeToSeconds(int, int, int, int) can be used to convert days, hours, minutes to seconds.
Throws:
InvalidArgumentException - if a negative value for ttl is supplied.

setVersion

public void setVersion(long aVersion)
Sets the version attribute. Is only maintained for user convenience. It is not used internally by the cache.

Specified by:
setVersion in interface Attributes
Parameters:
aVersion - the version number to set.

timeToSeconds

public long timeToSeconds(int days,
                          int hours,
                          int minutes,
                          int seconds)
                   throws InvalidArgumentException
Will convert the time specified into seconds.

Specified by:
timeToSeconds in interface Attributes
Parameters:
days - number of days.
hours - number of hours.
minutes - number of minutes.
seconds - number of seconds.
Returns:
the converted time in seconds.
Throws:
InvalidArgumentException - if any of the parameters are negative values.

toString

public String toString()
returns these Attributes as a String.

Overrides:
toString in class Object
Returns:
these Attributes as a String.


Copyright © 2002-2009 Hosted by SourceForge. All Rights Reserved.