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:
- methods:
1. contextInitialized -- used to context initialize
Sample code:
//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:
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
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】

浙公网安备 33010602011771号