You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ch...@astrazeneca.com on 2002/08/02 17:16:02 UTC

RE: struts 1.1 b1 plugins and the tomcat 4.0.3 manager applicatio n

Ok, destroy seems to be being called on stop now, even though I haven't
really done anything.

I did review the servlet specification and found a solution that I can use
if necessary, namely supplying a listener which initializes the resources on
app (servletContext) start and shut down.



-----Original Message-----
From: Falling, Christopher 
Sent: Friday, August 02, 2002 3:37 AM
To: struts-user@jakarta.apache.org
Subject: struts 1.1 b1 plugins and the tomcat 4.0.3 manager application


I am using struts 1.1 b1 and testing the plugin capabilities.  In particular
I am using poolman 2.0.4 and the RMIRegistry to test the cleanup of these
resources when I stop the web application via the tomcat manager
application.  

The destroy method seems to be working just fine when tomcat is shutdown,
but does not seem to be being called with the calls to
http://localhost/manager/stop?path=/app

or
http://localhost/manager/remove?path=/app

>From the code I can see that the destroy methods of the plugins are being
called when the action servlet is destroyed, however is there any reason
that tomcat is not destroying the servlets when the application is being
stopped or removed by the management application.  And if this is the way
that the specification is supposed to work, what would be the best way to
propagate the stop method to the servlet.  As a side note, 
http://localhost/manager/start?path=/app 

will cause the servlet to execute the init method.

Thus issuing the reload request or the path of issuing a stop request
followed by a start request will result in the initialization being reran
but the destroy method not being called.

Here is the code for JNDI plugin

public class JNDIPlugin implements PlugIn {
  private Log log = LogFactory.getLog(JNDIPlugin.class);
  private String jndiURL;
  private String jndiFactory;

  public void setJndiURL (String value) {
    jndiURL = value;
  }
  public void setJndiFactory (String value) {
    jndiFactory = value;
  }
  public String getJndiURL () {
    return jndiURL;
  }
  public String getJndiFactory () {
    return jndiFactory;
  }

  public void destroy() {
    if (log.isInfoEnabled())
      log.info("Executing destroy on JNDIPlugin");
    try {
      java.rmi.registry.Registry registry =
java.rmi.registry.LocateRegistry.getRegistry();
      String [] names = registry.list();
      if (log.isInfoEnabled())
        log.info("The number of bound names are " + names.length);
      for (int i = 0; i< names.length; i++) {
        if (log.isInfoEnabled())
          log.info("unbinding " + names[i] + " from registry");
        registry.unbind(names[i]);
      }
    } catch (Exception e) {
      log.error("Exception in cleanup of RMI Registry", e);
    }
  }

  public void init(ApplicationConfig config) throws ServletException {
    if (log.isInfoEnabled())
      log.info("Initializing JNDIPlugin");
    if
("com.sun.jndi.rmi.registry.RegistryContextFactory".equals(jndiFactory)) {
      try {
        int port = 1099;
        if (jndiURL.indexOf("rmi://") != -1)
          jndiURL = jndiURL.substring("rmi://".length());
        if (jndiURL.indexOf(":") != -1) {
          jndiURL = jndiURL.substring(jndiURL.indexOf(":")+1,
jndiURL.length());
          try {
            port = Integer.parseInt(jndiURL.trim());
          } catch (Exception rmie) {
          }
        }
        java.rmi.registry.LocateRegistry.createRegistry(port);
        if (log.isInfoEnabled())
          log.info("JNDI is the RMIRegistry Provider, started it on local
port" + port);
      } catch (Exception rmiex) {
          log.error("Did not start RMI JNDI provider", rmiex);
      }
    } else {
      log.error("Unknown JNDI configuration");
    }
  }
}

Thanks

Christopher Falling
Software Engineer, Discovery IS
____________________________________
AstraZeneca, R&D Boston
Discovery Information Systems

AstraZeneca R&D Boston - Waltham
35 Gatehouse Drive
Waltham, MA  02451
Local x4730
Tel: +01 781 839 4730
christopher.falling@astrazeneca.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>