org.globus.wsrf.impl
Class ResourceHomeImpl

java.lang.Object
  extended byorg.globus.wsrf.impl.ResourceHomeImpl
All Implemented Interfaces:
Initializable, ResourceHome
Direct Known Subclasses:
NotificationConsumerHome, SecurityContextHome, SubscriptionHome

public abstract class ResourceHomeImpl
extends Object
implements ResourceHome, Initializable

An implementation of the ResourceHome interface. This implementation was designed to work with resources that implement the PersistenceCallback interface as well as memory resident resources. If the resource class implements the PersistenceCallback interface SoftReferences will be used to recycle resource objects. The resource class implementation is responsible for saving its state to disk. This implementation will not call PersistenceCallback.store(). The resource implementation must have a default constructor.

Configuration options:


Note: Must be deployed with org.globus.wsrf.jndi.BeanFactory in JNDI or user must first call initialize() method. Also when overriding the initialize() method make sure to call super.initialize();.

Note: This ResourceHome implementation performs per key synchronization.


Nested Class Summary
private static class ResourceHomeImpl.Sweeper
          This ResourceSweeper implementation just returns the resources currently stored in the map.
 
Field Summary
private  Cache cache
           
private  String cacheLocation
           
private static org.globus.util.I18n i18n
           
private  boolean initialized
           
protected  Class keyTypeClass
           
protected  QName keyTypeName
           
protected  LockManager lockManager
           
private static org.apache.commons.logging.Log logger
           
protected  Class resourceClass
           
private  boolean resourceIsPersistent
           
protected  Map resources
           
private  ResourceHomeImpl.Sweeper sweeper
           
private  long sweeperDelay
           
 
Constructor Summary
ResourceHomeImpl()
           
 
Method Summary
protected  void add(ResourceKey key, Resource resource)
           
private  void addResource(ResourceKey key, Resource resource)
           
protected  Resource createNewInstance()
           
protected  Resource createNewInstanceAndLoad(ResourceKey key)
           
 Resource find(ResourceKey key)
          Retrives a resource.
private  Resource get(ResourceKey key)
           
 String getCacheLocation()
           
 Class getKeyTypeClass()
          The resource key type.
 QName getKeyTypeName()
          The name of the resource key.
 String getResourceClass()
           
 long getSweeperDelay()
           
 void initialize()
           
 void remove(ResourceKey key)
          Removes a resource.
 void setCacheLocation(String jndiLocation)
           
 void setResourceClass(String clazz)
           
 void setResourceKeyName(String keyName)
           
 void setResourceKeyType(String clazz)
           
 void setSweeperDelay(long delay)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.commons.logging.Log logger

i18n

private static org.globus.util.I18n i18n

resources

protected Map resources

keyTypeName

protected QName keyTypeName

resourceClass

protected Class resourceClass

keyTypeClass

protected Class keyTypeClass

resourceIsPersistent

private boolean resourceIsPersistent

lockManager

protected LockManager lockManager

cacheLocation

private String cacheLocation

cache

private Cache cache

sweeperDelay

private long sweeperDelay

sweeper

private ResourceHomeImpl.Sweeper sweeper

initialized

private boolean initialized
Constructor Detail

ResourceHomeImpl

public ResourceHomeImpl()
Method Detail

setResourceClass

public void setResourceClass(String clazz)
                      throws ClassNotFoundException
Throws:
ClassNotFoundException

getResourceClass

public String getResourceClass()

setResourceKeyType

public void setResourceKeyType(String clazz)
                        throws ClassNotFoundException
Throws:
ClassNotFoundException

getKeyTypeClass

public Class getKeyTypeClass()
Description copied from interface: ResourceHome
The resource key type. The ResourceKey used or passed to this ResourceHome must have match this type (corresponds to ResourceKey.getValue()).

Specified by:
getKeyTypeClass in interface ResourceHome
Returns:
the type of the key.

setResourceKeyName

public void setResourceKeyName(String keyName)

getKeyTypeName

public QName getKeyTypeName()
Description copied from interface: ResourceHome
The name of the resource key. The ResourceKey used or passed to this ResourceHome must have match this name (corresponds to ResourceKey.getName()).

Specified by:
getKeyTypeName in interface ResourceHome
Returns:
the name of the key.

setSweeperDelay

public void setSweeperDelay(long delay)

getSweeperDelay

public long getSweeperDelay()

setCacheLocation

public void setCacheLocation(String jndiLocation)

getCacheLocation

public String getCacheLocation()

initialize

public void initialize()
                throws Exception
Specified by:
initialize in interface Initializable
Throws:
Exception

createNewInstance

protected Resource createNewInstance()
                              throws ResourceException
Throws:
ResourceException

createNewInstanceAndLoad

protected Resource createNewInstanceAndLoad(ResourceKey key)
                                     throws ResourceException
Throws:
ResourceException

find

public Resource find(ResourceKey key)
              throws ResourceException
Description copied from interface: ResourceHome
Retrives a resource. Note: This function must not return null. It must return the resource object or throw an exception if there is no resource with the specified key.

Specified by:
find in interface ResourceHome
Returns:
non-null resource object.
Throws:
ResourceException - if any other error occurs.

get

private Resource get(ResourceKey key)
              throws ResourceException
Throws:
ResourceException

remove

public void remove(ResourceKey key)
            throws ResourceException
Removes a resource. If the resource implements the RemoveCallback interface the RemoveCallback.remove() operation will be called. The RemoveCallback.remove() operation is called under a reentrant lock. Therefore, a RemoveCallback.remove() implementation might perform ResourceHome.find() on itself from the same thread but will deadlock if done from another thread.

Specified by:
remove in interface ResourceHome
Throws:
NoSuchResourceException - if no resource exists with the given key
InvalidResourceKeyException - if the resource key is invalid.
RemoveNotSupportedException - if remove operation is not supported.
ResourceException - if any other error occurs.

add

protected void add(ResourceKey key,
                   Resource resource)

addResource

private void addResource(ResourceKey key,
                         Resource resource)