Oracle Application Server Java Object Cache API Reference
10g Release 2 (10.1.2)

B14018-02


oracle.ias.cache
Class CacheLoader

java.lang.Object
  extended byoracle.ias.cache.CacheLoader

Direct Known Subclasses:
CacheListLoader

public abstract class CacheLoader
extends java.lang.Object

CacheLoader is an abstract class. Application should extend this class to handle the loading of objects into the cache. A cache loader can be registered for a region, a group or a specific object using CacheAccess object's define methods.

Since:
2.0.0
Version:
2.0.0 07/12/00
See Also:
CacheAccess.defineRegion, CacheAccess.defineGroup, CacheAccess.defineObject

Constructor Summary
CacheLoader()
           

 

Method Summary
protected  java.io.File createDiskObject(java.lang.Object handle)
          is called from the load method to create a disk object.
protected  java.io.File createDiskObject(java.lang.Object handle, Attributes attr)
          is called from the load method to create a disk object.
protected  java.io.OutputStream createStream(java.lang.Object handle)
          is called from the load method to create a streamAccessed object.
protected  java.io.OutputStream createStream(java.lang.Object handle, Attributes attr)
          is called from the load method to create a streamAccessed object.
protected  CacheException exceptionHandler(java.lang.String msg, java.lang.Exception ex)
          is called from the load method to convert any non CacheExceptions into CacheExceptions with the base exception set to the orginal exception.
protected  java.lang.Object getFromRemote(java.lang.Object handle, oracle.ias.cache.CacheAddress addr, int timeout, boolean useRemoteTtl)
          searches a specific remote caches for the object to be loaded.
protected  java.lang.Object getName(java.lang.Object handle)
          returns the name Object for the object being loaded.
protected  java.lang.String getRegion(java.lang.Object handle)
          returns the name of the region for the object being loaded.
protected  boolean isRemoteRequest(java.lang.Object handle)
          returns true if the load was prompted from a remote site, false otherwise If the load was triggered by a direct request from another site, this method will return true.
abstract  java.lang.Object load(java.lang.Object handle, java.lang.Object argument)
          is an abstract method.
protected  void log(java.lang.String msg)
          The log method is called from the load method to record a message in the cache's log.
protected  java.lang.Object netSearch(java.lang.Object handle, int timeout)
          searches other caches for the object to be loaded.
protected  java.lang.Object netSearch(java.lang.Object handle, int timeout, boolean useRemoteTtl)
          searchs other caches for the object to be loaded.
protected  void setAttributes(java.lang.Object handle, Attributes attr)
          sets the attributes of the object in the load method.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

CacheLoader

public CacheLoader()

Method Detail

load

public abstract java.lang.Object load(java.lang.Object handle,
                                      java.lang.Object argument)
                               throws CacheException
is an abstract method. Applications should implement this method to customize the loading of cache object. This method is called by the caching service when the requested object is not in the cache.
Parameters:
handle - An internal handle object is passed in from cache service. It should only be used as the first parameter of the netSearch(handle, timeout) or setAttributes(handle, attributes) API.
argument - It is an argument object for load method passed in from customer code. This object is passed in as args either in get(String name, Object args), or get(String name, String group, Object args)
Returns:
In general, the object that is to be saved in the cache should be returned. If createStream has been called the OutputStream object returned by createStream should be returned. If createDiskObject is called the File object returned by createDiskObject should be returned.
Throws:
CacheException - if any error occurs.
Since:
2.0.0
See Also:
CacheAccess.get

netSearch

protected final java.lang.Object netSearch(java.lang.Object handle,
                                           int timeout)
                                    throws CacheException
searches other caches for the object to be loaded. This method is called from the default load method and is available to be called by application overrides of the load method. This is a protected method so it is available only from the load method. If the search is successful, a reference to a local copy of the object is returned. If the object is not found an ObjectNotFoundException is thrown.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
timeout - The time to wait for the response in milliseconds.
Returns:
the requested object if found, otherwise a null.
Throws:
oracle.ias.cache.ObjectNotFoundException - if the object is not found or timeout.
CacheException
Since:
2.0.0

