|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A source cache caches Objects that are created from a source. It handles transparently rereading sources and recreation of objects if the source validity has expired or the object has been cleaned from the cache. For this, a reloader callback needs to be registered that actually does the recreation of the cached object.
Example:
public void service(ServiceManager manager) { ... // obtain source cache on startup / service / initialize SourceCache cache = (SourceCache) manager.lookup(SourceCache.ROLE); // register reloader // with anonymous class handling the callback cache.register( new SourceReloader() { public Object reload(Source src, Object param) { return refresh(src, (String) param[0], (Integer) param[1] ); }); } // have callback method. Private is OK because its used from a anonymous // nested class. private CreatedObject refresh(Source src, String param1, Integer param2) { ... } public void foo() { ... // use cache CreatedObject foo = (CreatedObject) cache.getObject(resolver, key, uri, ... Object[] { param1, new Integer(param2) }); } public void dispose() { // release source cache on dispose manager.release(cache); }
Field Summary | |
static String |
ROLE
|
Method Summary | |
Object |
getObject(SourceResolver resolver,
Object key,
String uri,
Object parameter)
Retrieve an object from the cache. |
void |
register(SourceReloader reloader)
Register a source reloader that will recreate cached objects. |
Field Detail |
public static final String ROLE
Method Detail |
public void register(SourceReloader reloader)
reloader
- public Object getObject(SourceResolver resolver, Object key, String uri, Object parameter) throws MalformedURLException, IOException
resolver
- A source resolver to use.key
- An object used as a key to the cached object.uri
- A string holding the URI.parameter
- Parameters to pass to the source reloader.
MalformedURLException
IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |