Package com.isomorphic.base

# Class InitListener

java.lang.Object
com.isomorphic.base.InitListener

All Implemented Interfaces:
  `jakarta.servlet.ServletContextListener`, `jakarta.servlet.ServletRequestListener`, `EventListener`

public class InitListener extends Object implements jakarta.servlet.ServletContextListener, jakarta.servlet.ServletRequestListener
The SmartClient Server framework must be initialized from its config files at startup time, before user code invokes any framework functionality. If you are running standalone (ie, outside of a servlet container), you should call the static utility method `ISCInit.go()` early in your bootstrap code (eg, from the top of your `main()` method).

If you are running inside a servlet engine, install the following listener in your web.xml. This must be the first listener registered in web.xml. In addition to exporting configured database connections via JNDI before other frameworks initialize, its requestInitialized() callback is the certified start boundary that detects ResourceCaptureScope state left on a pooled worker by the preceding request. If an earlier request listener legitimately creates an RCS for the new request, InitListener cannot distinguish it from stale state and would clean resources that the earlier listener is still using. Being first also makes its requestDestroyed() callback run last, after other request listeners release their resources. See below for other rationale related to Spring.

- Install `InitListener`, which is both a `ServletContextListener` and `ServletRequestListener`:

         <listener>
              <listener-class>com.isomorphic.base.InitListener</listener-class>
          </listener>

## Interaction with Spring initialization

The Spring framework attempts to initialize itself in similar ways to the SmartClient framework, and similarly it wants its own initialization to be the very first thing that happens. This can cause problems in certain cases. For example, one known problem occurs when you define DataSource instances as Spring beans, and Spring gets to initialize itself first: it attempts to instantiate a instance of the bean, which ultimately calls into our framework code before the framework has been initialized.

The solution to this is to use the `InitListener`, and to ensure that it is declared in your `web.xml` file before the Spring `ContextLoaderListener`. The Servlet 2.3 spec states (SRV.10.3.3):

"During Web application execution, listeners are invoked in the order of their registration."

Therefore, declaring the SmartClient listener before the Spring one ensures that things run in the correct order in Servlet 2.4-compatible containers, and in those Servlet 2.3 containers that enforce the rule of running listeners before initializing filters or servlets.