org.apache.tapestry.pageload
Class PageSource

java.lang.Object
  extended by org.apache.tapestry.pageload.PageSource
All Implemented Interfaces:
IPageSource

public class PageSource
extends Object
implements IPageSource

A source for pages for a particular application. Each application should have its own PageSource, storing it into the ServletContext using a unique key (usually built from the application name).

The PageSource acts as a pool for IPage instances. Pages are retrieved from the pool using getPage(IRequestCycle, String, IMonitor) and are later returned to the pool using releasePage(IPage).

TBD: Pooled pages stay forever. Need a strategy for cleaning up the pool, tracking which pages have been in the pool the longest, etc. A mechanism for reporting pool statistics would be useful.

Author:
Howard Lewis Ship

Constructor Summary
PageSource(IEngine engine)
           
 
Method Summary
protected  MultiKey buildKey(IEngine engine, String pageName)
          Builds a key for a named page in the application's current locale.
protected  MultiKey buildKey(IPage page)
          Builds a key from an existing page, using the page's name and locale.
protected  void discardPageLoader(PageLoader loader)
          Invoked once the PageLoader is not longer needed; it is then returned to the pool.
protected  void discardPageSpecificationResolver(PageSpecificationResolver resolver)
          Invoked once the PageSpecificationResolver is no longer needed, it is returned to the pool.
 IPage getPage(IRequestCycle cycle, String pageName, IMonitor monitor)
          Gets the page from a pool, or otherwise loads the page.
protected  PageLoader getPageLoader(IRequestCycle cycle)
          Invoked to obtain an instance of PageLoader.
protected  PageSpecificationResolver getPageSpecificationResolver(IRequestCycle cycle)
          Invoked to obtain an instance of PageSpecificationResolver.
 IResourceResolver getResourceResolver()
           
 void releasePage(IPage page)
          Returns the page to the appropriate pool.
 void reset()
          Invoked (during testing primarily) to release the entire pool of pages, and the caches of bindings and assets.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PageSource

public PageSource(IEngine engine)
Method Detail

getResourceResolver

public IResourceResolver getResourceResolver()
Specified by:
getResourceResolver in interface IPageSource

buildKey

protected MultiKey buildKey(IEngine engine,
                            String pageName)
Builds a key for a named page in the application's current locale.


buildKey

protected MultiKey buildKey(IPage page)
Builds a key from an existing page, using the page's name and locale. This is used when storing a page into the pool.


getPage

public IPage getPage(IRequestCycle cycle,
                     String pageName,
                     IMonitor monitor)
Gets the page from a pool, or otherwise loads the page. This operation is threadsafe.

Specified by:
getPage in interface IPageSource
Parameters:
cycle - the current request cycle
pageName - the name of the page. May be qualified with a library id prefix, which may even be nested. Unqualified names are searched for extensively in the application namespace, and then in the framework namespace.
monitor - informed of any page loading activity

getPageLoader

protected PageLoader getPageLoader(IRequestCycle cycle)
Invoked to obtain an instance of PageLoader. An instance if aquired from the pool or, if none are available, created fresh.

Since:
3.0

discardPageLoader

protected void discardPageLoader(PageLoader loader)
Invoked once the PageLoader is not longer needed; it is then returned to the pool.

Since:
3.0

getPageSpecificationResolver

protected PageSpecificationResolver getPageSpecificationResolver(IRequestCycle cycle)
Invoked to obtain an instance of PageSpecificationResolver. An instance is acquired form the pool or, if none are available, a new one is instantiated.

Since:
3.0

discardPageSpecificationResolver

protected void discardPageSpecificationResolver(PageSpecificationResolver resolver)
Invoked once the PageSpecificationResolver is no longer needed, it is returned to the pool.

Since:
3.0

releasePage

public void releasePage(IPage page)
Returns the page to the appropriate pool. Invokes IPage.detach().

Specified by:
releasePage in interface IPageSource

reset

public void reset()
Invoked (during testing primarily) to release the entire pool of pages, and the caches of bindings and assets.

Specified by:
reset in interface IPageSource

toString

public String toString()
Overrides:
toString in class Object