org.apache.shindig.gadgets
Class AbstractSpecFactory<T>

java.lang.Object
  extended by org.apache.shindig.gadgets.AbstractSpecFactory<T>
Direct Known Subclasses:
DefaultGadgetSpecFactory, DefaultMessageBundleFactory

public abstract class AbstractSpecFactory<T>
extends Object

Basis for implementing GadgetSpec and MessageBundle factories. Automatically updates objects as needed asynchronously to provide optimal throughput.


Nested Class Summary
protected static class AbstractSpecFactory.Query
          Holds information used to fetch a spec.
protected static class AbstractSpecFactory.SpecRetrievalFailedException
           
 
Constructor Summary
AbstractSpecFactory(Class<T> clazz, ExecutorService executor, RequestPipeline pipeline, Cache<Uri,Object> cache, long refresh)
           
 
Method Summary
protected  T fetchFromNetwork(AbstractSpecFactory.Query query)
          Retrieves a spec from the network, parses, and adds it to the cache.
protected  T getSpec(AbstractSpecFactory.Query query)
          Attempt to fetch a spec, either from cache or from the network.
protected abstract  T parse(String content, AbstractSpecFactory.Query query)
          Parse and return a new spec object from the network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSpecFactory

public AbstractSpecFactory(Class<T> clazz,
                           ExecutorService executor,
                           RequestPipeline pipeline,
                           Cache<Uri,Object> cache,
                           long refresh)
Parameters:
clazz - the class for spec objects.
executor - for asynchronously updating specs
pipeline - the request pipeline for fetching new specs
cache - a cache for parsed spec objects
refresh - the frequency at which to update specs, independent of cache expiration policy
Method Detail

getSpec

protected T getSpec(AbstractSpecFactory.Query query)
             throws GadgetException
Attempt to fetch a spec, either from cache or from the network. Note that the query passed here will always be passed, unmodified, to parse(String, Query). This can be used to carry additional context information during parsing.

Throws:
GadgetException

fetchFromNetwork

protected T fetchFromNetwork(AbstractSpecFactory.Query query)
                      throws AbstractSpecFactory.SpecRetrievalFailedException,
                             GadgetException
Retrieves a spec from the network, parses, and adds it to the cache.

Throws:
AbstractSpecFactory.SpecRetrievalFailedException
GadgetException

parse

protected abstract T parse(String content,
                           AbstractSpecFactory.Query query)
                    throws XmlException,
                           GadgetException
Parse and return a new spec object from the network.

Parameters:
content - the content located at specUri
query - same as was passed getSpec(Query)
Throws:
XmlException
GadgetException


Copyright © 2007-2012. All Rights Reserved.