netSearch

protected final java.lang.Object netSearch(java.lang.Object handle,
                                           int timeout,
                                           boolean useRemoteTtl)
                                    throws CacheException
searchs other caches for the object to be loaded. This method is called from the default load method and is available to be called by application overrides of the load method. If the useRemoteTtl parameter is true, the time to live interval or idle time interval that was set at the remote site will be used locally overwriting the attribute that is currently set. NetSearch is a protected method so it is available only from the load method. If the search is successful, a reference to a local copy of the object is returned. If the object is not found an ObjectNotFoundException is thrown.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
timeout - The time to wait for the response in milliseconds.
useRemoteTtl - if true the idletime/ttlInterval from the remote cache are used as the local values
Returns:
the requested object if found, otherwise a null.
Throws:
oracle.ias.cache.ObjectNotFoundException - if the object is not found or timeout.
CacheException
Since:
2.0.0

isRemoteRequest

protected final boolean isRemoteRequest(java.lang.Object handle)
returns true if the load was prompted from a remote site, false otherwise If the load was triggered by a direct request from another site, this method will return true. This allows the implementor to handle the loading differently in the remote case if desired.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
Returns:
true if the load was prompted from a remote site, false otherwise
Since:
9.0.4

getFromRemote

protected final java.lang.Object getFromRemote(java.lang.Object handle,
                                               oracle.ias.cache.CacheAddress addr,
                                               int timeout,
                                               boolean useRemoteTtl)
                                        throws CacheException
searches a specific remote caches for the object to be loaded. This method is called from the default load method and is available to be called by application overrides of the load method. If the useRemoteTtl parameter is true, the time to live interval or idle time interval that was set at the remote site will be used locally overwriting the attribute that is currently set. getFromRemote is a protected method so it is available only from the load method. If the search is successful, a reference to a local copy of the object is returned. If the object is not found an ObjectNotFoundException is thrown.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
timeout - The time to wait for the response in milliseconds.
useRemoteTtl - if true the idletime/ttlInterval from the remote cache are used as the local values
Returns:
the requested object if found, otherwise a null.
Throws:
oracle.ias.cache.ObjectNotFoundException - if the object is not found or timeout.
CacheException
Since:
9.0.4

setAttributes

protected final void setAttributes(java.lang.Object handle,
                                   Attributes attr)
                            throws CacheException
sets the attributes of the object in the load method. This method is available to be called by application overrides of the load method. This is a protected method so it is available only from the load method.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
attr - The set of attributes to associate with the object
Throws:
CacheException - if a error occurs
Since:
2.0.0

getName

protected final java.lang.Object getName(java.lang.Object handle)
returns the name Object for the object being loaded. This method is available to be called by application overrides of the load method. This is a protected method so it is available only from the load method.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
Returns:
The name Object for the object being loaded.
Since:
2.0.0

getRegion

protected final java.lang.String getRegion(java.lang.Object handle)
returns the name of the region for the object being loaded. This method is available to be called by application overrides of the load method. This is a protected method so it is available only from the load method.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
Returns:
The name Object for the object being loaded.
Since:
2.0.0

createStream

protected final java.io.OutputStream createStream(java.lang.Object handle,
                                                  Attributes attr)
                                           throws oracle.ias.cache.ObjectExistsException,
                                                  DiskCacheException,
                                                  CacheException
is called from the load method to create a streamAccessed object. The OutputStream object returned is used to load the object into the cache. When using a StreamAccess object the attributes for the object should be set on the createStream call rather than with the setAttributes method. This ensure that the file will be created correctly with relationship to the DISTRIBUTE flag. If the object is distributed and is being loaded or has been loaded by another cache an ObjectExistException is thrown. This exception should be thrown by the load method. The cache will handle the exception and return the loaded object to the application.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
attr - The set of attributes to associate with the object
Returns:
An OutputStream to load the object into the cache.
Throws:
CacheException - if a error occurs
oracle.ias.cache.ObjectExistsException - if the object is being or has already been loaded by another cache
DiskCacheException
Since:
2.0.0

