Because I hand waved a bit in email (I was on webmail and did not have 
access to code on the weekend). I thought I should be explicit for Martin:

AbstractCachedAuthority - this is the version of 
BufferedAuthorityFactory that *only* is used as super class.
>     public IdentifiedObject createObject(String code) throws 
> FactoryException {
>         final String key = toKey(code);
>         IdentifiedObject obj = (IdentifiedObject) cache.get(key);
>         if (obj == null) {
>             try {
>                 cache.writeLock(key);
>                 obj = (IdentifiedObject) cache.peek(key);
>                 if (obj == null) {
>                     obj = generateObject(code);
>                     cache.put(key, obj);
>                 }
>             } finally {
>                 cache.writeUnLock(key);
>             }
>         }
>         return obj;
>     }
>     protected abstract IdentifiedObject generateObject( String code ) 
> throws FactoryException;
The contract of what a subclass needs to do is clear, implemented the 
abstract method generateObject, I will eventually mark the createObject 
method as final.

CachedAuthorityDecorator - this is the version of 
BufferedAuthorityFactory that *only* can be used as a decorator (a 
wrapper adding caching to an already existing authority factory):
>     public IdentifiedObject createObject(String code) throws 
> FactoryException {
>         final String key = toKey(code);
>         IdentifiedObject obj = (IdentifiedObject) cache.get(key);
>         if (obj == null) {
>             try {
>                 cache.writeLock(key);
>                 obj = (IdentifiedObject) cache.peek(key);
>                 if (obj == null) {
>                     obj = authority.createObject(code);
>                     cache.put(key, obj);
>                 }
>             } finally {
>                 cache.writeUnLock(key);
>             }
>         }
>         return obj;
>     }
To create one of these you need to supply a value for the delegate being 
wrapped - the field authority in this case. This class is already marked 
final.

Finally we have AbstractAuthorityMediator who acts as a mediator. This 
is when the instance we are going to be delegating to (ie the worker) 
needs to be created and managed as needed. We do that with an ObjectPool 
(so we do not have to figure out lifecycle control and eviction 
strategies ourself:
>     public IdentifiedObject createObject(String code) throws 
> FactoryException {
>         final String key = toKey(code);
>         IdentifiedObject obj = (IdentifiedObject) cache.get(key);
>         if (obj == null) {
>             try {
>                 AbstractCachedAuthorityFactory worker = null;
>                 try {
>                     worker = (AbstractCachedAuthorityFactory) 
> getPool().borrowObject();
>                     obj = worker.createObject(code);
>                 } finally {
>                     getPool().returnObject(worker);
>                 }
>             } catch (FactoryException e) {
>                 throw e;
>             } catch (Exception e) {
>                 throw new FactoryException(e);
>             }
>         }
>         return obj;
>     }
I hope that by cutting straight to the code things are made more clear.
Jody




-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to