Pluto Learning 1 -- PortalStartupListener

PortalStartupListener

PortalStartupListener is a Class used to listen to the Servlet Context's starup / shutdown behavior and do some initialize stuff during those phases. (notes: Servlet Context starup or shutdown phase can be considered as Tomcat's startup or shutdown in pluto's case.)

features as follows: 

  - in "pluto-portal-driver" project. 

  - extends ContentLoaderListener (which comes from 【Spring-web-XXX.jar】)

  - func:

  1. instantiation & registration of DriverConfiguration  
At this stage, we just need to know that:
  - DriverConfiguration has a implementation called DriverConfigurationImpl
  - DriverConfigurationImpl gets the instances of some services which portal container could commonly used as its attributes      

    through the Spring IoC
  - DriverConfigurationImpl and those services are defined as beans in the Spring Bean Configuration files, so they can be
    loaded when server starts up
For more detail,we can refer to 【to do...

 

  2. instantiation & registration of AdminConfiguration  
At this stage, we just need to know that:
  - AdminConfiguration has a implementation called AdminConfigurationImpl.
  - AdminConfigurationImpl has PortletRegistryAdminService RenderConfigAdminService two interfaces as types of its attributes.

  - RenderConfigAdminService get its instance value of the implementation called RenderConfigServiceImpl which is defined in

    Sring Bean Configuration files.

  - AdminConfigurationImpl and RenderConfigAdminService are defined as beans in the Spring Bean Configuration files

    while PortletRegistryAdminService not.

For more detail,we can refer to 【to do...

 

  3. instantiation & registration of PortletContainer  
At this stage, we just need to know that:
  - PortletContainer is defined in 【pluto-container-api-XXX.jar】, which we do not need to know right now.

For more detail,we can refer to 【to do...

 

  - methods:

    1. contextInitialized -- used to context initialize 

Sample code:

public void contextInitialized(ServletContextEvent event) { 
    final ServletContext servletContext = event.getServletContext();  
    
//ServletContextEvent & ServletContext are from Servlet API

    PortalStartupListener.servletContext 
= servletContext;
    
super.contextInitialized(event);

    ... ...

    WebApplicationContext springContext 
= (WebApplicationContext)
                servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    
//WebApplicationContext comes from 【Spring-Web-XXX.jar】

    ... ...    

    
//instantiate and register DriverConfiguration
    DriverConfiguration driverConfiguration = (DriverConfiguration)
                springContext.getBean(
"DriverConfiguration");
    servletContext.setAttribute(DRIVER_CONFIG_KEY, driverConfiguration);
    //DriverConfiguration is a interface also in 【"pluto-portal-driver" project】

    //instantiate and register AdminConfiguration
    AdminConfiguration adminConfiguration = (AdminConfiguration)
                springContext.getBean(
"AdminConfiguration");
    servletContext.setAttribute(ADMIN_CONFIG_KEY, adminConfiguration);
    //AdminConfiguration is a interface also in 【"pluto-portal-driver" project】

    //instantiate and register PortletContainer
    PortletContainer container = (PortletContainer) springContext.getBean("PortletContainer");
    servletContext.setAttribute(CONTAINER_KEY, container);
    //PortletContainer is a type comes from 【"pluto-container-api.jar"】
    ... ...

    2. contextDestroyed -- used to destroy context

Sample code: 

public void contextDestroyed(ServletContextEvent event) {
    ServletContext servletContext 
= event.getServletContext();
    ... ...
    
// some destroy method of related instances
    destroyContainer(servletContext); 
    destroyAdminConfiguration(servletContext);
    destroyDriverConfiguration(servletContext);
    ... ...
    
super.contextDestroyed(event);

 

    3. destroyXXX -- concret destroy method of related instances

Sample code:
// take destroy container as an example
private void destroyContainer(ServletContext servletContext) {
    ... ...    
    PortletContainer container 
= (PortletContainer)
                servletContext.getAttribute(CONTAINER_KEY);
    ... ...    
    container.destroy();
    ... ...            
    servletContext.removeAttribute(
CONTAINER_KEY);

}
// AdminConfiguration & DriverConfiguration destroy method go similar way.

Notes:

  about the constants:  CONTAINER_KEY, DRIVER_CONFIG_KEY & DRIVER_CONFIG_KEY are defined in AttributeKeys Class,

  which is also in 【"pluto-portal-driver" project】 

posted @ 2011-03-19 18:14  Jason_Lambert  阅读(117)  评论(0)    收藏  举报