SK.gnome.dwarf.utils.cache
Class SimplePool

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.utils.cache.SimplePool
All Implemented Interfaces:
Pool, Reportable, Service

public class SimplePool
extends GenericService
implements Pool, Reportable

This class implements simple object pool with a maximum size limit.

This service implements the Pool interface. The maximum size of the pool may be specified via the setSize(int) method. If the size is zero, the pool may grow forever.

This pool implementation is thread-safe.


Field Summary
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
SimplePool(java.lang.String name)
          Creates a new SimplePool with no size limit.
 
Method Summary
 void clear()
          Removes all objects from the pool.
 java.lang.Object get()
          Gets an object from the pool.
 boolean put(java.lang.Object obj)
          Puts the object to the pool.
 java.lang.String report()
          Returns the service report.
 void setSize(int size)
          Sets the maximum pool size limit.
 void shutdown()
          Shuts down the service; It clears the pool content as well by calling clear().
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, init, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimplePool

public SimplePool(java.lang.String name)
Creates a new SimplePool with no size limit.

Method Detail

setSize

public void setSize(int size)
Sets the maximum pool size limit.

Zero value means no limit, which is the default for newly created SimplePool objects.

Parameters:
size - the maximum size of the pool
See Also:
put(Object)

shutdown

public void shutdown()
Shuts down the service;

It clears the pool content as well by calling clear().

Specified by:
shutdown in interface Service
Overrides:
shutdown in class GenericService

put

public boolean put(java.lang.Object obj)
Puts the object to the pool.

The new object is put to the pool only if the maximum size limit is greater than the current pool size.

Specified by:
put in interface Pool
Parameters:
obj - the cached object
Returns:
true if the object was put to the pool, false otherwise

get

public java.lang.Object get()
Description copied from interface: Pool
Gets an object from the pool.

The object is removed from the pool and returned to the caller.

If an object implementing the Cacheable interface is being removed from the pool, the Cacheable.handleCacheEvent(Cacheable.CacheEvent) method must be invoked on it with the Cacheable.CacheEvent.REMOVED value.

Specified by:
get in interface Pool
Returns:
the cached object or null if no object exists in the pool

clear

public void clear()
Description copied from interface: Pool
Removes all objects from the pool.

If an object implementing the Cacheable interface is being removed from the pool, the Cacheable.handleCacheEvent(Cacheable.CacheEvent) method must be invoked on it with the Cacheable.CacheEvent.INVALIDATED value.

Specified by:
clear in interface Pool

report

public java.lang.String report()
Returns the service report.

Returns the current/peak/total number of cached objects plus the number of pool hits and misses so far.

Note: When clearing the pool via the clear() method, only the current number of the cached entries is reset to zero.

Specified by:
report in interface Reportable
Returns:
current service state in a human-readable format


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.