createStream

protected final java.io.OutputStream createStream(java.lang.Object handle)
                                           throws oracle.ias.cache.ObjectExistsException,
                                                  DiskCacheException,
                                                  CacheException,
                                                  java.io.IOException
is called from the load method to create a streamAccessed object. The OutputStream object returned is used to load the object into the cache. When using a StreamAccess object the attributes for the object should be set on the createStream call rather than with the setAttributes method. This ensure that the file will be created correctly with relationship to the DISTRIBUTE flag. If the object is distributed and is being loaded or has been loaded by another cache an ObjectExistException is thrown. This exception should be thrown by the load method. The cache will handle the exception and return the loaded object to the application.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
Returns:
An OutputStream to load the object into the cache.
Throws:
oracle.ias.cache.ObjectExistsException - if the object is being or has already been loaded by another cache
DiskCacheException
CacheException
java.io.IOException
Since:
2.0.0

createDiskObject

protected final java.io.File createDiskObject(java.lang.Object handle,
                                              Attributes attr)
                                       throws oracle.ias.cache.ObjectExistsException,
                                              DiskCacheException,
                                              CacheException,
                                              java.io.IOException
is called from the load method to create a disk object. The File object returned is used to load the object into the cache. When using a Disk object the attributes for the object should be set on the createDiskObject call rather than with the setAttributes method. This insure that the file will be created correctly with relationship to the DISTRIBUTE flag. If the object is distributed and is being loaded or has been loaded by another cache an ObjectExistException is thrown. This exception should be thrown by the load method. The cache will handle the exception and return the loaded object to the application.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
attr - The set of attributes to associate with the object
Returns:
An OutputStream to load the object into the cache.
Throws:
CacheException - if a error occurs
oracle.ias.cache.ObjectExistsException - if the object is being or has already been loaded by another cache
DiskCacheException
java.io.IOException
Since:
2.0.0

createDiskObject

protected final java.io.File createDiskObject(java.lang.Object handle)
                                       throws oracle.ias.cache.ObjectExistsException,
                                              DiskCacheException,
                                              CacheException,
                                              java.io.IOException
is called from the load method to create a disk object. The File object returned is used to load the object into the cache. When using a Disk object the attributes for the object should be set on the createDiskObject call rather than with the setAttributes method. This insure that the file will be created correctly with relationship to the DISTRIBUTE flag. If the object is distributed and is being loaded or has been loaded by another cache an ObjectExistException is thrown. This exception should be thrown by the load method. The cache will handle the exception and return the loaded object to the application.
Parameters:
handle - An internal cache handle object, it is passed in as the first parameter in load(Object handle, Object argument().
Returns:
An OutputStream to load the object into the cache.
Throws:
oracle.ias.cache.ObjectExistsException - if the object is being or has already been loaded by another cache
DiskCacheException
CacheException
java.io.IOException
Since:
2.0.0

exceptionHandler

protected final CacheException exceptionHandler(java.lang.String msg,
                                                java.lang.Exception ex)
is called from the load method to convert any non CacheExceptions into CacheExceptions with the base exception set to the orginal exception. This allows the load method to only throw CacheExceptions without loosing important information. The exception will also be logged (assuming that logging is configured and the logging severity is set sufficiently high). For all CacheExceptions, if CacheException.printStackTrace() is called and there is a base exception, the stack for the base exception will be printed.
Parameters:
msg - the message to be included with the exception
ex - the original exception
Returns:
A CacheException
Since:
2.0.0

log

protected final void log(java.lang.String msg)
The log method is called from the load method to record a message in the cache's log. How and where the logging occurs is dependent of the configuration of the logger in the cache.
Parameters:
msg - the message to be logged
Since:
2.0.0

Oracle Application Server Java Object Cache API Reference
10g Release 2 (10.1.2)

B14018-02


Copyright © 2004, 2005, Oracle. All rights reserved.