org.apache.tapestry.pageload
Class PageSource

java.lang.Object
  extended by org.apache.commons.pool.BaseKeyedPoolableObjectFactory
      extended by org.apache.tapestry.pageload.PageSource
All Implemented Interfaces:
EventListener, org.apache.commons.pool.KeyedPoolableObjectFactory, org.apache.hivemind.events.RegistryShutdownListener, IPageSource, ReportStatusListener, ResetEventListener

public class PageSource
extends org.apache.commons.pool.BaseKeyedPoolableObjectFactory
implements IPageSource, ResetEventListener, ReportStatusListener, org.apache.hivemind.events.RegistryShutdownListener

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

The PageSource acts as a pool for IPageinstances. Pages are retrieved from the pool using getPage(IRequestCycle, String)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.

Author:
Howard Lewis Ship

Constructor Summary
PageSource()
           
 
Method Summary
protected  PageKey buildKey(IEngine engine, String pageName)
          Builds a key for a named page in the application's current locale.
protected  PageKey buildKey(IPage page)
          Builds a key from an existing page, using the page's name and locale.
 org.apache.hivemind.ClassResolver getClassResolver()
          Gets the class resolver used to load all pages / page components.
 IPage getPage(IRequestCycle cycle, String pageName)
          Gets the page from a pool, or otherwise loads the page.
 void initializeService()
           
 Object makeObject(Object key)
           
 void registryDidShutdown()
           
 void releasePage(IPage page)
          Returns the page to the appropriate pool.
 void reportStatus(ReportStatusEvent event)
           
 void resetEventDidOccur()
           
 void setClassResolver(org.apache.hivemind.ClassResolver resolver)
           
 void setLoader(IPageLoader loader)
           
 void setPageSpecificationResolver(PageSpecificationResolver resolver)
           
 void setPropertySource(IPropertySource propertySource)
           
 void setRequestCycle(IRequestCycle cycle)
           
 void setServiceId(String serviceId)
           
 
Methods inherited from class org.apache.commons.pool.BaseKeyedPoolableObjectFactory
activateObject, destroyObject, passivateObject, validateObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageSource

public PageSource()
Method Detail

initializeService

public void initializeService()

registryDidShutdown

public void registryDidShutdown()
Specified by:
registryDidShutdown in interface org.apache.hivemind.events.RegistryShutdownListener

getClassResolver

public org.apache.hivemind.ClassResolver getClassResolver()
Description copied from interface: IPageSource
Gets the class resolver used to load all pages / page components.

Specified by:
getClassResolver in interface IPageSource
Returns:
ClassResolver instance used to load classes.

buildKey

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

Parameters:
engine - The current engine servicing this request.
pageName - The name of the page to build key for.
Returns:
The unique key for ths specified page and current Locale.

buildKey

protected PageKey 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.

Parameters:
page - The page to build the key for.
Returns:
The unique key for the specified page instance.

makeObject

public Object makeObject(Object key)
                  throws Exception
Specified by:
makeObject in interface org.apache.commons.pool.KeyedPoolableObjectFactory
Specified by:
makeObject in class org.apache.commons.pool.BaseKeyedPoolableObjectFactory
Throws:
Exception

getPage

public IPage getPage(IRequestCycle cycle,
                     String pageName)
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.
Returns:
The loaded page.
See Also:
PageSpecificationResolver.resolve(IRequestCycle, String)

releasePage

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

Specified by:
releasePage in interface IPageSource
Parameters:
page - The page to release.

resetEventDidOccur

public void resetEventDidOccur()
Specified by:
resetEventDidOccur in interface ResetEventListener

reportStatus

public void reportStatus(ReportStatusEvent event)
Specified by:
reportStatus in interface ReportStatusListener

setServiceId

public void setServiceId(String serviceId)

setRequestCycle

public void setRequestCycle(IRequestCycle cycle)

setClassResolver

public void setClassResolver(org.apache.hivemind.ClassResolver resolver)
Since:
4.0

setPageSpecificationResolver

public void setPageSpecificationResolver(PageSpecificationResolver resolver)
Since:
4.0

setLoader

public void setLoader(IPageLoader loader)
Since:
4.0

setPropertySource

public void setPropertySource(IPropertySource propertySource)


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.