Status Module
Introduction
The Status Module can be used to determine the status of other modules running in a GeoServer instance. This module can be queried remotely using the Spring Remoting API. It returns a list of IStatusReports that contain information about each module.
Technical Details
Interfaces
The Status Module is centered around three simple interfaces.
IStatusReport represents the status of a module within a GeoServer instance. It consists of a name, a status (okay, warning, or error), and a message (of type Exception).
IStatusReporter is the entry point for someone wishing to query the status of modules. It provides a method to retrieve all of the IStatusReports.
IStatusChecker is the interface used by IStatusReporter to check on the status of a module. They are responsible for querying the modules themselves and creating an IStatusReport.
IStatusReport
public interface IStatusReport extends Serializable { public static final int OKAY = 0; public static final int WARNING = 1; public static final int ERROR = 2; public String getModuleName(); public Exception getMessage(); public int getStatus(); }
Because IStatusReports are intended to be sent over remote channels, they must all be Serializable. Module name is a human readable String that could be displayed to a user to identify this module. Status can be one of the three static constants. Message is an Exception containing a message or a stack trace relevant to the current status. Message could be null, for instance if status was OKAY.
IStatusReporter
public interface IStatusReporter { public List<IStatusReport> getStatusReports(); }
The IStatusReporter can be accessed remotely, and is responsible for querying all available IStatusChecker objects and aggregating their IStatusReports. The reports are made available through getStatusReports().
IStatusChecker
public interface IStatusChecker { public IStatusReport checkStatus(); }
The IStatusChecker is an interface that represents a mechanism to query the status of a module. Implementors should, when checkStatus() is called, retrieve and query status information about the module they are implementing for. Once status is determined, an IStatusReport should be constructed and returned.
Implementation
A basic implementation of the status module is provided in the org.vfny.geoserver.control.internal package. Included are two classes: DefaultStatusReport and StatusReporterImpl.
DefaultStatusReport
public class DefaultStatusReport implements IStatusReport { private int status; private Exception message; private String name; ... }
DefaultStatusReport is a simple read-only bean object that implements IStatusReports. It contains getters for the three fields, as well as a constructor which takes each field as a parameter. This can be used by implementations of IStatusChecker.
StatusReporterImpl
public class StatusReporterImpl implements IStatusReporter, ApplicationContextAware { private ApplicationContext applicationContext; public List getStatusReports() { List reports = new ArrayList(); Map checkerBeans = (Map) applicationContext.getBeansOfType(IStatusChecker.class); Iterator iter = checkerBeans.entrySet().iterator(); while (iter.hasNext()) { Entry entry = (Entry) iter.next(); IStatusChecker checker = (IStatusChecker) entry.getValue(); reports.add(checker.checkStatus()); } return reports; } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } }
StatusReporterImpl is the reference implemetnation for IStatusReporter. It examines the Spring applicationContext for all beans that implement IStatusChecker. It then iterates through them, calling checkStatus on each one. It aggregates the IStatusReports and returns them.
Example IStatusChecker Implementation
The module includes an example implementation of IStatusChecker that queries the WFS module. This checks for the existance of a "wfs" bean, and then checks to see if it is enabled or not.
public class WFSStatusChecker implements IStatusChecker, ApplicationContextAware { private static final String NAME = "WFS"; private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public IStatusReport checkStatus() { int status = IStatusReport.OKAY; Exception message = null; WFS wfs = null; try { wfs = (WFS) applicationContext.getBean("wfs"); } catch (Exception e) { status = IStatusReport.ERROR; message = e; return new DefaultStatusReport(NAME, status, message); } if (wfs == null) { status = IStatusReport.ERROR; message = new Exception("WFS failed to load. Please check server logs"); } else if (!wfs.isEnabled()) { status = IStatusReport.ERROR; message = new Exception("WFS service is currently disabled"); } return new DefaultStatusReport(NAME, status, message); } }
The bean must be included in the applicationContext in order to get picked up by StatusReporterImpl:
<bean id="wfsstatuschecker" class="org.vfny.geoserver.control.internal.WFSStatusChecker"/>